Find distance of route from get.shortest.paths()

前端 未结 1 374
你的背包
你的背包 2020-12-30 15:40

I\'m using the igraph package in R to do something rather simple: Calculate the shortest distance between two nodes in my network. Is there a straightforward w

1条回答
  •  一整个雨季
    2020-12-30 15:56

    You can use shortest.paths function, e.g.:

    # compute the min distances from '234' to all other vertices
    tmp3 <- shortest.paths(g2,v='234',weights=E(g2)$newcost)
    
    # print min distance from '234' to '245'
    tmp3[1, which(V(g2)$name == '245')]
    

    The distance computed by the algorithm is 34.5 = 11 + 8.2 + 15.3, as shown in the following picture:

    enter image description here

    0 讨论(0)
提交回复
热议问题