Boost logo

Boost Users :

Subject: [Boost-users] [graph] Having multiple BFS visitors
From: Maxime van Noppen (maxime_at_[hidden])
Date: 2011-07-04 06:23:35


I'm trying to have multiple visitors in the BFS algorithm, thus mixing
two examples provided by the doc:


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

   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_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),
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]’
> 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.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at