Reputation: 253
I have a boost graph defined as
typedef boost::adjacency_list<boost::setS, boost::listS,
boost::undirectedS, CoordNode, CoordSegment> BGraph;
typedef boost::graph_traits<BGraph>::vertex_descriptor VertexDesc;
BGraph _graph;
and I want to know the connected components of same graph with
int num = boost::connected_components(_graph, propMap);
I already tried to create the required writable property map (propMap) with
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);
}
but that doesn't work; I get compilations errors.
If the vertex container would be vecS, it would be easier, because a simple array or vector would suffice. But what am I supposed to pass to this function if I have listS as the vertex container?
How can I create the necessary writable property map? Can somebody give me an example?
Upvotes: 3
Views: 998
Reputation: 253
Works!
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));
Upvotes: 5