$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] (no subject)
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2011-04-06 12:15:55
Hi,
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 <boost/graph/adjacency_list.hpp>
>     #include <boost/graph/connected_components.hpp>
> 
>     using namespace std;
>     using namespace boost;
> 
>     Box& b = conf.GetBox();
> 
You seem to use your own classes and you do not provide the definition. Thus 
this is unfortunately not a minimal example. So in the future, it might 
facilitate help from others to you, with this in the back of your head.
> 
>     if (!ai) {
>         ai = new AtomList();
>         *ai = conf.GetAtoms().AtomSelector(selecti, b);
>     }
> 
>     typedef boost::adjacency_list<
>             listS,
>             listS,
>             undirectedS,
>     	    property<vertex_index_t, size_t>,
>     	    no_property>
> 
>     > graph_t;
> 
>     graph_t g(ai->size());
>     property_map<graph_t, vertex_index_t>::type index = get(vertex_index,
> g); 
With listS as the vertex container, I would expect it to fail here. An 
adjacency_list with listS does not automatically create a vertex_index 
property. So you might give vecS a try. Especially, if you insert most of the 
vertices (if not all) at one specific moment and you are not constantly 
changing the number of vertices in the graph, I think it will make no big 
difference in performance whether you use vecS or listS. But you have the 
benefit of automatic vertex_index property-creation.
I can however not compile your example (s. above) nor did you provide the 
error message you get, so I can't tell you for sure if this is the source of 
error.
> graph_traits<graph_t>::vertex_iterator vi, vi_end;
>     graph_traits<graph_t>::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));
> 
> 
> 
> 
> The compilation is successfull until I add the last line:
>  int num_clusters = connected_components(g, &component[0],
> vertex_index_map(index));
This confuses me a bit, as I would expect the error in an earlier line.
So you might look forward to provide your error message or a really working, 
minimal example.
> 
> 
> Hope somebody can give a hint
Hope this helps.
> gabriel
Best,
Cedric