Boost logo

Boost Users :

From: Lars S. Jessen (ljessen_at_[hidden])
Date: 2006-02-26 19:19:30


Hi.

I have an adjacency_list graph where I need to find the shortest path
between two vertices. This can be done with the following code
(from http://www.boost.org/libs/graph/example/astar-cities.cpp):

   ...
   vector<mygraph_t::vertex_descriptor> p(num_vertices(g));
   vector<cost> d(num_vertices(g));
   try {
     // call astar named parameter interface
     astar_search
       (g, start,
        distance_heuristic<mygraph_t, cost, location*>
         (locations, goal),
        predecessor_map(&p[0]).distance_map(&d[0]).
        visitor(astar_goal_visitor<vertex>(goal)));

   } catch(found_goal fg) { // found a path to the goal
     list<vertex> shortest_path;
     for(vertex v = goal;; v = p[v]) {
       shortest_path.push_front(v);
       if(p[v] == v)
         break;
     }
   ...

As you can see, it's easy to obtain the list of vertices that makes the
shortest path from start to goal, but how do I obtain the list of edges
connecting start to goal?

- Lars


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