Shortest (directed or undirected) paths between vertices
Source:R/structural.properties.R
shortest.paths.Rd
shortest.paths()
was renamed to distances()
to create a more
consistent API.
Arguments
- graph
The graph to work on.
- v
Numeric vector, the vertices from which the shortest paths will be calculated.
- to
Numeric vector, the vertices to which the shortest paths will be calculated. By default it includes all vertices. Note that for
distances()
every vertex must be included here at most once. (This is not required forshortest_paths()
.- mode
Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If
out
then the shortest paths from the vertex, ifin
then to it will be considered. Ifall
, the default, then the graph is treated as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.- weights
Possibly a numeric vector giving edge weights. If this is
NULL
and the graph has aweight
edge attribute, then the attribute is used. If this isNA
then no weights are used (even if the graph has aweight
attribute). In a weighted graph, the length of a path is the sum of the weights of its constituent edges.- algorithm
Which algorithm to use for the calculation. By default igraph tries to select the fastest suitable algorithm. If there are no weights, then an unweighted breadth-first search is used, otherwise if all weights are positive, then Dijkstra's algorithm is used. If there are negative weights and we do the calculation for more than 100 sources, then Johnson's algorithm is used. Otherwise the Bellman-Ford algorithm is used. You can override igraph's choice by explicitly giving this parameter. Note that the igraph C core might still override your choice in obvious cases, i.e. if there are no edge weights, then the unweighted algorithm will be used, regardless of this argument.