我构建了一个 boost BGL 图:
using vertex_t = std::variant<node_t, specialNode_t>; // structs
using edge_t = std::variant<TerminalType>; // enum
using Graph_t = boost::adjacency_list<
boost::vecS,
boost::vecS,
boost::undirectedS,
vertex_t,
edge_t>;
Graph_t myGraph;
我试图找到(收集)从某个起点(顶点)可到达的所有顶点(按距离排序)。这意味着我想创建一个从某个起始顶点可到达的所有顶点的列表,其中“较近”的顶点存储在列表/向量的前面。因此我(认为我)需要 BFS。
不幸的是我没能找到如何在没有编译错误的情况下做到这一点:
boost::queue<vertex_t> Q;
boost::default_bfs_visitor vis; // Will do my collecting visitor later...
auto indexmap = boost::get(boost::vertex_index, myGraph);
auto colormap = boost::make_vector_property_map<boost::default_color_type>(indexmap);
boost::breadth_first_visit(myGraph, start, std::ref(Q), vis, colormap);
这会导致以下错误:
Error C2039 'push': is not a member of 'std::reference_wrapper<boost::queue<ListSim::vertex_t,std::deque<_Tp,std::allocator<_Ty>>>>'
Error C2039 'empty': is not a member of 'std::reference_wrapper<boost::queue<ListSim::vertex_t,std::deque<_Tp,std::allocator<_Ty>>>>'
Error C2039 'top': is not a member of 'std::reference_wrapper<boost::queue<ListSim::vertex_t,std::deque<_Tp,std::allocator<_Ty>>>>'
Error C2039 'pop': is not a member of 'std::reference_wrapper<boost::queue<ListSim::vertex_t,std::deque<_Tp,std::allocator<_Ty>>>>'
Error C2039 'push': is not a member of 'std::reference_wrapper<boost::queue<ListSim::vertex_t,std::deque<_Tp,std::allocator<_Ty>>>>'
我的问题:
- 谁能阐明我的错误?或者也许是一个指向
例子?
- 是否可能有更好的(在效率方面)或不同的方法来实现该目标?
(我想先使用“connected_components”......但它使用DFS,无法满足我的距离/排序标准)。