本文介绍了如何将boost :: graph算法与listS,setS用作顶点/边缘容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用boost :: graph库的boost示例通常使用类似

The boost examples for usage of the boost::graph library usually employ a graph like

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

,因此它们工作得很好.但是我有一个

and therefore they work very well. But I have a graph with

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

并且算法无法立即使用.在大多数情况下,必须提供用于查找特定顶点索引(整数值)的vertex_descriptor的映射.

and the algorithms don't work out of the box. In most cases a map for looking up a vertex_descriptor for a particular vertex index (integer value) has to be provided.

我想检查我的图是否是平面的,并计算它的平面嵌入.我提供了一个顶点索引图,它确实以这种方式工作,例如connected_components算法,但显然不适用于boyer_myrvold_planarity_test:

I want to check whether my graph is planar and compute a planar embedding of it.I provide a vertex index map and it does work in that way for e.g. the connected_components algorithm, but obviously not for the 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;

它会导致各种隐秘的模板错误...

It results in various cryptic template errors...

> 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>        ]

简而言之,它抱怨它无法像我所希望的那样转换/使用它.

In brief, it complains that it cannot convert/use it as I would like it.

我如何使其起作用?

我还需要给功能什么?

不幸的是,几乎没有提升将setS或listS用作容器的示例.此外,我不能使用属性标签,因为这是较大实现的一部分,并且需要将属性保留在外部.

Unfortunately, there are hardly boost examples for working with setS or listS as containers. Furthermore, I cannot use the property tags because this is part of a larger implementation and I need to keep the properties external.

如果有人提出建议,我将非常高兴.

I would be very happy if somebody has a suggestion.

推荐答案

错误消息提示您需要提供一个vertex_index映射;在此处中看到了同样的问题. 此处;实际上,他们的问题与您的问题几乎相同.

The error message tells that you need to provide a vertex_index map; see the same problem answered here. Various ways to add the vertex_index map to adjacency_list are discussed here; in fact their problem is almost identical to yours.

这篇关于如何将boost :: graph算法与listS,setS用作顶点/边缘容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 23:55