简体   繁体   English

在R igraph中将all_shortest_paths vpath转换为epath

[英]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? 是否有一种简单的方法来转换或获取all_shortest_paths返回的vpath的epath?

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. 您可以使用E()函数使用path=参数将一系列折点转换为边列表。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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