## simple example : a ring graph
# edges exist for pairs
A = array(0,c(10,10))
for (i in 1:9){
A[i,i+1] = 1
A[i+1,i] = 1
}
A[10,1] <- A[1,10] <- 1
# compute shortest-path and show the matrix
sdA <- shortestpath(A)
# visualize
opar <- par(no.readonly=TRUE)
par(pty="s")
image(sdA, main="shortest path length for a ring graph")
par(opar)
Run the code above in your browser using DataLab