2016-10-04 29 views
0

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

# 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') 

我可以访问名称verticies的:

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

但我不能访问边缘的名称,它只是出现空:

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

如果你有另一种方法,我打开建议。最后,我基本上需要一个边缘名称的字符向量。

谢谢!

回答

0

给他们的名字得到名称:

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) 

enter image description here

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" 
相关问题