shortest: Compute Shortest-Path Distance

Description Usage Arguments Value Examples

View source: R/compute_shortest.R

Description

shortest routine is an implementation of Floyd-Warshall algorithm to find the shortest path between N nodes for a given graph. For simplicity, this function only accepts a symmetric network of \lbrace 0, 1 \rbrace binary edges.

Usage

1
shortest(graph)

Arguments

graph

one of the followings; (1) an igraph object, (2) a network object, or (3) an (N\times N) adjacency matrix.

Value

an (N\times N) matrix of pairwise shortest path distances.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## load the karate club data
data(karate, package="T4network")

## compute shortest-path distance
dist.spd = shortest(karate$A)

## visualize
opar <- par(no.readonly=TRUE)
par(pty="s")
image(dist.spd[,34:1], axes=FALSE, main="shortest-path distance matrix")
par(opar)

kisungyou/T4network documentation built on Dec. 21, 2021, 6:44 a.m.