...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

// named parameter versiontemplate <class VertexListGraph, class ComponentMap, class P, class T, class R> typename property_traits<ComponentMap>::value_type connected_components(VertexListGraph& G, ComponentMap comp, const bgl_named_params<P, T, R>& params =all defaults);// there is not a non-named parameter version of this function

The `connected_components()` functions compute the connected
components of an undirected graph using a DFS-based approach. A
** connected component** of an undirected graph is a set of
vertices that are all reachable from each other. If the connected
components need to be maintained while a graph is growing the
disjoint-set based approach of function

The output of the algorithm is recorded in the component property map
`comp`, which will contain numbers giving the component number
assigned to each vertex. The total number of components is the return
value of the function.

`boost/graph/connected_components.hpp`

An undirected graph. The graph type must be a model of Vertex List Graph and Incidence Graph.OUT:

Python: The parameter is namedgraph.

The algorithm computes how many connected components are in the graph, and assigning each component an integer label. The algorithm then records which component each vertex in the graph belongs to by recording the component number in the component property map. TheComponentMaptype must be a model of Writable Property Map. The value type shouch be an integer type, preferably the same as thevertices_size_typeof the graph. The key type must be the graph's vertex descriptor type.

Python: Must be anvertex_int_mapfor the graph.

Python default:graph.get_vertex_int_map("component")

This is used by the algorithm to keep track of its progress through the graph. The typeIN:ColorMapmust be a model of Read/Write Property Map and its key type must be the graph's vertex descriptor type and the value type of the color map must model ColorValue.

Default:an iterator_property_map created from astd::vectorofdefault_color_typeof sizenum_vertices(g)and using thei_mapfor the index map.

Python: The color map must be avertex_color_mapfor the graph.

This maps each vertex to an integer in the range[0, num_vertices(g)). This parameter is only necessary when the default color property map is used. The typeVertexIndexMapmust be a model of Readable Property Map. The value type of the map must be an integer type. The vertex descriptor type of the graph needs to be usable as the key type of the map.

Default:get(vertex_index, g). Note: if you use this default, make sure your graph has an internalvertex_indexproperty. For example,adjacency_listwithVertexList=listSdoes not have an internalvertex_indexproperty.

Python: Unsupported parameter.

The time complexity for the connected components algorithm is also
*O(V + E)*.

The file `examples/connected_components.cpp`
contains an example of calculating the connected components of an
undirected graph.

Copyright © 2000-2001 | Jeremy Siek, Indiana University (jsiek@osl.iu.edu) |