我有一个网络,其中每条边都将其进入网络的时间作为属性,例如
f=c("a","b","a")
t=c("b","c","c")
g=graph.data.frame(data.frame(f,t))
E(g)$time=c(1,2,20)
get.shortest.paths(g,from="a",to="c",mode="all")
[[1]]
[1] 1 3这是A->C,我希望它返回A->B->C作为最短路径,或者更确切地说是最快路径。有没有办法做到这一点?
发布于 2013-12-18 07:39:43
您可以将weights指定为get.shortest.paths
get.shortest.paths(g,from="a",to="c",mode="all",weights=E(g)$time)
#[[1]]
#[1] 1 2 3或者,如果指定了weight边缘属性,则不需要在调用中正式指定此属性。
E(g)$weight <- c(1,2,20)
get.shortest.paths(g,from="a",to="c",mode="all")
#[[1]]
#[1] 1 2 3https://stackoverflow.com/questions/20646618
复制相似问题