3

ブーストグラフは次のように定義されています

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がある場合、この関数に何を渡す必要がありますか?

必要な書き込み可能なプロパティマップを作成するにはどうすればよいですか?誰かが私に例を教えてもらえますか?

4

1 に答える 1

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));   
于 2013-09-05T07:19:46.460 に答える