首页 文章

如何将boost :: graph算法与listS,setS一起用作顶点/边缘容器?

提问于
浏览
4

使用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作为容器几乎没有提升示例 . 此外,我不能使用属性标记,因为这是更大的实现的一部分,我需要保持属性外部 .

如果有人有建议,我会很高兴 .

1 回答

  • 5

    错误消息告诉您需要提供vertex_index映射;看到同样的问题回答here . 讨论了将vertex_index映射添加到adjacency_list的各种方法here;事实上他们的问题几乎与你的问题相同 .

相关问题