igraph has two useful functions, shortest_paths and all_shortest_paths. The former outputs one of the shortest paths, the other outputs all of them. However, the former also is able to output the edge types of the path while the latter doesn't seem to be able to.
How do I use all_shortest_paths to extract the "edge type" for all of the shortest paths? I have provided clarifying code below:
library(igraph)
m <- read.table(row.names=1, header=TRUE, text=
" A B C D
A 0 1 1 0
B 0 0 0 1
C 0 0 0 1
D 0 0 0 0")
m <- as.matrix(m)
ig <- graph.adjacency(m, mode="directed")
plot(ig)
E(ig)
for (i in 1:length(E(ig))) {
if (i == 4) {
E(ig)[i]$type <- -1
} else {
E(ig)[i]$type <- 1
}
}
###This gets one of the shortest paths
test1 <- shortest_paths(ig, from = V(ig)[1], to = V(ig)[4], mode = "out", output = "epath")
###This outputs the types for the shortest path above
test1$epath[[1]]$type
###This gets all the shortest paths
test2 <- all_shortest_paths(ig, from = V(ig)[1], to = V(ig)[4], mode = "out")
###The code below doesn't work. How do I get the types for ALL the shortest paths?
test2$res[[1]]$type