如何使用listS作为顶点容器为boost图创建PropertyMap?

cha*_*ero 3 boost boost-graph

我有一个提升图定义为

typedef boost::adjacency_list<boost::setS, boost::listS,
        boost::undirectedS, CoordNode, CoordSegment> BGraph;
typedef boost::graph_traits<BGraph>::vertex_descriptor  VertexDesc;
BGraph _graph;
Run Code Online (Sandbox Code Playgroud)

我想知道同一张图的连通分量

 int num = boost::connected_components(_graph, propMap);
Run Code Online (Sandbox Code Playgroud)

我已经尝试创建所需的可写属性映射 (propMap)

typedef  std::map<VertexDesc, size_t> IndexMap;
IndexMap mapIndex;
boost::associative_property_map<IndexMap> propMap(mapIndex);
VertexIterator di, dj;
boost::tie(di, dj) = boost::vertices(_graph);
for(di; di != dj; ++di){
    boost::put(propMap, (*di), 0);
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用;我收到编译错误。

如果顶点容器是 vecS,那就更容易了,因为一个简单的数组或向量就足够了。但是如果我有 listS 作为顶点容器,我应该传递给这个函数什么?

如何创建必要的可写属性映射?有人可以举个例子吗?

cha*_*ero 5

作品!

typedef boost::adjacency_list
    <boost::setS, boost::listS,
        boost::undirectedS, 
        boost::no_property,
        boost::no_property> Graph;
    typedef boost::graph_traits<Graph>::vertex_iterator VertexIterator;
    typedef boost::graph_traits<Graph>::vertex_descriptor   VertexDesc;
    typedef std::map<VertexDesc, size_t> VertexDescMap; 

Graph graph;

...


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


std::map<VertexDesc, size_t> compMap;
boost::associative_property_map<VertexDescMap> componentMap(compMap);            
boost::associative_property_map<VertexDescMap>& componentMap;

boost::connected_components(_graph, componentMap, boost::vertex_index_map(indexMap));   
Run Code Online (Sandbox Code Playgroud)