Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breadth_first_visit substitues null BFS visitor #197

Closed
jeffythedragonslayer opened this issue Jan 8, 2020 · 1 comment
Closed

breadth_first_visit substitues null BFS visitor #197

jeffythedragonslayer opened this issue Jan 8, 2020 · 1 comment

Comments

@jeffythedragonslayer
Copy link

jeffythedragonslayer commented Jan 8, 2020

breadth_first_visit ignores the visitor object passed in and uses a null one instead. To recreate:

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <iostream>
using namespace std;

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property<boost::vertex_index_t, uint>, boost::property<boost::edge_index_t, uint>> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor                       vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor                         edge_t;
typedef boost::graph_traits<Graph>::vertex_descriptor                       vertex_t;


struct CollectBFSVisitor : public boost::default_bfs_visitor
{
        virtual void initialize_vertex(vertex_t v, Graph const& g) {cout << "init vertex\n";};
        virtual void discover_vertex(vertex_t v, Graph const& g) {};
        virtual void examine_vertex(vertex_t v, Graph const& g) {};
        virtual void finish_vertex(vertex_t v, Graph const& g) {};
        virtual void black_target(edge_t, Graph const& g) {};
        virtual void gray_target(edge_t, Graph const& g) {};
        virtual void tree_target(edge_t, Graph const& g) {};
        virtual void tree_edge(edge_t, Graph const& g) {};
        virtual void non_tree_edge(edge_t, Graph const& g) {};
};

struct VertBuffer : boost::queue<vertex_t>
{
};

int main()
{
        Graph g;
        vertex_t x = add_vertex(g);
        auto indexmap = boost::get(boost::vertex_index, g);
        auto colormap = boost::make_vector_property_map<boost::default_color_type>(indexmap);

        VertBuffer q;

        CollectBFSVisitor v;
        breadth_first_visit(g, x, q, v, colormap); // the cout doesn't run, but if you change it to breadth_first_search it does
}

Problem line in boost/graph/breadth_first_search.hpp

breadth_first_visit
  (ng, s,
   choose_param(get_param(params, buffer_param_t()), boost::ref(Q)).get(),
   choose_param(get_param(params, graph_visitor),
                make_bfs_visitor(null_visitor())),
   choose_pmap(get_param(params, vertex_color), ng, vertex_color)
   );
@jeffythedragonslayer
Copy link
Author

My bad, I tried putting in a cout << "discover vertex\n"; and found that the visitor object is in fact not being ignored. The line from breadth_first_search.hpp I posted seems to choose a default visitor if none was provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant