我在R中使用igraph遇到了奇怪的行为
shortest.paths
命令返回正确的结果,get.shortest.paths
返回警告但没有结果。
shortest.paths(g, v=2795, to=2839) # correct
[,1]
[1,] 3930.4
get.shortest.paths(g, from=2795, to=2839) # warning and no results
[[1]]
numeric(0)
Warning message:
In get.shortest.paths(g_novy, from = 2795, to = 2839) :
At structural_properties.c:5296 :Couldn't reach some vertices
有谁知道,问题是什么?
谢谢, 兹比涅克
答案 0 :(得分:4)
我的猜测是你有一个有向图。 shortest.paths
函数将告诉您最短无向路径的长度。 get.shortest.paths
函数告诉您顶点之间没有定向路径。以下是似乎正在发生的最简单的例子:
g <- graph(1:2)
plot(g)
shortest.paths(g, v=2, to=1)
# [,1]
# [1,] 1
get.shortest.paths(g, from=2, to=1)
# [[1]]
# numeric(0)
#
# Warning message:
# In get.shortest.paths(g, from = 2, to = 1) :
# At structural_properties.c:706 :Couldn't reach some vertices