簡體   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