`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, na.omit=TRUE)
```

dat

one or more input graphs.

inf.replace

the value to use for geodesic distances between disconnected nodes; by default, this is equal `Inf`

.

count.paths

logical; should a count of geodesics be included in the returned object?

predecessors

logical; should a predecessor list be included in the returned object?

ignore.eval

logical; should edge values be ignored when computing geodesics?

na.omit

logical; should `NA`

-valued edges be removed?

A list containing:

If `count.paths==TRUE`

, a matrix containing the number of geodesics between each pair of vertices

A matrix containing the geodesic distances between each pair of vertices

If `predecessors`

, 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 j

This routine is used by a variety of other functions; many of these will allow the user to provide manually precomputed `geodist`

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 (except for `NA`

ed edges, which are dropped when `na.omit==TRUE`

). 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.

Brandes, U. (2000). ``Faster Evaluation of Shortest-Path Based Centrality Indices.'' *Konstanzer Schriften in Mathematik und Informatik*, 120.

West, D.B. (1996). *Introduction to Graph Theory.* Upper Saddle River, N.J.: Prentice Hall.

```
# NOT RUN {
#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