次の質問(get.shortest.paths()からルートの距離を見つける)は非常に役立ちましたが、さらに一歩進めたいと思います。データフレームに1つの列を追加しましたが、最小の新しいコストパスに関連する「合計距離」を取得したいと思います。
私が使用したigraph/Rコードの下。
df2 = rbind(c(234,235,21.6,75),
c(234,326,11.0,35),
c(235,241,14.5,78),
c(326,241,8.2,98),
c(241,245,15.3,75),
c(234,245,38.46,65))
df2 = as.data.frame(df2)
names(df2) = c("start_id","end_id","newcost","distance")
df2
require(igraph)
g2 <- graph.data.frame(df2, directed=FALSE)
tkplot(g2)
(tmp2 = get.shortest.paths(g2, from='234', to='245',weights=E(g2)$newcost))
# This gives the shortest path based on $newcost
V(g2)[tmp2[[1]]]
私が答えたい質問は、この最短経路に関連する距離はどれくらいかということです。最短経路の答えは34.5であり、(手動で計算して)この経路に関連する距離は208です。
この距離を自動的に取得する方法に関するヒントをいくつか理解してください。
ありがとう!Jochem
# What is the distance related to the min newcost?