R中的igraph:get.shortest.paths错误,但shortsts.paths错误

时间:2013-12-16 08:16:45

标签: r igraph

我在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

有谁知道,问题是什么?

谢谢, 兹比涅克

1 个答案:

答案 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