简体   繁体   中英

Converting all_shortest_paths vpaths to epaths in R igraph

Is there a simple way of converting or getting the epaths for the vpaths returned by all_shortest_paths?

library(igraph)

g <- make_ring(10)

# Returns epaths
shortest_paths(g, 1, 6, output="epath")

# Does not return epaths
all_shortest_paths(g, 1, 6)

You can use the E() function to turn a sequence of verticies into an edge list with the path= parameter.

lapply(all_shortest_paths(g, 1, 6)$res, function(x) E(g, path=x))
# [[1]]
# + 5/10 edges:
# [1] 1--10 9--10 8-- 9 7-- 8 6-- 7
# 
# [[2]]
# + 5/10 edges:
# [1] 1--2 2--3 3--4 4--5 5--6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM