shortest.paths
calculates the length of all the
shortest paths from or to the vertices in the
network. get.shortest.paths
calculates one shortest path (the
path itself, and not just its length) from or to the given vertex.shortest.paths(graph, v=V(graph), mode = "all")
get.shortest.paths(graph, from, to=V(graph), mode = "all")
get.all.shortest.paths(graph, from, to = V(graph), mode = "all")
average.path.length(graph, directed=TRUE, unconnected=TRUE)
out
then the shortest paths from the vertex, if
in
then to it will be cshortest.paths
a numeric matrix with vcount(graph)
columns and length(v)
rows. The shortest path length from a vertex to
itself is always zero. For get.shortest.paths
a list of length
vcount(graph)
. List element i
contains the vertex ids on
the path from vertex from
to vertex i
(or the other way
for directed graphs depending on the mode
argument). The vector
also contains from
and i
as the first and last
elements. If from
is the same as i
then it is only
included once. If there is no path between two vertices then a
numeric vector of length zero is returned as the list element.
For get.all.shortest.paths
a list is returned, each list
element contains a shortest path from from
to a vertex in
to
. The shortest paths to the same vertex are collected into
consecutive elements of the list.
For average.path.length
a single number is returned.
Note that shortest.paths
is able to calculate the path length
from or to many vertices at the same time, but
get.shortest.paths
works from one source only. This might
change in the future.
Also note that get.shortest.paths
gives only one shortest path,
however more than one might exists between two vertices.
get.all.shortest.paths
calculates all shortest paths from a
vertex to other vertices given in the to
argument.
g <- graph.ring(10)
shortest.paths(g)
get.shortest.paths(g, 5)
get.all.shortest.paths(g, 0, 5:7)
average.path.length(g)
Run the code above in your browser using DataLab