<trclass="memdesc:a2d8283743a52c2e331309c33c798b23c"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Reserves memory for num_nodes and resets the data structures. <ahref="#a2d8283743a52c2e331309c33c798b23c">More...</a><br/></td></tr>
<trclass="memdesc:a2b3b54f216c61506eaaace2d29819f79"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Adds the information that NodeIndex tail and NodeIndex head are connected. <ahref="#a2b3b54f216c61506eaaace2d29819f79">More...</a><br/></td></tr>
<trclass="memdesc:a257c3606c853fb7b79f62a5b62c65359"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Adds a complete StarGraph to the object. <ahref="#a257c3606c853fb7b79f62a5b62c65359">More...</a><br/></td></tr>
<trclass="memdesc:a37aff82e0d7503f2dda86e1211cc89af"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Compresses the path for node. <ahref="#a37aff82e0d7503f2dda86e1211cc89af">More...</a><br/></td></tr>
<trclass="memdesc:aa3cdc15d5fad9ed6672bd4e436d987dd"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the equivalence class representative for node. <ahref="#aa3cdc15d5fad9ed6672bd4e436d987dd">More...</a><br/></td></tr>
<trclass="memdesc:abe650442ae4ce0a544245721946abb89"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Returns the number of connected components. <ahref="#abe650442ae4ce0a544245721946abb89">More...</a><br/></td></tr>
<trclass="memdesc:a8de720dd960dc6e2e831bb27c3500466"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Merges the equivalence classes of node1 and node2. <ahref="#a8de720dd960dc6e2e831bb27c3500466">More...</a><br/></td></tr>
class operations_research::ConnectedComponents< NodeIndex, ArcIndex ></h3>
<p>Template class implementing a Union-Find algorithm with path compression for maintaining the connected components of a graph. </p>
<p>See Cormen et al. 2nd Edition. MIT Press, 2001. ISBN 0-262-03293-7. Chapter 21: Data structures for Disjoint Sets, pp. 498-524. and Tarjan (1975). Efficiency of a Good But Not Linear <aclass="el"href="classoperations__research_1_1Set.html">Set</a> Union Algorithm. Journal of the ACM 22(2):215-225 It is implemented as a template so that the size of NodeIndex can be chosen depending on the size of the graphs considered. The main interest is that arcs do not need to be kept. Thus the memory complexity is O(n) where n is the number of nodes in the graph. The complexity of this algorithm is O(n . alpha(n)) where alpha(n) is the inverse Ackermann function. alpha(n) <= log(log(log(..log(log(n))..) In practice alpha(n) <= 5. See Tarjan and van Leeuwen (1984). Worst-case analysis of set union algorithms. Journal of the ACM 31(2):245-281.</p>
<p>Usage example: ConnectedComponents<int, int> components; components.Init(num_nodes); for (int arc = 0; arc < num_arcs; ++arc) { components.AddArc(tail[arc], head[arc]); } int num_connected_components = components.GetNumberOfConnectedComponents(); if (num_connected_components == 1) { ///< Graph is completely connected. } ///< Group the nodes in the same connected component together. ///< group[class_number][i] contains the i-th node in group class_number. hash_map<int, std::vector<int>> group(num_connected_components); for (int node = 0; node < num_nodes; ++node) { group[components.GetClassRepresentative(node)].push_back(node); }</p>
<p>Keywords: graph, connected components. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00067">67</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
</div><h2class="groupheader">Constructor & Destructor Documentation</h2>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00069">69</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
</div>
</div>
<h2class="groupheader">Member Function Documentation</h2>
<p>Adds the information that NodeIndex tail and NodeIndex head are connected. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00083">83</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<p>Note that Depth-First Search is a better algorithm for finding connected components on graphs. </p><dlclass="todo"><dt><b><aclass="el"href="todo.html#_todo000005">Todo:</a></b></dt><dd>(user): implement Depth-First Search-based connected components finder. </dd></dl>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00095">95</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00106">106</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<p>Returns the equivalence class representative for node. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00123">123</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<p>Returns the number of connected components. </p>
<p>Allocates num_nodes_ bits for the computation. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00129">129</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<p>Reserves memory for num_nodes and resets the data structures. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00072">72</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
<p>Merges the equivalence classes of node1 and node2. </p>
<p>It's faster (~10%) to swap the two values and have a single piece of code for merging the classes. </p>
<pclass="definition">Definition at line <aclass="el"href="connectivity_8h_source.html#l00138">138</a> of file <aclass="el"href="connectivity_8h_source.html">connectivity.h</a>.</p>
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>