Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2005-04-22 17:12:54


On Apr 11, 2005, at 10:17 AM, Vivid Yang wrote:
> I have a question about incremental_component and disjoint_sets.
>
> Here is the context:
> I have a class object initialized with an empty boost::graph.
> The algorithm incrementally builds the graph with the function
> add_vertex(graph).
> At the same time, I have to maintain the connected components of the
> graph.
>
> Here is the question:
> I know incremental_component.hpp can deal with the case edges are being
> added.
> Could it deal with the case that vertices are being added?

Yes. Whenever you add a vertex, you will need to call make_set on it.
Also, be careful with the property maps rank and parent: if you add
vertices, you'll need to make space in those property maps, but if the
vectors reallocate your property maps will become invalid. The easiest
way to handle things would be to either (1) use a vector_property_map,
which automatically resizes and won't invalidator, or (2) make the rank
and parent properties part of the vertices in the graph.

> Especially at the beginning, the graph is empty.
>
> And it seems I cannot declare an empty disjoint_sets variable in the
> class:
> classe X
> { ......
> protected:
> //.... some graph typedef
> std::vector<graph_vertex_size_type> rank;
> std::vector<graph_vertex_descriptor> parent;
> disjoint_sets<Rank, Parent> ds;
> ......
> };

In the constructor for X, you will need to initialize "ds" with the
rank and property maps. The example in
        http://www.boost.org/libs/graph/doc/incremental_components.html
should help with this.

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net