|
Boost Users : |
Subject: [Boost-users] [graph] Having multiple BFS visitors
From: Maxime van Noppen (maxime_at_[hidden])
Date: 2011-07-04 06:23:35
Hi,
I'm trying to have multiple visitors in the BFS algorithm, thus mixing
two examples provided by the doc:
http://www.boost.org/doc/libs/1_46_1/libs/graph/example/bfs-example.cpp
and
http://www.boost.org/doc/libs/1_46_1/libs/graph/doc/bfs_visitor.html
What I have:
----------------------------------------------------------------------
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <iostream>
enum { r, s, t, u, v, w, x, y, N };
const char *name = "rstuvwxy";
using namespace boost;
class discover_visitor : public default_bfs_visitor
{
public:
template < typename Vertex, typename Graph >
void discover_vertex(Vertex u, const Graph & g) const
{
std::cout << "discover: " << name[u] << std::endl;
}
};
int main()
{
typedef adjacency_list < vecS, vecS, undirectedS > graph_t;
graph_t g;
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_edge(r, s, g);
boost::add_edge(s, u, g);
boost::add_edge(t, v, g);
std::vector<double> dist(N);
discover_visitor vis;
breadth_first_search(g, vertex(s, g),
boost::visitor(
make_bfs_visitor(
std::make_pair(record_distances(&dist[0],
on_tree_edge()), vis)
)
)
);
return EXIT_SUCCESS;
}
----------------------------------------------------------------------
This produces a lot of g++ errors such as:
> /usr/include/boost/graph/breadth_first_search.hpp:311:5: instantiated from âvoid boost::breadth_first_search(const VertexListGraph&, typename boost::graph_traits<Graph>::vertex_descriptor, const boost::bgl_named_params<P, T, R>&) [with VertexListGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>, P = boost::bfs_visitor<std::pair<boost::distance_recorder<double*, boost::on_tree_edge>, discover_visitor> >, T = boost::graph_visitor_t, R = boost::no_property, typename boost::graph_traits<Graph>::vertex_descriptor = long unsigned int]â
> bfs.cc:49:24: instantiated from here
> /usr/include/boost/graph/visitors.hpp:138:44: error: no type named âevent_filterâ in âclass discover_visitorâ
> /usr/include/boost/graph/visitors.hpp:139:51: error: no type named âevent_filterâ in âclass discover_visitorâ
The problem seems to come from the 2nd pair argument 'vis'. It compiles
if I repeat the first argument of the pair two times, ie:
std::make_pair(record_distances(&dist[0], on_tree_edge()),
record_distances(&dist[0], on_tree_edge()))
I tried to define an 'event_filter' in my visitor class:
typedef on_discover_vertex event_filter;
But then I get other g++ errors:
> /usr/include/boost/graph/visitors.hpp:109:8: error: no match for call to â(discover_visitor) (long unsigned int&, const boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>&)â
Is it possible to have self-defined visitors in an EventVisitorList? And
if so, how?
I'm using boost 1.46.1 with g++ 4.6.
Thanks!
-- Maxime
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