繁体   English   中英

如何访问get.shortest.paths的“ epath”输出以获取边缘名称?

[英]How can I access the 'epath' output of get.shortest.paths to get the edge names?

我想访问get.shortest.paths的'epath'输出并获取边缘的名称,而不是ID的名称。 目前,我具有边缘ID,但是我需要边缘的名称。 例如:

# create graph
solid = graph_from_literal(A-D,A-C,D-F,D-C,C-B,B-E)

# get edges of shortest paths
solid.epaths = get.shortest.paths(solid, from = 1, to = V(solid),output = 'epath')

# get verticies of shortest paths
solid.vpaths = get.shortest.paths(solid, from = 1, to = V(solid),output = 'vpath')

我可以访问顶点名称:

names(unlist(solid.vpaths$vpath[4]))

但是我无法访问边缘的名称,只是出现了空值:

names(unlist(solid.epaths$epath[4]))

如果您有其他方法,欢迎提出建议。 最后,我基本上需要边缘名称的字符向量。

谢谢!

给他们起名字以获得名字:

library(igraph)
solid = graph_from_literal(A-D,A-C,D-F,D-C,C-B,B-E)
E(solid)$name <- letters[seq_len(ecount(solid))]
plot(solid, edge.label = E(solid)$name)

在此处输入图片说明

solid.epaths = get.shortest.paths(solid, from = 1, to = 4, output = 'epath')
solid.vpaths = get.shortest.paths(solid, from = 1, to = 4, output = 'vpath')

names(unlist(solid.vpaths$vpath))
# [1] "A" "D" "F"
names(unlist(solid.epaths$epath))
# [1] "a" "d"

暂无
暂无

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

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