geodist
uses a BFS to find the number and lengths of geodesics between all nodes of dat
. Where geodesics do not exist, the value in inf.replace
is substituted for the distance in question.
geodist(dat, inf.replace=Inf, count.paths=TRUE, predecessors=FALSE, ignore.eval=TRUE)
Inf
. count.paths==TRUE
, a matrix containing the number of geodesics between each pair of verticespredecessors
, a list whose ith element is a list of vectors, the jth of which contains the intervening vertices on all shortest paths from i to jgeodist
output so as to prevent expensive recomputation. Note that the choice of infinite path length for disconnected vertex pairs is non-canonical (albeit common), and some may prefer to simply treat these as missing values. geodist
(without loss of generality) treats all paths as directed, a fact which should be kept in mind when interpreting geodist
output.
By default, geodist
ignores edge values. Setting ignore.eval=FALSE
will change this behavior, with edge values being interpreted as distances; where edge values reflect proximity or tie strength, transformation may be necessary. Edge values should also be non-negative. Because the valued-case algorithm is significantly slower than the unvalued-case algorithm, ignore.eval
should be set to TRUE
wherever possible.
West, D.B. (1996). Introduction to Graph Theory. Upper Saddle River, N.J.: Prentice Hall.
component.dist
, components
#Find geodesics on a random graph
gd<-geodist(rgraph(15))
#Examine the number of geodesics
gd$counts
#Examine the geodesic distances
gd$gdist
Run the code above in your browser using DataCamp Workspace