[bgl] breadth_first_search for shortest paths (fwd)

Dear Jeremy, et al, I am trying to implement a shortest paths algorithm on a directed graph. As I have unit edge weights, I would rather use breadth_first_search rather than dijkstra. // Is this a good candidate for addition? template <class Map, class Tag> struct vertex_marker : public boost::base_visitor<vertex_marker<Map,Tag> > { typedef Tag event_filter; vertex_marker(Map p_map,int p_val) : m_map(p_map),m_val(p_val) { } template <class Vertex, class Graph> void operator()(Vertex v,const Graph&) { boost::put(m_map,v,m_val); } Map m_map; int m_val; }; template <class Map, class Tag> vertex_marker<Map,Tag> mark_vertices(Map p_map, Tag, int p_v) { return vertex_marker<Map,Tag>(p_map,p_v); } boost::breadth_first_search( mygraph, rootnode, boost::visitor(boost::make_bfs_visitor( std::make_pair( boost::record_distances( boost::get(boost::vertex_distance,mygraph), boost::on_tree_edge()) , std::make_pair( mark_vertices( boost::get(boost::vertex_distance,mygraph), boost::on_initialize_vertex(), std::numeric_limits<int>::max()) , mark_vertices( boost::get(boost::vertex_distance,mygraph), boost::on_start_vertex(), 0) ) ) )) ); The problem is that on_start_vertex does not seem to be implemented for breadth_first_search, but it is for depth_first. For dijkstra, the start node seems to be automaticly zeroed. I guess I could mod Am I missing something really obvious here or is there an inconsistency across the algorithms? Shouldn't on_start_vertex be used for all of the graph algorithms? Also, I can't seem to find documentation on neighbor_bfs.hpp Thanks, Joel

Hi Joel, On Thu, 31 Oct 2002, Joel Young wrote: yg-boo> Dear Jeremy, et al, yg-boo> yg-boo> I am trying to implement a shortest paths algorithm on yg-boo> a directed graph. yg-boo> yg-boo> As I have unit edge weights, I would rather use breadth_first_search yg-boo> rather than dijkstra. Righto. yg-boo> yg-boo> // Is this a good candidate for addition? Sure. yg-boo> The problem is that on_start_vertex does not seem to be yg-boo> implemented for breadth_first_search, but it is for depth_first. yg-boo> For dijkstra, the start node seems to be automaticly zeroed. I yg-boo> guess I could mod yg-boo> yg-boo> Am I missing something really obvious here or is there an yg-boo> inconsistency across the algorithms? yg-boo> yg-boo> Shouldn't on_start_vertex be used for all of the graph algorithms? Well, if you use breadth_first_visit instead, then you can do the initialization of the vertices yourself, as is done in dijkstra. However, you have a point. It would be more consistent to have on_start_vertex implemented for breadth_first_search. Do you feel up to doing the patch? yg-boo> Also, I can't seem to find documentation on neighbor_bfs.hpp Yeah, that's on the to-do list. Cheers, Jeremy ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
participants (2)
-
Jeremy Siek
-
Joel Young