2013-12-16 145 views
1

我在R中使用igraph遇到了奇怪的行爲。 shortest.paths命令返回正確結果,get.shortest.paths返回警告並且沒有結果。igraph in R:error with get.shortest.paths but not with 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

我的猜測是,你有向圖。 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 
+0

太棒了!謝謝,那就是問題所在 – Zbynek

相關問題