使用两个访问者增强图表库

时间:2012-10-15 18:36:59

标签: c++ boost boost-graph

经过一些测试后,我观察到了stamp_times访问者的问题:

typedef adjacency_list <vecS, vecS, undirectedS> Graph;
typedef graph_traits <Graph>::edge_descriptor Edge;
typedef graph_traits <Graph>::vertex_descriptor Vertex;


Graph g(edges.begin(), edges.end(), n);

typedef graph_traits <Graph>::vertices_size_type Size;

std::vector<Size> dtime(num_vertices(g));
Size time = 0;

breadth_first_search(g, s, visitor(make_bfs_visitor(
                       stamp_times(dtime.begin(), time, on_discover_vertex()))));

(我对该代码的错误更少)。

我需要使用两个访客来记录前辈,第二个访问两个访问时间。

boost::breadth_first_search
    (g, s,
     boost::visitor(boost::make_bfs_visitor
            (std::make_pair(
            boost::record_predecessors(&p[0], boost::on_tree_edge()),
            stamp_times(dtime.begin(), time, on_discover_vertex())))));

但是这个代码事件没有编译。我得到以下错误。

/usr/include/boost/graph/visitors.hpp: In member function ‘void boost::time_stamper<TimeMap, TimeT, Tag>::operator()(Vertex, const Graph&) [with Vertex = long unsigned int, Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>, TimeMap = __gnu_cxx::__normal_iterator<long unsigned int*, std::vector<long unsigned int> >, TimeT = long unsigned int, Tag = boost::on_discover_vertex]’:
/usr/include/boost/graph/visitors.hpp:109:8:   instantiated from ‘void boost::detail::invoke_dispatch(Visitor&, T, Graph&, mpl_::true_) [with Visitor = boost::time_stamper<__gnu_cxx::__normal_iterator<long unsigned int*, std::vector<long unsigned int> >, long unsigned int, boost::on_discover_vertex>, T = long unsigned int, Graph = const boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>, mpl_::true_ = mpl_::bool_<true>]’
/usr/include/boost/graph/visitors.hpp:140:5:   instantiated from ‘void boost::invoke_visitors(Visitor&, T, Graph&, Tag) [with Visitor = boost::time_stamper<__gnu_cxx::__normal_iterator<long unsigned int*, std::vector<long unsigned int> >, long unsigned int, boost::on_discover_vertex>, T = long unsigned int, Graph = const boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>, Tag = boost::on_discover_vertex]’

1 个答案:

答案 0 :(得分:3)

stamp_times(以及其他EventVisitors)需要WritablePropertyMap。根据{{​​3}},有property_traits的特化允许使用c ++指针作为属性映射并且根据this“因为std :: vector的迭代器(通过调用begin获得) ))是一个指针,指针属性map方法也适用于std :: vector :: iterator“。显然,最后一部分不适用于最新版本的g ++(在4.6.3和4.7.1上测试过)。因此,为了调用stamp_times,您需要使用&dtime[0]代替dtime.begin()