Files
ortools-clone/docs/cpp_algorithms/dynamic__partition_8h_source.html

93 lines
84 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OR-Tools</title>
<meta http-equiv="Content-Type" content="text/html;"/>
<meta charset="utf-8"/>
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
<link rel="stylesheet" type="text/css" href="ortools.css" title="default" media="screen,print" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
</head>
<body>
<div id="banner-container">
<div id="banner">
<span id="sfml">OR-Tools 7.1@</span>
</div>
</div>
<div id="content">
<!-- Generated by Doxygen 1.8.15 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_a7cc1eeded8f693d0da6c729bc88c45a.html">ortools</a></li><li class="navelem"><a class="el" href="dir_80dda7a75b0dfcf996988638a63eb03a.html">algorithms</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">dynamic_partition.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="dynamic__partition_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">// Copyright 2010-2018 Google LLC</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment">// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span>&#160;<span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span>&#160;<span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span>&#160;<span class="comment">// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span>&#160;<span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span>&#160;<span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;<span class="comment">// TODO(user,user): refine this toplevel comment when this file settles.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="comment">// Two dynamic partition classes: one that incrementally splits a partition</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;<span class="comment">// into more and more parts; one that incrementally merges a partition into less</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="comment">// and less parts.</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="comment">// GLOSSARY:</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="comment">// The partition classes maintain a partition of N integers 0..N-1</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;<span class="comment">// (aka &quot;elements&quot;) into disjoint equivalence classes (aka &quot;parts&quot;).</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span>&#160;<span class="comment">// SAFETY:</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span>&#160;<span class="comment">// Like std::vector&lt;int&gt; crashes when used improperly, these classes are not</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span>&#160;<span class="comment">// &quot;safe&quot;: most of their methods may crash if called with invalid arguments. The</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span>&#160;<span class="comment">// client code is responsible for using this class properly. A few DCHECKs()</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span>&#160;<span class="comment">// will help catch bugs, though.</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span>&#160;<span class="preprocessor">#ifndef OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160;<span class="preprocessor">#define OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160;</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160;<span class="preprocessor">#include &quot;ortools/base/logging.h&quot;</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceoperations__research.html">operations_research</a> {</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;<span class="comment">// Partition class that supports incremental splitting, with backtracking.</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160;<span class="comment">// See http://en.wikipedia.org/wiki/Partition_refinement .</span></div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span>&#160;<span class="comment">// More precisely, the supported edit operations are:</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;<span class="comment">// - Refine the partition so that a subset S (typically, |S| &lt;&lt;&lt; N)</span></div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160;<span class="comment">// of elements are all considered non-equivalent to any element in ¬S.</span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160;<span class="comment">// Typically, this should be done in O(|S|).</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160;<span class="comment">// - Undo the above operations (backtracking).</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160;<span class="comment">//</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>&#160;<span class="comment">// TODO(user): rename this to BacktrackableSplittingPartition.</span></div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html"> 49</a></span>&#160;<span class="keyword">class </span><a class="code" href="classoperations__research_1_1DynamicPartition.html">DynamicPartition</a> {</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <span class="comment">// Creates a DynamicPartition on n elements, numbered 0..n-1. Start with</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>&#160; <span class="comment">// the trivial partition (only one subset containing all elements).</span></div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; <span class="keyword">explicit</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#afe6f90b99c0b1d646b00ad2d1bb0a09d">DynamicPartition</a>(<span class="keywordtype">int</span> num_elements);</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; <span class="comment">// Ditto, but specify the initial part of each elements. Part indices must</span></div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; <span class="comment">// form a dense integer set starting at 0; eg. [2, 1, 0, 1, 1, 3, 0] is valid.</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; <span class="keyword">explicit</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#afe6f90b99c0b1d646b00ad2d1bb0a09d">DynamicPartition</a>(<span class="keyword">const</span> std::vector&lt;int&gt;&amp; initial_part_of_element);</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160; <span class="comment">// Accessors.</span></div><div class="line"><a name="l00060"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a4b07bd0eb40bb3fcb3419672313342ea"> 60</a></span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a4b07bd0eb40bb3fcb3419672313342ea">NumElements</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> element_.size(); }</div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a0f4d81d407e148e26480f5ef01778270"> 61</a></span>&#160; <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a0f4d81d407e148e26480f5ef01778270">NumParts</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> part_.size(); }</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;</div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; <span class="comment">// To iterate over the elements in part #i:</span></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; <span class="comment">// for (int element : partition.ElementsInPart(i)) { ... }</span></div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; <span class="comment">//</span></div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; <span class="comment">// ORDERING OF ELEMENTS INSIDE PARTS: the order of elements within a given</span></div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; <span class="comment">// part is volatile, and may change with Refine() or UndoRefine*() operations,</span></div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; <span class="comment">// even if the part itself doesn&#39;t change.</span></div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; <span class="keyword">struct </span>IterablePart;</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; IterablePart <a class="code" href="classoperations__research_1_1DynamicPartition.html#ac1dcc361f73f495e0f362f834b224e89">ElementsInPart</a>(<span class="keywordtype">int</span> i) <span class="keyword">const</span>;</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#af3a2c6e1e18891125f15e42e391055bb">PartOf</a>(<span class="keywordtype">int</span> element) <span class="keyword">const</span>;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a87ccb17e1972d153100a9b061a918ba1">SizeOfPart</a>(<span class="keywordtype">int</span> part) <span class="keyword">const</span>;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a079d605b371556e228347843c9b15d2d">ParentOfPart</a>(<span class="keywordtype">int</span> part) <span class="keyword">const</span>;</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160;</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160; <span class="comment">// A handy shortcut to ElementsInPart(PartOf(e)). The returned IterablePart</span></div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160; <span class="comment">// will never be empty, since it contains at least i.</span></div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; IterablePart <a class="code" href="classoperations__research_1_1DynamicPartition.html#a79106998d8499c5c25f4c74c14456b60">ElementsInSamePartAs</a>(<span class="keywordtype">int</span> i) <span class="keyword">const</span>;</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160;</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160; <span class="comment">// Returns a fingerprint of the given part. While collisions are possible,</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160; <span class="comment">// their probability is quite low. Two parts that have the same size and the</span></div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; <span class="comment">// same fingerprint are most likely identical.</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; <span class="comment">// Also, two parts that have the exact same set of elements will *always*</span></div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; <span class="comment">// have the same fingerprint.</span></div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160; uint64 <a class="code" href="classoperations__research_1_1DynamicPartition.html#a4e68b8de69272cf549b346595d332198">FprintOfPart</a>(<span class="keywordtype">int</span> part) <span class="keyword">const</span>;</div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span>&#160;</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; <span class="comment">// Refines the partition such that elements that are in distinguished_subset</span></div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>&#160; <span class="comment">// never share the same part as elements that aren&#39;t in that subset.</span></div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160; <span class="comment">// This might be a no-op: in that case, NumParts() won&#39;t change, but the</span></div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160; <span class="comment">// order of elements inside each part may change.</span></div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160; <span class="comment">//</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160; <span class="comment">// ORDERING OF PARTS:</span></div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160; <span class="comment">// For each i such that Part #i has a non-trivial intersection with</span></div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160; <span class="comment">// &quot;distinguished_subset&quot; (neither empty, nor the full Part); Part #i is</span></div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span>&#160; <span class="comment">// stripped out of all elements that are in &quot;distinguished_subset&quot;, and</span></div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span>&#160; <span class="comment">// those elements are sent to a newly created part, whose parent_part = i.</span></div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span>&#160; <span class="comment">// The parts newly created by a single Refine() operations are sorted</span></div><div class="line"><a name="l00098"></a><span class="lineno"> 98</span>&#160; <span class="comment">// by parent_part.</span></div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>&#160; <span class="comment">// Example: a Refine() on a partition with 6 parts causes parts #1, #3 and</span></div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>&#160; <span class="comment">// #4 to be split: the partition will now contain 3 new parts: part #6 (with</span></div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>&#160; <span class="comment">// parent_part = 1), part #7 (with parent_part = 3) and part #8 (with</span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>&#160; <span class="comment">// parent_part = 4).</span></div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>&#160; <span class="comment">//</span></div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span>&#160; <span class="comment">// TODO(user): the graph symmetry finder could probably benefit a lot from</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span>&#160; <span class="comment">// keeping track of one additional bit of information for each part that</span></div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span>&#160; <span class="comment">// remains unchanged by a Refine() operation: was that part entirely *in*</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span>&#160; <span class="comment">// the distinguished subset or entirely *out*?</span></div><div class="line"><a name="l00108"></a><span class="lineno"> 108</span>&#160; <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a16fce09dd4c359a6acfd0a864e0a5ebd">Refine</a>(<span class="keyword">const</span> std::vector&lt;int&gt;&amp; distinguished_subset);</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>&#160; <span class="comment">// Undo one or several Refine() operations, until the number of parts</span></div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>&#160; <span class="comment">// becomes equal to &quot;original_num_parts&quot;.</span></div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>&#160; <span class="comment">// Prerequisite: NumParts() &gt;= original_num_parts.</span></div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>&#160; <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a968140cdf9d2766625e1d476a7a71590">UndoRefineUntilNumPartsEqual</a>(<span class="keywordtype">int</span> original_num_parts);</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>&#160;</div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>&#160; <span class="comment">// Dump the partition to a std::string. There might be different conventions</span></div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>&#160; <span class="comment">// for sorting the parts and the elements inside them.</span></div><div class="line"><a name="l00117"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1a"> 117</a></span>&#160; <span class="keyword">enum</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1a">DebugStringSorting</a> {</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span>&#160; <span class="comment">// Elements are sorted within parts, and parts are then sorted</span></div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span>&#160; <span class="comment">// lexicographically.</span></div><div class="line"><a name="l00120"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aacb9b001cac613035de5d6f1f38f7fda1"> 120</a></span>&#160; <a class="code" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aacb9b001cac613035de5d6f1f38f7fda1">SORT_LEXICOGRAPHICALLY</a>,</div><div class="line"><a name="l00121"></a><span class="lineno"> 121</span>&#160; <span class="comment">// Elements are sorted within parts, and parts are kept in order.</span></div><div class="line"><a name="l00122"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aa5edad0b79a2c83ec1b1560960504c161"> 122</a></span>&#160; <a class="code" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aa5edad0b79a2c83ec1b1560960504c161">SORT_BY_PART</a>,</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>&#160; };</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>&#160; std::string <a class="code" href="classoperations__research_1_1DynamicPartition.html#ac535d0a440192c96effe5b938a9482c7">DebugString</a>(<a class="code" href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1a">DebugStringSorting</a> sorting) <span class="keyword">const</span>;</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span>&#160;</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span>&#160; <span class="comment">// ADVANCED USAGE:</span></div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span>&#160; <span class="comment">// All elements (0..n-1) of the partition, sorted in a way that&#39;s compatible</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span>&#160; <span class="comment">// with the hierarchical partitioning:</span></div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>&#160; <span class="comment">// - All the elements of any given part are contiguous.</span></div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>&#160; <span class="comment">// - Elements of a part P are always after elements of part Parent(P).</span></div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>&#160; <span class="comment">// - The order remains identical (and the above property holds) after any</span></div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>&#160; <span class="comment">// UndoRefine*() operation.</span></div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>&#160; <span class="comment">// Note that the order does get changed by Refine() operations.</span></div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>&#160; <span class="comment">// This is a reference, so it&#39;ll only remain valid and constant until the</span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>&#160; <span class="comment">// class is destroyed or until Refine() get called.</span></div><div class="line"><a name="l00136"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#ab516c7e5e0e64a4fca27ab1790d459e5"> 136</a></span>&#160; <span class="keyword">const</span> std::vector&lt;int&gt;&amp; <a class="code" href="classoperations__research_1_1DynamicPartition.html#ab516c7e5e0e64a4fca27ab1790d459e5">ElementsInHierarchicalOrder</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span>&#160; <span class="keywordflow">return</span> element_;</div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span>&#160; }</div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span>&#160;</div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span>&#160; <span class="keyword">private</span>:</div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span>&#160; <span class="comment">// A DynamicPartition instance maintains a list of all of its elements,</span></div><div class="line"><a name="l00142"></a><span class="lineno"> 142</span>&#160; <span class="comment">// &#39;sorted&#39; by partitions: elements of the same subset are contiguous</span></div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>&#160; <span class="comment">// in that list.</span></div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>&#160; std::vector&lt;int&gt; element_;</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>&#160;</div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>&#160; <span class="comment">// The reverse of elements_[]: element_[index_of_[i]] = i.</span></div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>&#160; std::vector&lt;int&gt; index_of_;</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span>&#160;</div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>&#160; <span class="comment">// part_of_[i] is the index of the part that contains element i.</span></div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>&#160; std::vector&lt;int&gt; part_of_;</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>&#160;</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; <span class="keyword">struct </span>Part {</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; <span class="comment">// This part holds elements[start_index .. end_index-1].</span></div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span>&#160; <span class="comment">// INVARIANT: end_index &gt; start_index.</span></div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>&#160; <span class="keywordtype">int</span> start_index; <span class="comment">// Inclusive</span></div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>&#160; <span class="keywordtype">int</span> end_index; <span class="comment">// Exclusive</span></div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>&#160;</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>&#160; <span class="comment">// The Part that this part was split out of. See the comment at Refine().</span></div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>&#160; <span class="comment">// INVARIANT: part[i].parent_part &lt;= i, and the equality holds iff part[i]</span></div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>&#160; <span class="comment">// has no parent.</span></div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>&#160; <span class="keywordtype">int</span> parent_part; <span class="comment">// Index into the part[] array.</span></div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>&#160;</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>&#160; <span class="comment">// The part&#39;s fingerprint is the XOR of all fingerprints of its elements.</span></div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>&#160; <span class="comment">// See FprintOfInt32() in the .cc.</span></div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>&#160; uint64 fprint;</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>&#160;</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>&#160; Part() : start_index(0), end_index(0), parent_part(0), fprint(0) {}</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>&#160; Part(<span class="keywordtype">int</span> start_index, <span class="keywordtype">int</span> end_index, <span class="keywordtype">int</span> parent_part, uint64 fprint)</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>&#160; : start_index(start_index),</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>&#160; end_index(end_index),</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>&#160; parent_part(parent_part),</div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; fprint(fprint) {}</div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>&#160; };</div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160; std::vector&lt;Part&gt; part_; <span class="comment">// The disjoint parts.</span></div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160;</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; <span class="comment">// Used temporarily and exclusively by Refine(). This prevents Refine()</span></div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; <span class="comment">// from being thread-safe.</span></div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; <span class="comment">// INVARIANT: tmp_counter_of_part_ contains only 0s before and after Refine().</span></div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; std::vector&lt;int&gt; tmp_counter_of_part_;</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; std::vector&lt;int&gt; tmp_affected_parts_;</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160;};</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160;</div><div class="line"><a name="l00183"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html"> 183</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html">DynamicPartition::IterablePart</a> {</div><div class="line"><a name="l00184"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ab1abe2eb3716aa80bd29b1e7260484a2"> 184</a></span>&#160; std::vector&lt;int&gt;::const_iterator <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ab1abe2eb3716aa80bd29b1e7260484a2">begin</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0">begin_</a>; }</div><div class="line"><a name="l00185"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#abd3e25c24209be1e6cffda93230bbdd9"> 185</a></span>&#160; std::vector&lt;int&gt;::const_iterator <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#abd3e25c24209be1e6cffda93230bbdd9">end</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818">end_</a>; }</div><div class="line"><a name="l00186"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0"> 186</a></span>&#160; std::vector&lt;int&gt;::const_iterator <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0">begin_</a>;</div><div class="line"><a name="l00187"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818"> 187</a></span>&#160; std::vector&lt;int&gt;::const_iterator <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818">end_</a>;</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160;</div><div class="line"><a name="l00189"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a757903108b39220312da2867ca8babe8"> 189</a></span>&#160; <span class="keywordtype">int</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a757903108b39220312da2867ca8babe8">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818">end_</a> - <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0">begin_</a>; }</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160;</div><div class="line"><a name="l00191"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a4858bbbfb1381ce091704073d878495b"> 191</a></span>&#160; <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a4858bbbfb1381ce091704073d878495b">IterablePart</a>() {}</div><div class="line"><a name="l00192"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae05724f38a9dbde27efff486cfde1e81"> 192</a></span>&#160; <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae05724f38a9dbde27efff486cfde1e81">IterablePart</a>(<span class="keyword">const</span> std::vector&lt;int&gt;::const_iterator&amp; b,</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; <span class="keyword">const</span> std::vector&lt;int&gt;::const_iterator&amp; e)</div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; : <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0">begin_</a>(b), <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818">end_</a>(e) {}</div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160;</div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; <span class="comment">// These typedefs allow this iterator to be used within testing::ElementsAre.</span></div><div class="line"><a name="l00197"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae0d65370bdf691912b56f25f52a4561e"> 197</a></span>&#160; <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae0d65370bdf691912b56f25f52a4561e">value_type</a>;</div><div class="line"><a name="l00198"></a><span class="lineno"><a class="line" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a449c15b1c8a64ef6572463e2f21ae174"> 198</a></span>&#160; <span class="keyword">typedef</span> std::vector&lt;int&gt;::const_iterator <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a449c15b1c8a64ef6572463e2f21ae174">const_iterator</a>;</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span>&#160;};</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>&#160;</div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>&#160;<span class="comment">// Partition class that supports incremental merging, using the union-find</span></div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>&#160;<span class="comment">// algorithm (see http://en.wikipedia.org/wiki/Disjoint-set_data_structure).</span></div><div class="line"><a name="l00203"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html"> 203</a></span>&#160;<span class="keyword">class </span><a class="code" href="classoperations__research_1_1MergingPartition.html">MergingPartition</a> {</div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>&#160; <span class="comment">// At first, all nodes are in their own singleton part.</span></div><div class="line"><a name="l00206"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a561892525aa4b6891d5f7636f62cd749"> 206</a></span>&#160; <a class="code" href="classoperations__research_1_1MergingPartition.html#a561892525aa4b6891d5f7636f62cd749">MergingPartition</a>() { <a class="code" href="classoperations__research_1_1MergingPartition.html#a2acc4c8e2883189a896862486d160438">Reset</a>(0); }</div><div class="line"><a name="l00207"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a2dddfdd1d086883ce9a1306acf647f30"> 207</a></span>&#160; <span class="keyword">explicit</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a2dddfdd1d086883ce9a1306acf647f30">MergingPartition</a>(<span class="keywordtype">int</span> num_nodes) { <a class="code" href="classoperations__research_1_1MergingPartition.html#a2acc4c8e2883189a896862486d160438">Reset</a>(num_nodes); }</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span>&#160; <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a2acc4c8e2883189a896862486d160438">Reset</a>(<span class="keywordtype">int</span> num_nodes);</div><div class="line"><a name="l00209"></a><span class="lineno"> 209</span>&#160;</div><div class="line"><a name="l00210"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f"> 210</a></span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">NumNodes</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> parent_.size(); }</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span>&#160;</div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span>&#160; <span class="comment">// Complexity: amortized O(Ackermann⁻¹(N)) -- which is essentially O(1) --</span></div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span>&#160; <span class="comment">// where N is the number of nodes.</span></div><div class="line"><a name="l00214"></a><span class="lineno"> 214</span>&#160; <span class="comment">//</span></div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>&#160; <span class="comment">// Return value: If this merge caused a representative node (of either node1</span></div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>&#160; <span class="comment">// or node2) to stop being a representative (because only one can remain);</span></div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>&#160; <span class="comment">// this method returns that removed representative. Otherwise it returns -1.</span></div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>&#160; <span class="comment">//</span></div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span>&#160; <span class="comment">// Details: a smaller part will always be merged onto a larger one.</span></div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>&#160; <span class="comment">// Upons ties, the smaller representative becomes the overall representative.</span></div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a189669a00c0a94f224db9005c8925310">MergePartsOf</a>(<span class="keywordtype">int</span> node1, <span class="keywordtype">int</span> node2); <span class="comment">// The &#39;union&#39; of the union-find.</span></div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span>&#160;</div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span>&#160; <span class="comment">// Get the representative of &quot;node&quot; (a node in the same equivalence class,</span></div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160; <span class="comment">// which will also be returned for any other &quot;node&quot; in the same class).</span></div><div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160; <span class="comment">// The complexity if the same as MergePartsOf().</span></div><div class="line"><a name="l00226"></a><span class="lineno"> 226</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#ab5aff2ca8ee76377b90e75f369a06965">GetRootAndCompressPath</a>(<span class="keywordtype">int</span> node);</div><div class="line"><a name="l00227"></a><span class="lineno"> 227</span>&#160;</div><div class="line"><a name="l00228"></a><span class="lineno"> 228</span>&#160; <span class="comment">// Specialized reader API: prunes &quot;nodes&quot; to only keep at most one node per</span></div><div class="line"><a name="l00229"></a><span class="lineno"> 229</span>&#160; <span class="comment">// part: any node which is in the same part as an earlier node will be pruned.</span></div><div class="line"><a name="l00230"></a><span class="lineno"> 230</span>&#160; <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a09305f65b966f5d00cdb7c5e3fcec43a">KeepOnlyOneNodePerPart</a>(std::vector&lt;int&gt;* nodes);</div><div class="line"><a name="l00231"></a><span class="lineno"> 231</span>&#160;</div><div class="line"><a name="l00232"></a><span class="lineno"> 232</span>&#160; <span class="comment">// Output the whole partition as node equivalence classes: if there are K</span></div><div class="line"><a name="l00233"></a><span class="lineno"> 233</span>&#160; <span class="comment">// parts and N nodes, node_equivalence_classes[i] will contain the part index</span></div><div class="line"><a name="l00234"></a><span class="lineno"> 234</span>&#160; <span class="comment">// (a number in 0..K-1) of node #i. Parts will be sorted by their first node</span></div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span>&#160; <span class="comment">// (i.e. node 0 will always be in part 0; then the next node that isn&#39;t in</span></div><div class="line"><a name="l00236"></a><span class="lineno"> 236</span>&#160; <span class="comment">// part 0 will be in part 1, and so on).</span></div><div class="line"><a name="l00237"></a><span class="lineno"> 237</span>&#160; <span class="comment">// Returns the number K of classes.</span></div><div class="line"><a name="l00238"></a><span class="lineno"> 238</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a450228c4fe64624a5c075a462ff91290">FillEquivalenceClasses</a>(std::vector&lt;int&gt;* node_equivalence_classes);</div><div class="line"><a name="l00239"></a><span class="lineno"> 239</span>&#160;</div><div class="line"><a name="l00240"></a><span class="lineno"> 240</span>&#160; <span class="comment">// Dump all components, with nodes sorted within each part and parts</span></div><div class="line"><a name="l00241"></a><span class="lineno"> 241</span>&#160; <span class="comment">// sorted lexicographically. Eg. &quot;0 1 3 4 | 2 5 | 6 7 8&quot;.</span></div><div class="line"><a name="l00242"></a><span class="lineno"> 242</span>&#160; std::string <a class="code" href="classoperations__research_1_1MergingPartition.html#a62fb42554b2c7db5121b5b4230188d9d">DebugString</a>();</div><div class="line"><a name="l00243"></a><span class="lineno"> 243</span>&#160;</div><div class="line"><a name="l00244"></a><span class="lineno"> 244</span>&#160; <span class="comment">// Advanced usage: sets &#39;node&#39; to be in its original singleton. All nodes</span></div><div class="line"><a name="l00245"></a><span class="lineno"> 245</span>&#160; <span class="comment">// who may point to &#39;node&#39; as a parent will remain in an inconsistent state.</span></div><div class="line"><a name="l00246"></a><span class="lineno"> 246</span>&#160; <span class="comment">// This can be used to reinitialize a MergingPartition that has been sparsely</span></div><div class="line"><a name="l00247"></a><span class="lineno"> 247</span>&#160; <span class="comment">// modified in O(|modifications|).</span></div><div class="line"><a name="l00248"></a><span class="lineno"> 248</span>&#160; <span class="comment">// CRASHES IF USED INCORRECTLY.</span></div><div class="line"><a name="l00249"></a><span class="lineno"> 249</span>&#160; <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a955ac764e9c8dcd4358202de4ecd47fd">ResetNode</a>(<span class="keywordtype">int</span> node);</div><div class="line"><a name="l00250"></a><span class="lineno"> 250</span>&#160;</div><div class="line"><a name="l00251"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a154e7e5b242aa754c41d709d3bc351c1"> 251</a></span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a154e7e5b242aa754c41d709d3bc351c1">NumNodesInSamePartAs</a>(<span class="keywordtype">int</span> node) {</div><div class="line"><a name="l00252"></a><span class="lineno"> 252</span>&#160; <span class="keywordflow">return</span> part_size_[<a class="code" href="classoperations__research_1_1MergingPartition.html#ab5aff2ca8ee76377b90e75f369a06965">GetRootAndCompressPath</a>(node)];</div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>&#160; }</div><div class="line"><a name="l00254"></a><span class="lineno"> 254</span>&#160;</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span>&#160; <span class="comment">// FOR DEBUGGING OR SPECIAL &quot;CONST&quot; ACCESS ONLY:</span></div><div class="line"><a name="l00256"></a><span class="lineno"> 256</span>&#160; <span class="comment">// Find the root of the union-find tree with leaf &#39;node&#39;, i.e. its</span></div><div class="line"><a name="l00257"></a><span class="lineno"> 257</span>&#160; <span class="comment">// representative node, but don&#39;t use path compression.</span></div><div class="line"><a name="l00258"></a><span class="lineno"> 258</span>&#160; <span class="comment">// The amortized complexity can be as bad as log(N), as opposed to the</span></div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span>&#160; <span class="comment">// version using path compression.</span></div><div class="line"><a name="l00260"></a><span class="lineno"> 260</span>&#160; <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a57d8288fbe286978c65abf82bd051000">GetRoot</a>(<span class="keywordtype">int</span> node) <span class="keyword">const</span>;</div><div class="line"><a name="l00261"></a><span class="lineno"> 261</span>&#160;</div><div class="line"><a name="l00262"></a><span class="lineno"> 262</span>&#160; <span class="keyword">private</span>:</div><div class="line"><a name="l00263"></a><span class="lineno"> 263</span>&#160; <span class="comment">// Along the upwards path from &#39;node&#39; to its root, set the parent of all</span></div><div class="line"><a name="l00264"></a><span class="lineno"> 264</span>&#160; <span class="comment">// nodes (including the root) to &#39;parent&#39;.</span></div><div class="line"><a name="l00265"></a><span class="lineno"> 265</span>&#160; <span class="keywordtype">void</span> SetParentAlongPathToRoot(<span class="keywordtype">int</span> node, <span class="keywordtype">int</span> parent);</div><div class="line"><a name="l00266"></a><span class="lineno"> 266</span>&#160;</div><div class="line"><a name="l00267"></a><span class="lineno"> 267</span>&#160; std::vector&lt;int&gt; parent_;</div><div class="line"><a name="l00268"></a><span class="lineno"> 268</span>&#160; std::vector&lt;int&gt; part_size_;</div><div class="line"><a name="l00269"></a><span class="lineno"> 269</span>&#160;</div><div class="line"><a name="l00270"></a><span class="lineno"> 270</span>&#160; <span class="comment">// Used transiently by KeepOnlyOneNodePerPart().</span></div><div class="line"><a name="l00271"></a><span class="lineno"> 271</span>&#160; std::vector&lt;bool&gt; tmp_part_bit_;</div><div class="line"><a name="l00272"></a><span class="lineno"> 272</span>&#160;};</div><div class="line"><a name="l00273"></a><span class="lineno"> 273</span>&#160;</div><div class="line"><a name="l00274"></a><span class="lineno"> 274</span>&#160;<span class="comment">// *** Implementation of inline methods of the above classes. ***</span></div><div class="line"><a name="l00275"></a><span class="lineno"> 275</span>&#160;</div><div class="line"><a name="l00276"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#ac1dcc361f73f495e0f362f834b224e89"> 276</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html">DynamicPartition::IterablePart</a> <a class="code" href="classoperations__research_1_1DynamicPartition.html#ac1dcc361f73f495e0f362f834b224e89">DynamicPartition::ElementsInPart</a>(</div><div class="line"><a name="l00277"></a><span class="lineno"> 277</span>&#160; <span class="keywordtype">int</span> i)<span class="keyword"> const </span>{</div><div class="line"><a name="l00278"></a><span class="lineno"> 278</span>&#160; DCHECK_GE(i, 0);</div><div class="line"><a name="l00279"></a><span class="lineno"> 279</span>&#160; DCHECK_LT(i, <a class="code" href="classoperations__research_1_1DynamicPartition.html#a0f4d81d407e148e26480f5ef01778270">NumParts</a>());</div><div class="line"><a name="l00280"></a><span class="lineno"> 280</span>&#160; <span class="keywordflow">return</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html">IterablePart</a>(element_.begin() + part_[i].start_index,</div><div class="line"><a name="l00281"></a><span class="lineno"> 281</span>&#160; element_.begin() + part_[i].end_index);</div><div class="line"><a name="l00282"></a><span class="lineno"> 282</span>&#160;}</div><div class="line"><a name="l00283"></a><span class="lineno"> 283</span>&#160;</div><div class="line"><a name="l00284"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#af3a2c6e1e18891125f15e42e391055bb"> 284</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#af3a2c6e1e18891125f15e42e391055bb">DynamicPartition::PartOf</a>(<span class="keywordtype">int</span> element)<span class="keyword"> const </span>{</div><div class="line"><a name="l00285"></a><span class="lineno"> 285</span>&#160; DCHECK_GE(element, 0);</div><div class="line"><a name="l00286"></a><span class="lineno"> 286</span>&#160; DCHECK_LT(element, part_of_.size());</div><div class="line"><a name="l00287"></a><span class="lineno"> 287</span>&#160; <span class="keywordflow">return</span> part_of_[element];</div><div class="line"><a name="l00288"></a><span class="lineno"> 288</span>&#160;}</div><div class="line"><a name="l00289"></a><span class="lineno"> 289</span>&#160;</div><div class="line"><a name="l00290"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a87ccb17e1972d153100a9b061a918ba1"> 290</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a87ccb17e1972d153100a9b061a918ba1">DynamicPartition::SizeOfPart</a>(<span class="keywordtype">int</span> part)<span class="keyword"> const </span>{</div><div class="line"><a name="l00291"></a><span class="lineno"> 291</span>&#160; DCHECK_GE(part, 0);</div><div class="line"><a name="l00292"></a><span class="lineno"> 292</span>&#160; DCHECK_LT(part, part_.size());</div><div class="line"><a name="l00293"></a><span class="lineno"> 293</span>&#160; <span class="keyword">const</span> Part&amp; p = part_[part];</div><div class="line"><a name="l00294"></a><span class="lineno"> 294</span>&#160; <span class="keywordflow">return</span> p.end_index - p.start_index;</div><div class="line"><a name="l00295"></a><span class="lineno"> 295</span>&#160;}</div><div class="line"><a name="l00296"></a><span class="lineno"> 296</span>&#160;</div><div class="line"><a name="l00297"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a079d605b371556e228347843c9b15d2d"> 297</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a079d605b371556e228347843c9b15d2d">DynamicPartition::ParentOfPart</a>(<span class="keywordtype">int</span> part)<span class="keyword"> const </span>{</div><div class="line"><a name="l00298"></a><span class="lineno"> 298</span>&#160; DCHECK_GE(part, 0);</div><div class="line"><a name="l00299"></a><span class="lineno"> 299</span>&#160; DCHECK_LT(part, part_.size());</div><div class="line"><a name="l00300"></a><span class="lineno"> 300</span>&#160; <span class="keywordflow">return</span> part_[part].parent_part;</div><div class="line"><a name="l00301"></a><span class="lineno"> 301</span>&#160;}</div><div class="line"><a name="l00302"></a><span class="lineno"> 302</span>&#160;</div><div class="line"><a name="l00303"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a79106998d8499c5c25f4c74c14456b60"> 303</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html">DynamicPartition::IterablePart</a> <a class="code" href="classoperations__research_1_1DynamicPartition.html#a79106998d8499c5c25f4c74c14456b60">DynamicPartition::ElementsInSamePartAs</a>(</div><div class="line"><a name="l00304"></a><span class="lineno"> 304</span>&#160; <span class="keywordtype">int</span> i)<span class="keyword"> const </span>{</div><div class="line"><a name="l00305"></a><span class="lineno"> 305</span>&#160; <span class="keywordflow">return</span> <a class="code" href="classoperations__research_1_1DynamicPartition.html#ac1dcc361f73f495e0f362f834b224e89">ElementsInPart</a>(<a class="code" href="classoperations__research_1_1DynamicPartition.html#af3a2c6e1e18891125f15e42e391055bb">PartOf</a>(i));</div><div class="line"><a name="l00306"></a><span class="lineno"> 306</span>&#160;}</div><div class="line"><a name="l00307"></a><span class="lineno"> 307</span>&#160;</div><div class="line"><a name="l00308"></a><span class="lineno"><a class="line" href="classoperations__research_1_1DynamicPartition.html#a4e68b8de69272cf549b346595d332198"> 308</a></span>&#160;<span class="keyword">inline</span> uint64 <a class="code" href="classoperations__research_1_1DynamicPartition.html#a4e68b8de69272cf549b346595d332198">DynamicPartition::FprintOfPart</a>(<span class="keywordtype">int</span> part)<span class="keyword"> const </span>{</div><div class="line"><a name="l00309"></a><span class="lineno"> 309</span>&#160; DCHECK_GE(part, 0);</div><div class="line"><a name="l00310"></a><span class="lineno"> 310</span>&#160; DCHECK_LT(part, part_.size());</div><div class="line"><a name="l00311"></a><span class="lineno"> 311</span>&#160; <span class="keywordflow">return</span> part_[part].fprint;</div><div class="line"><a name="l00312"></a><span class="lineno"> 312</span>&#160;}</div><div class="line"><a name="l00313"></a><span class="lineno"> 313</span>&#160;</div><div class="line"><a name="l00314"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a57d8288fbe286978c65abf82bd051000"> 314</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a57d8288fbe286978c65abf82bd051000">MergingPartition::GetRoot</a>(<span class="keywordtype">int</span> node)<span class="keyword"> const </span>{</div><div class="line"><a name="l00315"></a><span class="lineno"> 315</span>&#160; DCHECK_GE(node, 0);</div><div class="line"><a name="l00316"></a><span class="lineno"> 316</span>&#160; DCHECK_LT(node, <a class="code" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">NumNodes</a>());</div><div class="line"><a name="l00317"></a><span class="lineno"> 317</span>&#160; <span class="keywordtype">int</span> child = node;</div><div class="line"><a name="l00318"></a><span class="lineno"> 318</span>&#160; <span class="keywordflow">while</span> (<span class="keyword">true</span>) {</div><div class="line"><a name="l00319"></a><span class="lineno"> 319</span>&#160; <span class="keyword">const</span> <span class="keywordtype">int</span> parent = parent_[child];</div><div class="line"><a name="l00320"></a><span class="lineno"> 320</span>&#160; <span class="keywordflow">if</span> (parent == child) <span class="keywordflow">return</span> child;</div><div class="line"><a name="l00321"></a><span class="lineno"> 321</span>&#160; child = parent;</div><div class="line"><a name="l00322"></a><span class="lineno"> 322</span>&#160; }</div><div class="line"><a name="l00323"></a><span class="lineno"> 323</span>&#160;}</div><div class="line"><a name="l00324"></a><span class="lineno"> 324</span>&#160;</div><div class="line"><a name="l00325"></a><span class="lineno"> 325</span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> MergingPartition::SetParentAlongPathToRoot(<span class="keywordtype">int</span> node, <span class="keywordtype">int</span> parent) {</div><div class="line"><a name="l00326"></a><span class="lineno"> 326</span>&#160; DCHECK_GE(node, 0);</div><div class="line"><a name="l00327"></a><span class="lineno"> 327</span>&#160; DCHECK_LT(node, <a class="code" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">NumNodes</a>());</div><div class="line"><a name="l00328"></a><span class="lineno"> 328</span>&#160; DCHECK_GE(parent, 0);</div><div class="line"><a name="l00329"></a><span class="lineno"> 329</span>&#160; DCHECK_LT(parent, <a class="code" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">NumNodes</a>());</div><div class="line"><a name="l00330"></a><span class="lineno"> 330</span>&#160; <span class="keywordtype">int</span> child = node;</div><div class="line"><a name="l00331"></a><span class="lineno"> 331</span>&#160; <span class="keywordflow">while</span> (<span class="keyword">true</span>) {</div><div class="line"><a name="l00332"></a><span class="lineno"> 332</span>&#160; <span class="keyword">const</span> <span class="keywordtype">int</span> old_parent = parent_[child];</div><div class="line"><a name="l00333"></a><span class="lineno"> 333</span>&#160; parent_[child] = parent;</div><div class="line"><a name="l00334"></a><span class="lineno"> 334</span>&#160; <span class="keywordflow">if</span> (old_parent == child) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00335"></a><span class="lineno"> 335</span>&#160; child = old_parent;</div><div class="line"><a name="l00336"></a><span class="lineno"> 336</span>&#160; }</div><div class="line"><a name="l00337"></a><span class="lineno"> 337</span>&#160;}</div><div class="line"><a name="l00338"></a><span class="lineno"> 338</span>&#160;</div><div class="line"><a name="l00339"></a><span class="lineno"><a class="line" href="classoperations__research_1_1MergingPartition.html#a955ac764e9c8dcd4358202de4ecd47fd"> 339</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classoperations__research_1_1MergingPartition.html#a955ac764e9c8dcd4358202de4ecd47fd">MergingPartition::ResetNode</a>(<span class="keywordtype">int</span> node) {</div><div class="line"><a name="l00340"></a><span class="lineno"> 340</span>&#160; DCHECK_GE(node, 0);</div><div class="line"><a name="l00341"></a><span class="lineno"> 341</span>&#160; DCHECK_LT(node, <a class="code" href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">NumNodes</a>());</div><div class="line"><a name="l00342"></a><span class="lineno"> 342</span>&#160; parent_[node] = node;</div><div class="line"><a name="l00343"></a><span class="lineno"> 343</span>&#160; part_size_[node] = 1;</div><div class="line"><a name="l00344"></a><span class="lineno"> 344</span>&#160;}</div><div class="line"><a name="l00345"></a><span class="lineno"> 345</span>&#160;</div><div class="line"><a name="l00346"></a><span class="lineno"> 346</span>&#160;} <span class="comment">// namespace operations_research</span></div><div class="line"><a name="l00347"></a><span class="lineno"> 347</span>&#160;</div><div class="line"><a name="l00348"></a><span class="lineno"> 348</span>&#160;<span class="preprocessor">#endif // OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_</span></div><div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a87ccb17e1972d153100a9b061a918ba1"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a87ccb17e1972d153100a9b061a918ba1">operations_research::DynamicPartition::SizeOfPart</a></div><div class="ttdeci">int SizeOfPart(int part) const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00290">dynamic_partition.h:290</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_af3a2c6e1e18891125f15e42e391055bb"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#af3a2c6e1e18891125f15e42e391055bb">operations_research::DynamicPartition::PartOf</a></div><div class="ttdeci">int PartOf(int element) const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00284">dynamic_partition.h:284</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a62fb42554b2c7db5121b5b4230188d9d"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a62fb42554b2c7db5121b5b4230188d9d">operations_research::MergingPartition::DebugString</a></div><div class="ttdeci">std::string DebugString()</div><div class="ttdoc">Dump all components, with nodes sorted within each part and parts sorted lexicographically.</div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_ac1869cef1d61b3cf54d2336f9e1768b0"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ac1869cef1d61b3cf54d2336f9e1768b0">operations_research::DynamicPartition::IterablePart::begin_</a></div><div class="ttdeci">std::vector&lt; int &gt;::const_iterator begin_</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00186">dynamic_partition.h:186</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a2dddfdd1d086883ce9a1306acf647f30"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a2dddfdd1d086883ce9a1306acf647f30">operations_research::MergingPartition::MergingPartition</a></div><div class="ttdeci">MergingPartition(int num_nodes)</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00207">dynamic_partition.h:207</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a79106998d8499c5c25f4c74c14456b60"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a79106998d8499c5c25f4c74c14456b60">operations_research::DynamicPartition::ElementsInSamePartAs</a></div><div class="ttdeci">IterablePart ElementsInSamePartAs(int i) const</div><div class="ttdoc">A handy shortcut to ElementsInPart(PartOf(e)).</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00303">dynamic_partition.h:303</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a079d605b371556e228347843c9b15d2d"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a079d605b371556e228347843c9b15d2d">operations_research::DynamicPartition::ParentOfPart</a></div><div class="ttdeci">int ParentOfPart(int part) const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00297">dynamic_partition.h:297</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html">operations_research::DynamicPartition::IterablePart</a></div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00183">dynamic_partition.h:183</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_a4858bbbfb1381ce091704073d878495b"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a4858bbbfb1381ce091704073d878495b">operations_research::DynamicPartition::IterablePart::IterablePart</a></div><div class="ttdeci">IterablePart()</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00191">dynamic_partition.h:191</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html">operations_research::MergingPartition</a></div><div class="ttdoc">Partition class that supports incremental merging, using the union-find algorithm (see http://en....</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00203">dynamic_partition.h:203</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_ac535d0a440192c96effe5b938a9482c7"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#ac535d0a440192c96effe5b938a9482c7">operations_research::DynamicPartition::DebugString</a></div><div class="ttdeci">std::string DebugString(DebugStringSorting sorting) const</div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_afe6f90b99c0b1d646b00ad2d1bb0a09d"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#afe6f90b99c0b1d646b00ad2d1bb0a09d">operations_research::DynamicPartition::DynamicPartition</a></div><div class="ttdeci">DynamicPartition(int num_elements)</div><div class="ttdoc">Creates a DynamicPartition on n elements, numbered 0..n-1.</div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a67b2a5be57842485dcb3c3db93bc2e1a"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1a">operations_research::DynamicPartition::DebugStringSorting</a></div><div class="ttdeci">DebugStringSorting</div><div class="ttdoc">Dump the partition to a std::string.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00117">dynamic_partition.h:117</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a955ac764e9c8dcd4358202de4ecd47fd"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a955ac764e9c8dcd4358202de4ecd47fd">operations_research::MergingPartition::ResetNode</a></div><div class="ttdeci">void ResetNode(int node)</div><div class="ttdoc">Advanced usage: sets 'node' to be in its original singleton.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00339">dynamic_partition.h:339</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a67b2a5be57842485dcb3c3db93bc2e1aacb9b001cac613035de5d6f1f38f7fda1"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aacb9b001cac613035de5d6f1f38f7fda1">operations_research::DynamicPartition::SORT_LEXICOGRAPHICALLY</a></div><div class="ttdoc">Elements are sorted within parts, and parts are then sorted lexicographically.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00120">dynamic_partition.h:120</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a0f4d81d407e148e26480f5ef01778270"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a0f4d81d407e148e26480f5ef01778270">operations_research::DynamicPartition::NumParts</a></div><div class="ttdeci">const int NumParts() const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00061">dynamic_partition.h:61</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_ae0d65370bdf691912b56f25f52a4561e"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae0d65370bdf691912b56f25f52a4561e">operations_research::DynamicPartition::IterablePart::value_type</a></div><div class="ttdeci">int value_type</div><div class="ttdoc">These typedefs allow this iterator to be used within testing::ElementsAre.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00197">dynamic_partition.h:197</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html">operations_research::DynamicPartition</a></div><div class="ttdoc">Partition class that supports incremental splitting, with backtracking.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00049">dynamic_partition.h:49</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_abd3e25c24209be1e6cffda93230bbdd9"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#abd3e25c24209be1e6cffda93230bbdd9">operations_research::DynamicPartition::IterablePart::end</a></div><div class="ttdeci">std::vector&lt; int &gt;::const_iterator end() const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00185">dynamic_partition.h:185</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_ac1dcc361f73f495e0f362f834b224e89"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#ac1dcc361f73f495e0f362f834b224e89">operations_research::DynamicPartition::ElementsInPart</a></div><div class="ttdeci">IterablePart ElementsInPart(int i) const</div><div class="ttdoc">*** Implementation of inline methods of the above classes. ***</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00276">dynamic_partition.h:276</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_ab516c7e5e0e64a4fca27ab1790d459e5"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#ab516c7e5e0e64a4fca27ab1790d459e5">operations_research::DynamicPartition::ElementsInHierarchicalOrder</a></div><div class="ttdeci">const std::vector&lt; int &gt; &amp; ElementsInHierarchicalOrder() const</div><div class="ttdoc">ADVANCED USAGE: All elements (0..n-1) of the partition, sorted in a way that's compatible with the hi...</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00136">dynamic_partition.h:136</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a09305f65b966f5d00cdb7c5e3fcec43a"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a09305f65b966f5d00cdb7c5e3fcec43a">operations_research::MergingPartition::KeepOnlyOneNodePerPart</a></div><div class="ttdeci">void KeepOnlyOneNodePerPart(std::vector&lt; int &gt; *nodes)</div><div class="ttdoc">Specialized reader API: prunes &quot;nodes&quot; to only keep at most one node per part: any node which is in t...</div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_ab5aff2ca8ee76377b90e75f369a06965"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#ab5aff2ca8ee76377b90e75f369a06965">operations_research::MergingPartition::GetRootAndCompressPath</a></div><div class="ttdeci">int GetRootAndCompressPath(int node)</div><div class="ttdoc">Get the representative of &quot;node&quot; (a node in the same equivalence class, which will also be returned f...</div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_a449c15b1c8a64ef6572463e2f21ae174"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a449c15b1c8a64ef6572463e2f21ae174">operations_research::DynamicPartition::IterablePart::const_iterator</a></div><div class="ttdeci">std::vector&lt; int &gt;::const_iterator const_iterator</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00198">dynamic_partition.h:198</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a2acc4c8e2883189a896862486d160438"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a2acc4c8e2883189a896862486d160438">operations_research::MergingPartition::Reset</a></div><div class="ttdeci">void Reset(int num_nodes)</div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_ab1abe2eb3716aa80bd29b1e7260484a2"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ab1abe2eb3716aa80bd29b1e7260484a2">operations_research::DynamicPartition::IterablePart::begin</a></div><div class="ttdeci">std::vector&lt; int &gt;::const_iterator begin() const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00184">dynamic_partition.h:184</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a561892525aa4b6891d5f7636f62cd749"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a561892525aa4b6891d5f7636f62cd749">operations_research::MergingPartition::MergingPartition</a></div><div class="ttdeci">MergingPartition()</div><div class="ttdoc">At first, all nodes are in their own singleton part.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00206">dynamic_partition.h:206</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_ae05724f38a9dbde27efff486cfde1e81"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#ae05724f38a9dbde27efff486cfde1e81">operations_research::DynamicPartition::IterablePart::IterablePart</a></div><div class="ttdeci">IterablePart(const std::vector&lt; int &gt;::const_iterator &amp;b, const std::vector&lt; int &gt;::const_iterator &amp;e)</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00192">dynamic_partition.h:192</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a8e5d14e6155d2a01fe50fc088ee55f3f"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a8e5d14e6155d2a01fe50fc088ee55f3f">operations_research::MergingPartition::NumNodes</a></div><div class="ttdeci">int NumNodes() const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00210">dynamic_partition.h:210</a></div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_a811d152ac3bcfa8132b5dc1e5c0e5818"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a811d152ac3bcfa8132b5dc1e5c0e5818">operations_research::DynamicPartition::IterablePart::end_</a></div><div class="ttdeci">std::vector&lt; int &gt;::const_iterator end_</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00187">dynamic_partition.h:187</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a67b2a5be57842485dcb3c3db93bc2e1aa5edad0b79a2c83ec1b1560960504c161"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a67b2a5be57842485dcb3c3db93bc2e1aa5edad0b79a2c83ec1b1560960504c161">operations_research::DynamicPartition::SORT_BY_PART</a></div><div class="ttdoc">Elements are sorted within parts, and parts are kept in order.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00122">dynamic_partition.h:122</a></div></div>
<div class="ttc" id="namespaceoperations__research_html"><div class="ttname"><a href="namespaceoperations__research.html">operations_research</a></div><div class="ttdoc">Licensed under the Apache License, Version 2.0 (the &quot;License&quot;); you may not use this file except in c...</div><div class="ttdef"><b>Definition:</b> <a href="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a57d8288fbe286978c65abf82bd051000"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a57d8288fbe286978c65abf82bd051000">operations_research::MergingPartition::GetRoot</a></div><div class="ttdeci">int GetRoot(int node) const</div><div class="ttdoc">FOR DEBUGGING OR SPECIAL &quot;CONST&quot; ACCESS ONLY: Find the root of the union-find tree with leaf 'node',...</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00314">dynamic_partition.h:314</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a968140cdf9d2766625e1d476a7a71590"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a968140cdf9d2766625e1d476a7a71590">operations_research::DynamicPartition::UndoRefineUntilNumPartsEqual</a></div><div class="ttdeci">void UndoRefineUntilNumPartsEqual(int original_num_parts)</div><div class="ttdoc">Undo one or several Refine() operations, until the number of parts becomes equal to &quot;original_num_par...</div></div>
<div class="ttc" id="structoperations__research_1_1DynamicPartition_1_1IterablePart_html_a757903108b39220312da2867ca8babe8"><div class="ttname"><a href="structoperations__research_1_1DynamicPartition_1_1IterablePart.html#a757903108b39220312da2867ca8babe8">operations_research::DynamicPartition::IterablePart::size</a></div><div class="ttdeci">int size() const</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00189">dynamic_partition.h:189</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a450228c4fe64624a5c075a462ff91290"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a450228c4fe64624a5c075a462ff91290">operations_research::MergingPartition::FillEquivalenceClasses</a></div><div class="ttdeci">int FillEquivalenceClasses(std::vector&lt; int &gt; *node_equivalence_classes)</div><div class="ttdoc">Output the whole partition as node equivalence classes: if there are K parts and N nodes,...</div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a4b07bd0eb40bb3fcb3419672313342ea"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a4b07bd0eb40bb3fcb3419672313342ea">operations_research::DynamicPartition::NumElements</a></div><div class="ttdeci">int NumElements() const</div><div class="ttdoc">Accessors.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00060">dynamic_partition.h:60</a></div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a16fce09dd4c359a6acfd0a864e0a5ebd"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a16fce09dd4c359a6acfd0a864e0a5ebd">operations_research::DynamicPartition::Refine</a></div><div class="ttdeci">void Refine(const std::vector&lt; int &gt; &amp;distinguished_subset)</div><div class="ttdoc">Refines the partition such that elements that are in distinguished_subset never share the same part a...</div></div>
<div class="ttc" id="classoperations__research_1_1DynamicPartition_html_a4e68b8de69272cf549b346595d332198"><div class="ttname"><a href="classoperations__research_1_1DynamicPartition.html#a4e68b8de69272cf549b346595d332198">operations_research::DynamicPartition::FprintOfPart</a></div><div class="ttdeci">uint64 FprintOfPart(int part) const</div><div class="ttdoc">Returns a fingerprint of the given part.</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00308">dynamic_partition.h:308</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a154e7e5b242aa754c41d709d3bc351c1"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a154e7e5b242aa754c41d709d3bc351c1">operations_research::MergingPartition::NumNodesInSamePartAs</a></div><div class="ttdeci">int NumNodesInSamePartAs(int node)</div><div class="ttdef"><b>Definition:</b> <a href="dynamic__partition_8h_source.html#l00251">dynamic_partition.h:251</a></div></div>
<div class="ttc" id="classoperations__research_1_1MergingPartition_html_a189669a00c0a94f224db9005c8925310"><div class="ttname"><a href="classoperations__research_1_1MergingPartition.html#a189669a00c0a94f224db9005c8925310">operations_research::MergingPartition::MergePartsOf</a></div><div class="ttdeci">int MergePartsOf(int node1, int node2)</div><div class="ttdoc">Complexity: amortized O(Ackermann⁻¹(N)) which is essentially O(1) where N is the number of nodes.</div></div>
</div><!-- fragment --></div><!-- contents -->
</div>
<div id="footer-container">
<div id="footer">
</div>
</div>
</body>
</html>