2

很抱歉这个新手问题,但我正在努力开始使用 BGL。我正在尝试深度优先搜索:

boost::default_dfs_visitor vis;
boost::depth_first_search( graph, boost::visitor(vis) );

而且我收到了大量有关颜色图的错误消息:

In file included from /usr/include/boost/graph/named_function_params.hpp:22,
                 from /usr/include/boost/graph/depth_first_search.hpp:21,
                 from main.cc:6:
/usr/include/boost/property_map/shared_array_property_map.hpp: In member function 'T& boost::shared_array_property_map<T, IndexMap>::operator[](typename boost::property_traits<IndexMap>::key_type) const [with T = boost::default_color_type, IndexMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>]':
/usr/include/boost/property_map/property_map.hpp:324:   instantiated from 'void boost::put(const boost::put_get_helper<Reference, PropertyMap>&, K, const V&) [with PropertyMap = boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >, Reference = boost::default_color_type&, K = void*, V = boost::default_color_type]'
/usr/include/boost/graph/depth_first_search.hpp:196:   instantiated from 'void boost::depth_first_search(const VertexListGraph&, DFSVisitor, ColorMap, typename boost::graph_traits<Graph>::vertex_descriptor) [with VertexListGraph = boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, DFSVisitor = boost::dfs_visitor<boost::null_visitor>, ColorMap = boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >]'
/usr/include/boost/graph/depth_first_search.hpp:295:   instantiated from 'void boost::depth_first_search(const VertexListGraph&, const boost::bgl_named_params<P, T, R>&) [with VertexListGraph = TreeGraph::graph_type, P = boost::dfs_visitor<boost::null_visitor>, T = boost::graph_visitor_t, R = boost::no_property]'
main.cc:272:   instantiated from here
/usr/include/boost/property_map/shared_array_property_map.hpp:36: error: no match for 'operator[]' in '((const boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)this)->boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >::data[boost::get [with PropertyMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>, Reference = const boost::detail::error_property_not_found&, K = void*](((const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >&)((const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)(&((const boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)this)->boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >::index))), ((void* const&)((void* const*)(& v))))]'
/usr/include/boost/smart_ptr/shared_array.hpp:85: note: candidates are: T& boost::shared_array<T>::operator[](ptrdiff_t) const [with T = boost::default_color_type]

depth_first_search 的文档说有一个默认值,而且我看到许多不提供自己的颜色图的示例,所以我不确定为什么会出现问题。

我的图表类型是:

typedef
  boost::adjacency_list<
  boost::vecS, boost::listS, boost::directedS,
  boost::property<boost::vertex_treegraphnode_t, TreeGraph::node>
  >
  graph_type;

我想也许是因为我有一个自定义属性图,可能会覆盖 depth_first_search 需要的一些颜色图默认值,但我补充说:

boost::property<boost::vertex_color_t, boost::default_color_type>

到财产清单,这也无济于事。

我尝试使用外部 color_map 进行 depth_first 搜索,但这似乎也没有帮助。

关于我可能做错了什么的任何想法?

谢谢。

4

1 回答 1

3
const boost::detail::error_property_not_found&, boost::vertex_index_t

这是“错误之海”的重要部分。只有作为模板参数的具有默认内部adjacency_list属性,并且此属性由默认颜色映射(您正在使用)使用。您有几种选择:vecSVertexListvertex_indexlistS

  • 您可以简单地vecS用作第二个参数(如果您不需要动态修改图形,这是最简单的)。
  • 您可以创建一个内部属性,然后确保对其进行初始化并使其与您的图形保持同步。为此,您需要将您的定义VertexProperty为:

    boost::property<vertex_index_t, std::size_t, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node>>
    

    接着:

    boost::property_map<graph_type,vertex_index_t>::type my_vertex_index_map=get(vertex_index,graph);
    std::size_t current_index=0;
    BGL_FORALL_VERTICES(v,graph,graph_type)
        put(my_vertex_index_map,v,current_index++);
    
  • 您可以创建一个外部属性,对其进行初始化并使其保持最新,然后depth_first_search使用命名参数将其传递给它。

    typedef graph_traits<graph_type>::vertex_descriptor VertexDesc;
    typedef map<VertexDesc, size_t> VertexIndexMap;
    VertexIndexMap mapIndex;
    boost::associative_property_map<VertexIndexMap> my_vertex_index_map(mapIndex);
    std::size_t current_index=0;
    BGL_FORALL_VERTICES(v,graph,graph_type)
        put(my_vertex_index_map,v,current_index++);
    ...
    boost::depth_first_search( graph, boost::visitor(vis).vertex_index_map(my_vertex_index_map);
    
于 2013-03-27T08:11:38.300 回答