簡體   English   中英

如何將boost :: graph算法與listS,setS一起用作頂點/邊緣容器?

[英]How to use boost::graph algorithms with listS, setS as vertex/edge containers?

使用boost :: graph庫的boost示例通常使用類似的圖形

using namespace boost;
typedef adjacency_list
    < vecS, // edge container 
      vecS, // vertex container
      undirectedS,
      property<vertex_index_t, int>,
      property<edge_index_t, int>
    > graph;

因此他們工作得很好。 但我有一個圖表

typedef adjacency_list
   < setS, // edge container 
     listS, // vertex container
     undirectedS,
     boost::no_property,  // vertex property
     boost::no_property // edge property
   > graph;

並且算法不能開箱即用。 在大多數情況下,必須提供用於查找特定頂點索引(整數值)的vertex_descriptor的映射。

我想檢查我的圖形是否是平面的並計算它的平面嵌入。 我提供了一個頂點索引映射,它確實以這種方式工作,例如connected_components算法,但顯然不適用於boyer_myrvold_planarity_test:

using namespace boost;

typedef adjacency_list
<boost::setS, boost::listS, undirectedS,
     boost::no_property, boost::no_property> graph;

typedef  boost::graph_traits<graph>::edge_descriptor    EdgeDesc;
typedef boost::graph_traits<graph>::vertex_descriptor   VertexDesc;

typedef std::map<VertexDesc, size_t> VertexDescMap;
typedef std::map<EdgeDesc, size_t> EdgeDescMap;
typedef boost::graph_traits<graph>::vertex_iterator VertexIterator;


graph K_4;

std::vector<VertexDesc> vertex;
for(int i=0;i < 4; ++i){
    VertexDesc v = boost::add_vertex(K_4);
    vertex.push_back(v);
}


  add_edge(vertex[0], vertex[1], K_4);
  add_edge(vertex[0], vertex[2], K_4);
  add_edge(vertex[0], vertex[3], K_4);
  add_edge(vertex[1], vertex[2], K_4);
  add_edge(vertex[1], vertex[3], K_4);
  add_edge(vertex[2], vertex[3], K_4);



   VertexDescMap vidxMap;
   boost::associative_property_map<VertexDescMap> vindexMap(vidxMap);
   VertexIterator di, dj;
   boost::tie(di, dj) = boost::vertices(K_4);
   for(int i = 0; di != dj; ++di,++i){
      boost::put(vindexMap, (*di), i);
   }


   if (boyer_myrvold_planarity_test(
   boost::boyer_myrvold_params::graph = K_4, 
   boost::boyer_myrvold_params::vertex_index_map = vindexMap))
    std::cout << "K_4 is planar." << std::endl;
  else
    std::cout << "ERROR! K_4 should have been recognized as planar!" 
          << std::endl;

它會導致各種神秘的模板錯誤......

> 1>main.cpp
> 1>C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(167)
> : error C2664:
> 'boost::boyer_myrvold_impl<Graph,VertexIndexMap,StoreOldHandlesPolicy,StoreEmbeddingPolicy>::boyer_myrvold_impl(const
> Graph &,VertexIndexMap)': Konvertierung des Parameters 2 von 'const
> boost::adj_list_vertex_property_map<Graph,ValueType,Reference,Tag>' in
> 'vertex_index_map_t' nicht möglich 1>        with 1>        [ 1>      
> Graph=graph_t, 1>            VertexIndexMap=vertex_index_map_t, 1>    
> StoreOldHandlesPolicy=boost::graph::detail::no_old_handles, 1>        
> StoreEmbeddingPolicy=boost::graph::detail::recursive_lazy_list 1>     
> ] 1>        and 1>        [ 1>            Graph=graph_t, 1>           
> ValueType=boost::detail::error_property_not_found, 1>           
> Reference=const boost::detail::error_property_not_found &, 1>         
> Tag=boost::vertex_index_t 1>        ] 1>        Kein
> benutzerdefinierter Konvertierungsoperator verfügbar, der diese
> Konvertierung durchführen kann, oder der Operator kann nicht
> aufgerufen werden 1>       
> C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(259):
> Siehe Verweis auf die Instanziierung der gerade kompilierten
> Funktions-template "bool
> boost::boyer_myrvold_params::core::dispatched_boyer_myrvold<ArgumentPack>(const
> ArgumentPack &,boost::mpl::false_,boost::mpl::true_)". 1>        with
> 1>        [ 1>           
> ArgumentPack=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>> 1>        ] 1>       
> C:\Libraries\PCL-1.5.1\3rdParty\Boost\include\boost/graph/boyer_myrvold_planar_test.hpp(281):
> Siehe Verweis auf die Instanziierung der gerade kompilierten
> Funktions-template "bool
> boost::boyer_myrvold_params::core::boyer_myrvold_planarity_test<boost::parameter::aux::arg_list<TaggedArg,Next>>(const ArgumentPack &)". 1>        with 1>        [ 1>           
> TaggedArg=boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,
> 1>           
> Next=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>, 1>           
> ArgumentPack=boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::embedding,const
> boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property>>,boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::boyer_myrvold_params::tag::graph,const
> boost::adjacency_list<boost::setS,boost::listS,boost::undirectedS,boost::no_property,boost::no_property>>,boost::parameter::aux::empty_arg_list>> 1>        ] 1>        .\src\main.cpp(135): Siehe Verweis auf die
> Instanziierung der gerade kompilierten Funktions-template "bool
> boost::boyer_myrvold_planarity_test<graph,boost::bgl_named_params<T,Tag,Base>>(const
> A0 &,const A1 &)". 1>        with 1>        [ 1>           
> T=boost::associative_property_map<VertexDescMap>, 1>           
> Tag=boost::vertex_index_t, 1>            Base=boost::no_property, 1>  
> A0=graph, 1>           
> A1=boost::bgl_named_params<boost::associative_property_map<VertexDescMap>,boost::vertex_index_t,boost::no_property> 1>        ]

簡而言之,它抱怨它無法按照我的意願轉換/使用它。

我怎樣才能使它工作?

我還需要為這個功能提供什么?

不幸的是,使用setS或listS作為容器幾乎沒有提升示例。 此外,我不能使用屬性標記,因為這是更大的實現的一部分,我需要保持屬性外部。

如果有人有建議,我會很高興。

錯誤消息告訴您需要提供vertex_index映射; 看到這里回答同樣的問題。 這里討論了將vertex_index映射添加到adjacency_list的各種方法; 事實上他們的問題幾乎與你的問題相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM