I have a (possibly dumb) shortest path question. What is the best way to get both the path (vpath is perfect for me) and the total weight of the shortest path. I see functions shortest_paths
(returns paths) and distances
(returns total weight) but that would mean calculating things twice. NB, I have weights in my graph. Is there a function to quickly calculate the total weight of a path?
> print(g)
IGRAPH 6c62431 DNW- 14 28 --
+ attr: name (v/c), weight (e/n)
+ edges from 6c62431 (vertex names):
[1] src ->i1-j1 src ->i1-j2 src ->i1-j3 src ->i1-j4 i1-j1->i2-j2
[6] i1-j1->i2-j3 i1-j1->i2-j4 i1-j1->i2-j5 i1-j2->i2-j3 i1-j2->i2-j4
[11] i1-j2->i2-j5 i1-j3->i2-j4 i1-j3->i2-j5 i1-j4->i2-j5 i2-j2->i3-j3
[16] i2-j2->i3-j4 i2-j2->i3-j5 i2-j2->i3-j6 i2-j3->i3-j4 i2-j3->i3-j5
[21] i2-j3->i3-j6 i2-j4->i3-j5 i2-j4->i3-j6 i2-j5->i3-j6 i3-j3->snk
[26] i3-j4->snk i3-j5->snk i3-j6->snk
> shortest_paths(g,from="src",to=c("snk"),output="both")
$vpath
$vpath[[1]]
+ 5/14 vertices, named, from 6c62431:
[1] src i1-j1 i2-j4 i3-j5 snk
$epath
$epath[[1]]
+ 4/28 edges from 6c62431 (vertex names):
[1] src ->i1-j1 i1-j1->i2-j4 i2-j4->i3-j5 i3-j5->snk
$predecessors
NULL
$inbound_edges
NULL
> distances(g,v=c("src"),to=c("snk"))
snk
src 16
question from:
https://stackoverflow.com/questions/65937876/shortest-path-path-length-in-igraph 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…