
On Wednesday, 6. April 2011 12:55:52 Gabriel Marchand wrote:
Hi, I am new to boost and I face the same problem mentioned here with "connected_components()" using a mutable graph (hence using a list for the vertex container). I try the detailed solution of Aaron Windsor in the previous post but I still get some errors at compilation. Here is my little code:
#include
#include using namespace std; using namespace boost;
Box& b = conf.GetBox();
if (!ai) { ai = new AtomList(); *ai = conf.GetAtoms().AtomSelector(selecti, b); }
typedef boost::adjacency_list< listS, listS, undirectedS, property
, no_property> > graph_t;
graph_t g(ai->size()); property_map
::type index = get(vertex_index, g); graph_traits ::vertex_iterator vi, vi_end; graph_traits ::vertices_size_type cnt = 0; for(tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi) put(index, *vi, cnt++); for (unsigned int i = 0; i < ai->size(); ++i) { Cartesian& crdi = ai->GetElement(i)->pos; for (unsigned int j = i + 1; j < ai->size(); ++j) { Cartesian& crdj = ai->GetElement(j)->pos; double r = conf.GetBox().CartesianDistance(crdi, crdj); if (r < rcut) { add_edge(vertex(i,g), vertex(j,g), g); // Add edge to Map if distance criteria is satisfied
} } }
vector<int> component(num_vertices(g)); int num_clusters = connected_components(g, &component[0], vertex_index_map(index));
Interstingly, while your code does in fact compile with listS and connected_component() being commented out, it results in a Segmentation Fault at the line containing put(index, *vi, cnt++); I don't know yet what causes this, but I am assuming that it has something to do with the error message you also provided stating missing put() definition for void*. By this, I mean that I assume that the usage of listS works somehow with void* (would make sense to me in some way) but this seems to be problematic, at least as fas as I know until now. I will have a deeper look at it. Until then, perhaps someone else will drop in and maybe even clarify this.
The compilation is successfull until I add the last line: int num_clusters = connected_components(g, &component[0], vertex_index_map(index));
Hope somebody can give a hint gabriel