gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:46:21 25 4
gpt4 key购买 nike

我有一个 boost 图定义为

typedef boost::adjacency_list<boost::setS, boost::listS,
boost::undirectedS, CoordNode, CoordSegment> BGraph;
typedef boost::graph_traits<BGraph>::vertex_descriptor VertexDesc;
BGraph _graph;

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

 int num = boost::connected_components(_graph, propMap);

我已经尝试使用

创建所需的可写属性映射 (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);
}

但这行不通;我收到编译错误。

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

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

最佳答案

有效!

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));

关于boost - 如何使用 listS 作为顶点容器为 boost 图创建 PropertyMap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15432104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com