Computes shortest path distances between nodes in a network. Supports all-pairs, single-source, and point-to-point queries.
Arguments
- x
Network input: matrix, igraph, network, cograph_network, or tna object
- from
Character or numeric node identifier(s) for the source. If NULL (default), compute distances from all nodes.
- to
Character or numeric node identifier(s) for the target. If NULL (default), compute distances to all nodes.
- weights
Edge weight handling: NULL (default) auto-detects from edge attributes, NA forces unweighted distances, or a numeric vector of custom weights.
- directed
Logical or NULL. If NULL (default), auto-detect from matrix symmetry. Set TRUE to force directed, FALSE to force undirected.
- ...
Not used. Any argument supplied here raises an
"unused argument"error.
Value
Depends on the query:
If both
fromandtoare NULL: a full distance matrix (all pairs)If
fromis a single node andtois NULL: a named numeric vector of distances from that node to all othersIf
fromis multiple nodes andtois NULL: a matrix with rows for each sourceIf both
fromandtoare single nodes: a single numeric valueOtherwise: a matrix of distances between the specified node sets
Details
Distances are computed with igraph::distances(). For weighted
networks, edge weights are used as distances by default. With
weights = NA, every edge has unit distance.
igraph also exports a shortest_paths() with a different signature and
return value; when both packages are attached, qualify the call as
cograph::shortest_paths().
