|
Boost Users : |
Subject: Re: [Boost-users] Graph Library Question
From: alex (alexhighviz_at_[hidden])
Date: 2014-05-16 09:13:03
>I was able to find the shortest distances between my starting node and the
rest
>of the nodes.
>
>Now I would like to output the path between my starting node and
destination
>node. I have tried a number of different examples but none of them seem to
>do what I want.
For this you need the predecessor map, just as you needed the distance map
to look up distances.
This is what Arne Vogel wrote last week:
To read the path from the PredecessorMap, you work your way backwards
from the destination vertex to the source vertex, always looking up the
predecessor of the current vertex in the predecessor map, until the
current vertex is equal to the source vertex. Then you just reverse the
path if necessary. Or, as simplified code:
vector<vertex> path;
for ( vertex current = destination; current != source; current =
predecessor[current] )
{
path.push_back(current);
}
path.push_back(source);
std::reverse(path.begin(), path.end());
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net