2013-03-26 28 views
2

對不起,新手問題,但我拉我的頭髮試圖開始使用BGL。我用深度優先搜索實驗:BGL depth_first_search錯誤,有彩色地圖

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的文件說,有一個默認的,和我已經看到了很多不提供自己的色彩地圖的例子,所以我不確定爲什麼會有問題。

My圖表類型:

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搜索,並且這似乎也沒有幫助。

任何想法,我可能做錯了什麼?

謝謝。

回答

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

這是「錯誤之海」的重要組成部分。只有adjacency_list具有vecS作爲VertexList模板參數具有默認內部vertex_index屬性和此屬性由默認顏色映射(您正在使用listS)使用。您有幾種選擇:

  • 您可以簡單地使用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); 
    
+0

感謝您的答覆。不幸的是,我不認爲我可以使用vecS作爲頂點,因爲圖形需要隨時修改。 – user1806566 2013-03-27 15:40:44

+0

在我上一篇文章後,我得到了這個想法,也許列表是問題,所以我創建了一個外部屬性顏色映射。我做了與創建外部vertex_index_map相同的方式,除了我沒有初始化任何東西,它似乎工作。是否只有在有vertex_index_map時才能使用默認顏色貼圖,但如果您提供了自己的顏色貼圖,那麼這是不必要的?如果是這樣,是否有理由相對於另一方偏好?謝謝。 – user1806566 2013-03-27 15:47:01