简体   繁体   English

使用两个访客提升图形库

[英]Boost graph library using two visitors

After some tests I observer that the stamp_times visitor is the problem: 经过一些测试,我观察到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()))));

(I got more less the same error with that code). (使用该代码我得到的错误更少了)。

I need to use two visitors one to record predecessors and a second one two obtain visiting time. 我需要使用两个访问者,一个记录前辈,第二个来获取访问时间。

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())))));

But this code event do not compile. 但是此代码事件不会编译。 I get following error. 我收到以下错误。

/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]’

stamp_times (and the other EventVisitors) expects a WritablePropertyMap . stamp_times (和其他EventVisitors)需要一个WritablePropertyMap According to this there are specializations of property_traits that allow using c++ pointers as property maps and according to this "Since the iterator of a std::vector (obtained with a call to begin()) is a pointer, the pointer property map method also works for std::vector::iterator". 根据这个也有特例property_traits在允许使用C ++指针作为属性映射,并根据 “自一个std ::向量的迭代器(带有调用获取开始())是一个指针,该指针属性映射方法还适用于std :: vector :: iterator“。 Apparently this last part is not true with recent versions of g++ (tested on 4.6.3 and 4.7.1). 显然,对于最新版本的g ++(在4.6.3和4.7.1上测试),这最后一部分是不正确的。 So in order to invoke stamp_times you need to use &dtime[0] instead of dtime.begin() . 因此,为了调用stamp_times您需要使用&dtime[0] dtime.begin() &dtime[0]而不是dtime.begin()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM