<ahref="max__flow_8h.html">Go to the documentation of this file.</a><divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="comment">// Copyright 2010-2018 Google LLC</span></div>
<divclass="line"><aname="l00002"></a><spanclass="lineno"> 2</span> <spanclass="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div>
<divclass="line"><aname="l00003"></a><spanclass="lineno"> 3</span> <spanclass="comment">// you may not use this file except in compliance with the License.</span></div>
<divclass="line"><aname="l00004"></a><spanclass="lineno"> 4</span> <spanclass="comment">// You may obtain a copy of the License at</span></div>
<divclass="line"><aname="l00008"></a><spanclass="lineno"> 8</span> <spanclass="comment">// Unless required by applicable law or agreed to in writing, software</span></div>
<divclass="line"><aname="l00009"></a><spanclass="lineno"> 9</span> <spanclass="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div>
<divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> <spanclass="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span> <spanclass="comment">// See the License for the specific language governing permissions and</span></div>
<divclass="line"><aname="l00012"></a><spanclass="lineno"> 12</span> <spanclass="comment">// limitations under the License.</span></div>
<divclass="line"><aname="l00014"></a><spanclass="lineno"> 14</span> <spanclass="comment">// An implementation of a push-relabel algorithm for the max flow problem.</span></div>
<divclass="line"><aname="l00016"></a><spanclass="lineno"> 16</span> <spanclass="comment">// In the following, we consider a graph G = (V,E,s,t) where V denotes the set</span></div>
<divclass="line"><aname="l00017"></a><spanclass="lineno"> 17</span> <spanclass="comment">// of nodes (vertices) in the graph, E denotes the set of arcs (edges). s and t</span></div>
<divclass="line"><aname="l00018"></a><spanclass="lineno"> 18</span> <spanclass="comment">// denote distinguished nodes in G called source and target. n = |V| denotes the</span></div>
<divclass="line"><aname="l00019"></a><spanclass="lineno"> 19</span> <spanclass="comment">// number of nodes in the graph, and m = |E| denotes the number of arcs in the</span></div>
<divclass="line"><aname="l00022"></a><spanclass="lineno"> 22</span> <spanclass="comment">// Each arc (v,w) is associated a capacity c(v,w).</span></div>
<divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span> <spanclass="comment">// A flow is a function from E to R such that:</span></div>
<divclass="line"><aname="l00026"></a><spanclass="lineno"> 26</span> <spanclass="comment">// a) f(v,w) <= c(v,w) for all (v,w) in E (capacity constraint.)</span></div>
<divclass="line"><aname="l00028"></a><spanclass="lineno"> 28</span> <spanclass="comment">// b) f(v,w) = -f(w,v) for all (v,w) in E (flow antisymmetry constraint.)</span></div>
<divclass="line"><aname="l00030"></a><spanclass="lineno"> 30</span> <spanclass="comment">// c) sum on v f(v,w) = 0 (flow conservation.)</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"> 32</span> <spanclass="comment">// The goal of this algorithm is to find the maximum flow from s to t, i.e.</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"> 33</span> <spanclass="comment">// for example to maximize sum v f(s,v).</span></div>
<divclass="line"><aname="l00035"></a><spanclass="lineno"> 35</span> <spanclass="comment">// The starting reference for this class of algorithms is:</span></div>
<divclass="line"><aname="l00036"></a><spanclass="lineno"> 36</span> <spanclass="comment">// A.V. Goldberg and R.E. Tarjan. A new approach to the maximum flow problem.</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"> 37</span> <spanclass="comment">// ACM Symposium on Theory of Computing, pp. 136-146.</span></div>
<divclass="line"><aname="l00040"></a><spanclass="lineno"> 40</span> <spanclass="comment">// The basic idea of the algorithm is to handle preflows instead of flows,</span></div>
<divclass="line"><aname="l00041"></a><spanclass="lineno"> 41</span> <spanclass="comment">// and to refine preflows until a maximum flow is obtained.</span></div>
<divclass="line"><aname="l00042"></a><spanclass="lineno"> 42</span> <spanclass="comment">// A preflow is like a flow, except that the inflow can be larger than the</span></div>
<divclass="line"><aname="l00043"></a><spanclass="lineno"> 43</span> <spanclass="comment">// outflow. If it is the case at a given node v, it is said that there is an</span></div>
<divclass="line"><aname="l00044"></a><spanclass="lineno"> 44</span> <spanclass="comment">// excess at node v, and inflow = outflow + excess.</span></div>
<divclass="line"><aname="l00046"></a><spanclass="lineno"> 46</span> <spanclass="comment">// More formally, a preflow is a function f such that:</span></div>
<divclass="line"><aname="l00048"></a><spanclass="lineno"> 48</span> <spanclass="comment">// 1) f(v,w) <= c(v,w) for all (v,w) in E (capacity constraint). c(v,w) is a</span></div>
<divclass="line"><aname="l00049"></a><spanclass="lineno"> 49</span> <spanclass="comment">// value representing the maximum capacity for arc (v,w).</span></div>
<divclass="line"><aname="l00051"></a><spanclass="lineno"> 51</span> <spanclass="comment">// 2) f(v,w) = -f(w,v) for all (v,w) in E (flow antisymmetry constraint)</span></div>
<divclass="line"><aname="l00053"></a><spanclass="lineno"> 53</span> <spanclass="comment">// 3) excess(v) = sum on u f(u,v) >= 0 is the excess at node v, the</span></div>
<divclass="line"><aname="l00054"></a><spanclass="lineno"> 54</span> <spanclass="comment">// algebraic sum of all the incoming preflows at this node.</span></div>
<divclass="line"><aname="l00056"></a><spanclass="lineno"> 56</span> <spanclass="comment">// Each node has an associated "height", in addition to its excess. The</span></div>
<divclass="line"><aname="l00057"></a><spanclass="lineno"> 57</span> <spanclass="comment">// height of the source is defined to be equal to n, and cannot change. The</span></div>
<divclass="line"><aname="l00058"></a><spanclass="lineno"> 58</span> <spanclass="comment">// height of the target is defined to be zero, and cannot change either. The</span></div>
<divclass="line"><aname="l00059"></a><spanclass="lineno"> 59</span> <spanclass="comment">// height of all the other nodes is initialized at zero and is updated during</span></div>
<divclass="line"><aname="l00060"></a><spanclass="lineno"> 60</span> <spanclass="comment">// the algorithm (see below). For those who want to know the details, the height</span></div>
<divclass="line"><aname="l00061"></a><spanclass="lineno"> 61</span> <spanclass="comment">// of a node, corresponds to a reduced cost, and this enables one to prove that</span></div>
<divclass="line"><aname="l00062"></a><spanclass="lineno"> 62</span> <spanclass="comment">// the algorithm actually computes the max flow. Note that the height of a node</span></div>
<divclass="line"><aname="l00063"></a><spanclass="lineno"> 63</span> <spanclass="comment">// can be initialized to the distance to the target node in terms of number of</span></div>
<divclass="line"><aname="l00064"></a><spanclass="lineno"> 64</span> <spanclass="comment">// nodes. This has not been tried in this implementation.</span></div>
<divclass="line"><aname="l00066"></a><spanclass="lineno"> 66</span> <spanclass="comment">// A node v is said to be *active* if excess(v) > 0.</span></div>
<divclass="line"><aname="l00068"></a><spanclass="lineno"> 68</span> <spanclass="comment">// In this case the following operations can be applied to it:</span></div>
<divclass="line"><aname="l00070"></a><spanclass="lineno"> 70</span> <spanclass="comment">// - if there are *admissible* incident arcs, i.e. arcs which are not saturated,</span></div>
<divclass="line"><aname="l00071"></a><spanclass="lineno"> 71</span> <spanclass="comment">// and whose head's height is lower than the height of the active node</span></div>
<divclass="line"><aname="l00072"></a><spanclass="lineno"> 72</span> <spanclass="comment">// considered, a PushFlow operation can be applied. It consists in sending as</span></div>
<divclass="line"><aname="l00073"></a><spanclass="lineno"> 73</span> <spanclass="comment">// much flow as both the excess at the node and the capacity of the arc</span></div>
<divclass="line"><aname="l00075"></a><spanclass="lineno"> 75</span> <spanclass="comment">// - if there are no admissible arcs, the active node considered is relabeled,</span></div>
<divclass="line"><aname="l00076"></a><spanclass="lineno"> 76</span> <spanclass="comment">// i.e. its height is increased to 1 + the minimum height of its neighboring</span></div>
<divclass="line"><aname="l00077"></a><spanclass="lineno"> 77</span> <spanclass="comment">// nodes on admissible arcs.</span></div>
<divclass="line"><aname="l00078"></a><spanclass="lineno"> 78</span> <spanclass="comment">// This is implemented in Discharge, which itself calls PushFlow and Relabel.</span></div>
<divclass="line"><aname="l00080"></a><spanclass="lineno"> 80</span> <spanclass="comment">// Before running Discharge, it is necessary to initialize the algorithm with a</span></div>
<divclass="line"><aname="l00081"></a><spanclass="lineno"> 81</span> <spanclass="comment">// preflow. This is done in InitializePreflow, which saturates all the arcs</span></div>
<divclass="line"><aname="l00082"></a><spanclass="lineno"> 82</span> <spanclass="comment">// leaving the source node, and sets the excess at the heads of those arcs</span></div>
<divclass="line"><aname="l00085"></a><spanclass="lineno"> 85</span> <spanclass="comment">// The algorithm terminates when there are no remaining active nodes, i.e. all</span></div>
<divclass="line"><aname="l00086"></a><spanclass="lineno"> 86</span> <spanclass="comment">// the excesses at all nodes are equal to zero. In this case, a maximum flow is</span></div>
<divclass="line"><aname="l00089"></a><spanclass="lineno"> 89</span> <spanclass="comment">// The complexity of this algorithm depends amongst other things on the choice</span></div>
<divclass="line"><aname="l00090"></a><spanclass="lineno"> 90</span> <spanclass="comment">// of the next active node. It has been shown, for example in:</span></div>
<divclass="line"><aname="l00091"></a><spanclass="lineno"> 91</span> <spanclass="comment">// L. Tuncel, "On the Complexity of Preflow-Push Algorithms for Maximum-Flow</span></div>
<divclass="line"><aname="l00094"></a><spanclass="lineno"> 94</span> <spanclass="comment">// J. Cheriyan and K. Mehlhorn, "An analysis of the highest-level selection rule</span></div>
<divclass="line"><aname="l00095"></a><spanclass="lineno"> 95</span> <spanclass="comment">// in the preflow-push max-flow algorithm", Information processing letters,</span></div>
<divclass="line"><aname="l00099"></a><spanclass="lineno"> 99</span> <spanclass="comment">// ...that choosing the active node with the highest level yields a</span></div>
<divclass="line"><aname="l00100"></a><spanclass="lineno"> 100</span> <spanclass="comment">// complexity of O(n^2 * sqrt(m)).</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment">// TODO(user): implement the above active node choice rule.</span></div>
<divclass="line"><aname="l00104"></a><spanclass="lineno"> 104</span> <spanclass="comment">// This has been validated experimentally in:</span></div>
<divclass="line"><aname="l00105"></a><spanclass="lineno"> 105</span> <spanclass="comment">// R.K. Ahuja, M. Kodialam, A.K. Mishra, and J.B. Orlin, "Computational</span></div>
<divclass="line"><aname="l00106"></a><spanclass="lineno"> 106</span> <spanclass="comment">// Investigations of Maximum Flow Algorithms", EJOR 97:509-542(1997).</span></div>
<divclass="line"><aname="l00110"></a><spanclass="lineno"> 110</span> <spanclass="comment">// TODO(user): an alternative would be to evaluate:</span></div>
<divclass="line"><aname="l00111"></a><spanclass="lineno"> 111</span> <spanclass="comment">// A.V. Goldberg, "The Partial Augment-Relabel Algorithm for the Maximum Flow</span></div>
<divclass="line"><aname="l00112"></a><spanclass="lineno"> 112</span> <spanclass="comment">// Problem.” In Proceedings of Algorithms ESA, LNCS 5193:466-477, Springer 2008.</span></div>
<divclass="line"><aname="l00115"></a><spanclass="lineno"> 115</span> <spanclass="comment">// An interesting general reference on network flows is:</span></div>
<divclass="line"><aname="l00116"></a><spanclass="lineno"> 116</span> <spanclass="comment">// R. K. Ahuja, T. L. Magnanti, J. B. Orlin, "Network Flows: Theory, Algorithms,</span></div>
<divclass="line"><aname="l00117"></a><spanclass="lineno"> 117</span> <spanclass="comment">// and Applications," Prentice Hall, 1993, ISBN: 978-0136175490,</span></div>
<divclass="line"><aname="l00146"></a><spanclass="lineno"> 146</span> <spanclass="comment">// A simple and efficient max-cost flow interface. This is as fast as</span></div>
<divclass="line"><aname="l00147"></a><spanclass="lineno"> 147</span> <spanclass="comment">// GenericMaxFlow<ReverseArcStaticGraph>, which is the fastest, but uses</span></div>
<divclass="line"><aname="l00148"></a><spanclass="lineno"> 148</span> <spanclass="comment">// more memory in order to hide the somewhat involved construction of the</span></div>
<divclass="line"><aname="l00151"></a><spanclass="lineno"> 151</span> <spanclass="comment">// TODO(user): If the need arises, extend this interface to support warm start.</span></div>
<divclass="line"><aname="l00154"></a><spanclass="lineno"> 154</span> <spanclass="comment">// The constructor takes no size.</span></div>
<divclass="line"><aname="l00155"></a><spanclass="lineno"> 155</span> <spanclass="comment">// New node indices will be created lazily by AddArcWithCapacity().</span></div>
<divclass="line"><aname="l00158"></a><spanclass="lineno"> 158</span> <spanclass="comment">// Adds a directed arc with the given capacity from tail to head.</span></div>
<divclass="line"><aname="l00159"></a><spanclass="lineno"> 159</span> <spanclass="comment">// * Node indices and capacity must be non-negative (>= 0).</span></div>
<divclass="line"><aname="l00160"></a><spanclass="lineno"> 160</span> <spanclass="comment">// * Self-looping and duplicate arcs are supported.</span></div>
<divclass="line"><aname="l00161"></a><spanclass="lineno"> 161</span> <spanclass="comment">// * After the method finishes, NumArcs() == the returned ArcIndex + 1.</span></div>
<divclass="line"><aname="l00165"></a><spanclass="lineno"> 165</span> <spanclass="comment">// Returns the current number of nodes. This is one more than the largest</span></div>
<divclass="line"><aname="l00166"></a><spanclass="lineno"> 166</span> <spanclass="comment">// node index seen so far in AddArcWithCapacity().</span></div>
<divclass="line"><aname="l00169"></a><spanclass="lineno"> 169</span> <spanclass="comment">// Returns the current number of arcs in the graph.</span></div>
<divclass="line"><aname="l00173"></a><spanclass="lineno"> 173</span> <spanclass="comment">// The implementation will crash if "arc" is not in [0, NumArcs()).</span></div>
<divclass="line"><aname="l00178"></a><spanclass="lineno"> 178</span> <spanclass="comment">// Solves the problem (finds the maximum flow from the given source to the</span></div>
<divclass="line"><aname="l00179"></a><spanclass="lineno"> 179</span> <spanclass="comment">// given sink), and returns the problem status.</span></div>
<divclass="line"><aname="l00181"></a><spanclass="lineno"> 181</span> <spanclass="comment">// Solve() was called and found an optimal solution. Note that OptimalFlow()</span></div>
<divclass="line"><aname="l00182"></a><spanclass="lineno"> 182</span> <spanclass="comment">// may be 0 which means that the sink is not reachable from the source.</span></div>
<divclass="line"><aname="l00184"></a><spanclass="lineno"> 184</span> <spanclass="comment">// There is a flow > std::numeric_limits<FlowQuantity>::max(). Note that in</span></div>
<divclass="line"><aname="l00185"></a><spanclass="lineno"> 185</span> <spanclass="comment">// this case, the class will contain a solution with a flow reaching that</span></div>
<divclass="line"><aname="l00188"></a><spanclass="lineno"> 188</span> <spanclass="comment">// TODO(user): rename POSSIBLE_OVERFLOW to INT_OVERFLOW and modify our</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment">// The input is inconsistent (bad tail/head/capacity values).</span></div>
<divclass="line"><aname="l00193"></a><spanclass="lineno"> 193</span> <spanclass="comment">// This should not happen. There was an error in our code (i.e. file a bug).</span></div>
<divclass="line"><aname="l00198"></a><spanclass="lineno"> 198</span> <spanclass="comment">// Returns the maximum flow we can send from the source to the sink in the</span></div>
<divclass="line"><aname="l00199"></a><spanclass="lineno"> 199</span> <spanclass="comment">// last OPTIMAL Solve() context.</span></div>
<divclass="line"><aname="l00202"></a><spanclass="lineno"> 202</span> <spanclass="comment">// Returns the flow on the given arc in the last OPTIMAL Solve() context.</span></div>
<divclass="line"><aname="l00204"></a><spanclass="lineno"> 204</span> <spanclass="comment">// Note: It is possible that there is more than one optimal solution. The</span></div>
<divclass="line"><aname="l00205"></a><spanclass="lineno"> 205</span> <spanclass="comment">// algorithm is deterministic so it will always return the same solution for</span></div>
<divclass="line"><aname="l00206"></a><spanclass="lineno"> 206</span> <spanclass="comment">// a given problem. However, there is no guarantee of this from one code</span></div>
<divclass="line"><aname="l00207"></a><spanclass="lineno"> 207</span> <spanclass="comment">// version to the next (but the code does not change often).</span></div>
<divclass="line"><aname="l00210"></a><spanclass="lineno"> 210</span> <spanclass="comment">// Returns the nodes reachable from the source by non-saturated arcs (.i.e.</span></div>
<divclass="line"><aname="l00211"></a><spanclass="lineno"> 211</span> <spanclass="comment">// arc with Flow(arc) < Capacity(arc)), the outgoing arcs of this set form a</span></div>
<divclass="line"><aname="l00212"></a><spanclass="lineno"> 212</span> <spanclass="comment">// minimum cut. This works only if Solve() returned OPTIMAL.</span></div>
<divclass="line"><aname="l00215"></a><spanclass="lineno"> 215</span> <spanclass="comment">// Returns the nodes that can reach the sink by non-saturated arcs, the</span></div>
<divclass="line"><aname="l00216"></a><spanclass="lineno"> 216</span> <spanclass="comment">// outgoing arcs of this set form a minimum cut. Note that if this is the</span></div>
<divclass="line"><aname="l00217"></a><spanclass="lineno"> 217</span> <spanclass="comment">// complement set of GetNodeReachableFromSource(), then the min-cut is unique.</span></div>
<divclass="line"><aname="l00218"></a><spanclass="lineno"> 218</span> <spanclass="comment">// This works only if Solve() returned OPTIMAL.</span></div>
<divclass="line"><aname="l00221"></a><spanclass="lineno"> 221</span> <spanclass="comment">// Creates the protocol buffer representation of the problem used by the last</span></div>
<divclass="line"><aname="l00222"></a><spanclass="lineno"> 222</span> <spanclass="comment">// Solve() call. This is mainly useful for debugging.</span></div>
<divclass="line"><aname="l00225"></a><spanclass="lineno"> 225</span> <spanclass="comment">// Change the capacity of an arc.</span></div>
<divclass="line"><aname="l00226"></a><spanclass="lineno"> 226</span> <spanclass="comment">// WARNING: This looks like it enables incremental solves, but as of 2018-02,</span></div>
<divclass="line"><aname="l00227"></a><spanclass="lineno"> 227</span> <spanclass="comment">// the next Solve() will restart from scratch anyway.</span></div>
<divclass="line"><aname="l00228"></a><spanclass="lineno"> 228</span> <spanclass="comment">// TODO(user): Support incrementality in the max flow implementation.</span></div>
<divclass="line"><aname="l00240"></a><spanclass="lineno"> 240</span> <spanclass="comment">// Note that we cannot free the graph before we stop using the max-flow</span></div>
<divclass="line"><aname="l00241"></a><spanclass="lineno"> 241</span> <spanclass="comment">// instance that uses it.</span></div>
<divclass="line"><aname="l00249"></a><spanclass="lineno"> 249</span> <spanclass="comment">// Specific but efficient priority queue implementation. The priority type must</span></div>
<divclass="line"><aname="l00250"></a><spanclass="lineno"> 250</span> <spanclass="comment">// be an integer. The queue allows to retrieve the element with highest priority</span></div>
<divclass="line"><aname="l00251"></a><spanclass="lineno"> 251</span> <spanclass="comment">// but only allows pushes with a priority greater or equal to the highest</span></div>
<divclass="line"><aname="l00252"></a><spanclass="lineno"> 252</span> <spanclass="comment">// priority in the queue minus one. All operations are in O(1) and the memory is</span></div>
<divclass="line"><aname="l00253"></a><spanclass="lineno"> 253</span> <spanclass="comment">// in O(num elements in the queue). Elements with the same priority are</span></div>
<divclass="line"><aname="l00254"></a><spanclass="lineno"> 254</span> <spanclass="comment">// retrieved with LIFO order.</span></div>
<divclass="line"><aname="l00256"></a><spanclass="lineno"> 256</span> <spanclass="comment">// Note(user): As far as I know, this is an original idea and is the only code</span></div>
<divclass="line"><aname="l00257"></a><spanclass="lineno"> 257</span> <spanclass="comment">// that use this in the Maximum Flow context. Papers usually refer to an</span></div>
<divclass="line"><aname="l00258"></a><spanclass="lineno"> 258</span> <spanclass="comment">// height-indexed array of simple linked lists of active node with the same</span></div>
<divclass="line"><aname="l00259"></a><spanclass="lineno"> 259</span> <spanclass="comment">// height. Even worse, sometimes they use double-linked list to allow arbitrary</span></div>
<divclass="line"><aname="l00260"></a><spanclass="lineno"> 260</span> <spanclass="comment">// height update in order to detect missing height (used for the Gap heuristic).</span></div>
<divclass="line"><aname="l00261"></a><spanclass="lineno"> 261</span> <spanclass="comment">// But this can actually be implemented a lot more efficiently by just</span></div>
<divclass="line"><aname="l00262"></a><spanclass="lineno"> 262</span> <spanclass="comment">// maintaining the height distribution of all the node in the graph.</span></div>
<divclass="line"><aname="l00274"></a><spanclass="lineno"> 274</span> <spanclass="comment">// Push a new element in the queue. Its priority must be greater or equal to</span></div>
<divclass="line"><aname="l00275"></a><spanclass="lineno"> 275</span> <spanclass="comment">// the highest priority present in the queue, minus one. This condition is</span></div>
<divclass="line"><aname="l00276"></a><spanclass="lineno"> 276</span> <spanclass="comment">// DCHECKed, and violating it yields erroneous queue behavior in NDEBUG mode.</span></div>
<divclass="line"><aname="l00279"></a><spanclass="lineno"> 279</span> <spanclass="comment">// Returns the element with highest priority and remove it from the queue.</span></div>
<divclass="line"><aname="l00280"></a><spanclass="lineno"> 280</span> <spanclass="comment">// IsEmpty() must be false, this condition is DCHECKed.</span></div>
<divclass="line"><aname="l00281"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_priority_queue_with_restricted_push.html#af355586ee86be2298efe2e81367eeffe"> 281</a></span>  Element <aclass="code"href="classoperations__research_1_1_priority_queue_with_restricted_push.html#af355586ee86be2298efe2e81367eeffe">Pop</a>();</div>
<divclass="line"><aname="l00284"></a><spanclass="lineno"> 284</span> <spanclass="comment">// Helper function to get the last element of a vector and pop it.</span></div>
<divclass="line"><aname="l00285"></a><spanclass="lineno"> 285</span>  Element PopBack(std::vector<std::pair<Element, IntegerPriority>>* queue);</div>
<divclass="line"><aname="l00287"></a><spanclass="lineno"> 287</span> <spanclass="comment">// This is the heart of the algorithm. basically we split the elements by</span></div>
<divclass="line"><aname="l00288"></a><spanclass="lineno"> 288</span> <spanclass="comment">// parity of their priority and the precondition on the Push() ensures that</span></div>
<divclass="line"><aname="l00289"></a><spanclass="lineno"> 289</span> <spanclass="comment">// both vectors are always sorted by increasing priority.</span></div>
<divclass="line"><aname="l00296"></a><spanclass="lineno"> 296</span> <spanclass="comment">// We want an enum for the Status of a max flow run, and we want this</span></div>
<divclass="line"><aname="l00297"></a><spanclass="lineno"> 297</span> <spanclass="comment">// enum to be scoped under GenericMaxFlow<>. Unfortunately, swig</span></div>
<divclass="line"><aname="l00298"></a><spanclass="lineno"> 298</span> <spanclass="comment">// doesn't handle templated enums very well, so we need a base,</span></div>
<divclass="line"><aname="l00299"></a><spanclass="lineno"> 299</span> <spanclass="comment">// untemplated class to hold it.</span></div>
<divclass="line"><aname="l00303"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba0e6873a155f86a4695f463bf8601d05f"> 303</a></span> <aclass="code"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba0e6873a155f86a4695f463bf8601d05f">NOT_SOLVED</a>, <spanclass="comment">// The problem was not solved, or its data were edited.</span></div>
<divclass="line"><aname="l00304"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2579881e7c83261bc21bafb5a5c92cad"> 304</a></span> <aclass="code"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba2579881e7c83261bc21bafb5a5c92cad">OPTIMAL</a>, <spanclass="comment">// Solve() was called and found an optimal solution.</span></div>
<divclass="line"><aname="l00305"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70baef3d63bf3419a0e33cd86b58fadc640b"> 305</a></span> <aclass="code"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70baef3d63bf3419a0e33cd86b58fadc640b">INT_OVERFLOW</a>, <spanclass="comment">// There is a feasible flow > max possible flow.</span></div>
<divclass="line"><aname="l00306"></a><spanclass="lineno"><aclass="line"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70bac2811be86dd03c6735e3b0db51ad914f"> 306</a></span> <aclass="code"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70bac2811be86dd03c6735e3b0db51ad914f">BAD_INPUT</a>, <spanclass="comment">// The input is inconsistent.</span></div>
<divclass="line"><aname="l00307"></a><spanclass="lineno"> 307</span> <aclass="code"href="classoperations__research_1_1_max_flow_status_class.html#a67a0db04d321a74b7e7fcfd3f1a3f70bac76ecfd837bdc6d4150bb02c403356e4">BAD_RESULT</a><spanclass="comment">// There was an error.</span></div>
<divclass="line"><aname="l00311"></a><spanclass="lineno"> 311</span> <spanclass="comment">// Generic MaxFlow (there is a default MaxFlow specialization defined below)</span></div>
<divclass="line"><aname="l00312"></a><spanclass="lineno"> 312</span> <spanclass="comment">// that works with StarGraph and all the reverse arc graphs from graph.h, see</span></div>
<divclass="line"><aname="l00313"></a><spanclass="lineno"> 313</span> <spanclass="comment">// the end of max_flow.cc for the exact types this class is compiled for.</span></div>
<divclass="line"><aname="l00325"></a><spanclass="lineno"> 325</span> <spanclass="comment">// The height of a node never excess 2 times the number of node, so we</span></div>
<divclass="line"><aname="l00326"></a><spanclass="lineno"> 326</span> <spanclass="comment">// use the same type as a Node index.</span></div>
<divclass="line"><aname="l00330"></a><spanclass="lineno"> 330</span> <spanclass="comment">// Initialize a MaxFlow instance on the given graph. The graph does not need</span></div>
<divclass="line"><aname="l00331"></a><spanclass="lineno"> 331</span> <spanclass="comment">// to be fully built yet, but its capacity reservation are used to initialize</span></div>
<divclass="line"><aname="l00332"></a><spanclass="lineno"> 332</span> <spanclass="comment">// the memory of this class. source and sink must also be valid node of</span></div>
<divclass="line"><aname="l00337"></a><spanclass="lineno"> 337</span> <spanclass="comment">// Returns the graph associated to the current object.</span></div>
<divclass="line"><aname="l00340"></a><spanclass="lineno"> 340</span> <spanclass="comment">// Returns the status of last call to Solve(). NOT_SOLVED is returned if</span></div>
<divclass="line"><aname="l00341"></a><spanclass="lineno"> 341</span> <spanclass="comment">// Solve() has never been called or if the problem has been modified in such a</span></div>
<divclass="line"><aname="l00342"></a><spanclass="lineno"> 342</span> <spanclass="comment">// way that the previous solution becomes invalid.</span></div>
<divclass="line"><aname="l00345"></a><spanclass="lineno"> 345</span> <spanclass="comment">// Returns the index of the node corresponding to the source of the network.</span></div>
<divclass="line"><aname="l00348"></a><spanclass="lineno"> 348</span> <spanclass="comment">// Returns the index of the node corresponding to the sink of the network.</span></div>
<divclass="line"><aname="l00351"></a><spanclass="lineno"> 351</span> <spanclass="comment">// Sets the capacity for arc to new_capacity.</span></div>
<divclass="line"><aname="l00357"></a><spanclass="lineno"> 357</span> <spanclass="comment">// Returns true if a maximum flow was solved.</span></div>
<divclass="line"><aname="l00360"></a><spanclass="lineno"> 360</span> <spanclass="comment">// Returns the total flow found by the algorithm.</span></div>
<divclass="line"><aname="l00363"></a><spanclass="lineno"> 363</span> <spanclass="comment">// Returns the flow on arc using the equations given in the comment on</span></div>
<divclass="line"><aname="l00373"></a><spanclass="lineno"> 373</span> <spanclass="comment">// Returns the capacity of arc using the equations given in the comment on</span></div>
<divclass="line"><aname="l00384"></a><spanclass="lineno"> 384</span> <spanclass="comment">// Returns the nodes reachable from the source in the residual graph, the</span></div>
<divclass="line"><aname="l00385"></a><spanclass="lineno"> 385</span> <spanclass="comment">// outgoing arcs of this set form a minimum cut.</span></div>
<divclass="line"><aname="l00388"></a><spanclass="lineno"> 388</span> <spanclass="comment">// Returns the nodes that can reach the sink in the residual graph, the</span></div>
<divclass="line"><aname="l00389"></a><spanclass="lineno"> 389</span> <spanclass="comment">// outgoing arcs of this set form a minimum cut. Note that if this is the</span></div>
<divclass="line"><aname="l00390"></a><spanclass="lineno"> 390</span> <spanclass="comment">// complement of GetNodeReachableFromSource(), then the min-cut is unique.</span></div>
<divclass="line"><aname="l00392"></a><spanclass="lineno"> 392</span> <spanclass="comment">// TODO(user): In the two-phases algorithm, we can get this minimum cut</span></div>
<divclass="line"><aname="l00393"></a><spanclass="lineno"> 393</span> <spanclass="comment">// without doing the second phase. Add an option for this if there is a need</span></div>
<divclass="line"><aname="l00394"></a><spanclass="lineno"> 394</span> <spanclass="comment">// to, note that the second phase is pretty fast so the gain will be small.</span></div>
<divclass="line"><aname="l00397"></a><spanclass="lineno"> 397</span> <spanclass="comment">// Checks the consistency of the input, i.e. that capacities on the arcs are</span></div>
<divclass="line"><aname="l00398"></a><spanclass="lineno"> 398</span> <spanclass="comment">// non-negative or null.</span></div>
<divclass="line"><aname="l00401"></a><spanclass="lineno"> 401</span> <spanclass="comment">// Checks whether the result is valid, i.e. that node excesses are all equal</span></div>
<divclass="line"><aname="l00402"></a><spanclass="lineno"> 402</span> <spanclass="comment">// to zero (we have a flow) and that residual capacities are all non-negative</span></div>
<divclass="line"><aname="l00403"></a><spanclass="lineno"> 403</span> <spanclass="comment">// or zero.</span></div>
<divclass="line"><aname="l00406"></a><spanclass="lineno"> 406</span> <spanclass="comment">// Returns true if there exists a path from the source to the sink with</span></div>
<divclass="line"><aname="l00407"></a><spanclass="lineno"> 407</span> <spanclass="comment">// remaining capacity. This allows us to easily check at the end that the flow</span></div>
<divclass="line"><aname="l00408"></a><spanclass="lineno"> 408</span> <spanclass="comment">// we computed is indeed optimal (provided that all the conditions tested by</span></div>
<divclass="line"><aname="l00409"></a><spanclass="lineno"> 409</span> <spanclass="comment">// CheckResult() also hold).</span></div>
<divclass="line"><aname="l00412"></a><spanclass="lineno"> 412</span> <spanclass="comment">// Sets the different algorithm options. All default to true.</span></div>
<divclass="line"><aname="l00413"></a><spanclass="lineno"> 413</span> <spanclass="comment">// See the corresponding variable declaration below for more details.</span></div>
<divclass="line"><aname="l00422"></a><spanclass="lineno"> 422</span> <aclass="code"href="classoperations__research_1_1_generic_max_flow.html#a33996084cb5b29f77cc6ee673b6ece51">process_node_by_height_</a> = value &&<aclass="code"href="classoperations__research_1_1_generic_max_flow.html#a3b2203f6789a10763c6ae978bf26b402">use_global_update_</a>;</div>
<divclass="line"><aname="l00425"></a><spanclass="lineno"> 425</span> <spanclass="comment">// Returns the protocol buffer representation of the current problem.</span></div>
<divclass="line"><aname="l00435"></a><spanclass="lineno"> 435</span> <spanclass="comment">// Returns true if node is active, i.e. if its excess is positive and it</span></div>
<divclass="line"><aname="l00436"></a><spanclass="lineno"> 436</span> <spanclass="comment">// is neither the source or the sink of the graph.</span></div>
<divclass="line"><aname="l00441"></a><spanclass="lineno"> 441</span> <spanclass="comment">// Sets the capacity of arc to 'capacity' and clears the flow on arc.</span></div>
<divclass="line"><aname="l00447"></a><spanclass="lineno"> 447</span> <spanclass="comment">// Returns true if a precondition for Relabel is met, i.e. the outgoing arcs</span></div>
<divclass="line"><aname="l00448"></a><spanclass="lineno"> 448</span> <spanclass="comment">// of node are all either saturated or the heights of their heads are greater</span></div>
<divclass="line"><aname="l00449"></a><spanclass="lineno"> 449</span> <spanclass="comment">// or equal to the height of node.</span></div>
<divclass="line"><aname="l00452"></a><spanclass="lineno"> 452</span> <spanclass="comment">// Returns context concatenated with information about arc</span></div>
<divclass="line"><aname="l00453"></a><spanclass="lineno"> 453</span> <spanclass="comment">// in a human-friendly way.</span></div>
<divclass="line"><aname="l00459"></a><spanclass="lineno"> 459</span> <spanclass="comment">// Get the first element from the active node container.</span></div>
<divclass="line"><aname="l00467"></a><spanclass="lineno"> 467</span> <spanclass="comment">// Push element to the active node container.</span></div>
<divclass="line"><aname="l00489"></a><spanclass="lineno"> 489</span> <spanclass="comment">// Discharges an active node node by saturating its admissible adjacent arcs,</span></div>
<divclass="line"><aname="l00490"></a><spanclass="lineno"> 490</span> <spanclass="comment">// if any, and by relabelling it when it becomes inactive.</span></div>
<divclass="line"><aname="l00493"></a><spanclass="lineno"> 493</span> <spanclass="comment">// Initializes the preflow to a state that enables to run Refine.</span></div>
<divclass="line"><aname="l00496"></a><spanclass="lineno"> 496</span> <spanclass="comment">// Clears the flow excess at each node by pushing the flow back to the source:</span></div>
<divclass="line"><aname="l00497"></a><spanclass="lineno"> 497</span> <spanclass="comment">// - Do a depth-first search from the source in the direct graph to cancel</span></div>
<divclass="line"><aname="l00499"></a><spanclass="lineno"> 499</span> <spanclass="comment">// - Then, return flow excess along the depth-first search tree (by pushing</span></div>
<divclass="line"><aname="l00500"></a><spanclass="lineno"> 500</span> <spanclass="comment">// the flow in the reverse dfs topological order).</span></div>
<divclass="line"><aname="l00501"></a><spanclass="lineno"> 501</span> <spanclass="comment">// The theoretical complexity is O(mn), but it is a lot faster in practice.</span></div>
<divclass="line"><aname="l00504"></a><spanclass="lineno"> 504</span> <spanclass="comment">// Computes the best possible node potential given the current flow using a</span></div>
<divclass="line"><aname="l00505"></a><spanclass="lineno"> 505</span> <spanclass="comment">// reverse breadth-first search from the sink in the reverse residual graph.</span></div>
<divclass="line"><aname="l00506"></a><spanclass="lineno"> 506</span> <spanclass="comment">// This is an implementation of the global update heuristic mentioned in many</span></div>
<divclass="line"><aname="l00507"></a><spanclass="lineno"> 507</span> <spanclass="comment">// max-flow papers. See for instance: B.V. Cherkassky, A.V. Goldberg, "On</span></div>
<divclass="line"><aname="l00508"></a><spanclass="lineno"> 508</span> <spanclass="comment">// implementing push-relabel methods for the maximum flow problem",</span></div>
<divclass="line"><aname="l00513"></a><spanclass="lineno"> 513</span> <spanclass="comment">// Tries to saturate all the outgoing arcs from the source that can reach the</span></div>
<divclass="line"><aname="l00514"></a><spanclass="lineno"> 514</span> <spanclass="comment">// sink. Most of the time, we can do that in one go, except when more flow</span></div>
<divclass="line"><aname="l00515"></a><spanclass="lineno"> 515</span> <spanclass="comment">// than kMaxFlowQuantity can be pushed out of the source in which case we</span></div>
<divclass="line"><aname="l00516"></a><spanclass="lineno"> 516</span> <spanclass="comment">// have to be careful. Returns true if some flow was pushed.</span></div>
<divclass="line"><aname="l00519"></a><spanclass="lineno"> 519</span> <spanclass="comment">// Pushes flow on arc, i.e. consumes flow on residual_arc_capacity_[arc],</span></div>
<divclass="line"><aname="l00520"></a><spanclass="lineno"> 520</span> <spanclass="comment">// and consumes -flow on residual_arc_capacity_[Opposite(arc)]. Updates</span></div>
<divclass="line"><aname="l00521"></a><spanclass="lineno"> 521</span> <spanclass="comment">// node_excess_ at the tail and head of arc accordingly.</span></div>
<divclass="line"><aname="l00524"></a><spanclass="lineno"> 524</span> <spanclass="comment">// Relabels a node, i.e. increases its height by the minimum necessary amount.</span></div>
<divclass="line"><aname="l00525"></a><spanclass="lineno"> 525</span> <spanclass="comment">// This version of Relabel is relaxed in a way such that if an admissible arc</span></div>
<divclass="line"><aname="l00526"></a><spanclass="lineno"> 526</span> <spanclass="comment">// exists at the current node height, then the node is not relabeled. This</span></div>
<divclass="line"><aname="l00527"></a><spanclass="lineno"> 527</span> <spanclass="comment">// enables us to deal with wrong values of first_admissible_arc_[node] when</span></div>
<divclass="line"><aname="l00528"></a><spanclass="lineno"> 528</span> <spanclass="comment">// updating it is too costly.</span></div>
<divclass="line"><aname="l00531"></a><spanclass="lineno"> 531</span> <spanclass="comment">// Handy member functions to make the code more compact.</span></div>
<divclass="line"><aname="l00538"></a><spanclass="lineno"> 538</span> <spanclass="comment">// Returns the set of nodes reachable from start in the residual graph or in</span></div>
<divclass="line"><aname="l00539"></a><spanclass="lineno"> 539</span> <spanclass="comment">// the reverse residual graph (if reverse is true).</span></div>
<divclass="line"><aname="l00546"></a><spanclass="lineno"> 546</span> <spanclass="comment">// A pointer to the graph passed as argument.</span></div>
<divclass="line"><aname="l00549"></a><spanclass="lineno"> 549</span> <spanclass="comment">// An array representing the excess for each node in graph_.</span></div>
<divclass="line"><aname="l00552"></a><spanclass="lineno"> 552</span> <spanclass="comment">// An array representing the height function for each node in graph_. For a</span></div>
<divclass="line"><aname="l00553"></a><spanclass="lineno"> 553</span> <spanclass="comment">// given node, this is a lower bound on the shortest path length from this</span></div>
<divclass="line"><aname="l00554"></a><spanclass="lineno"> 554</span> <spanclass="comment">// node to the sink in the residual network. The height of a node always goes</span></div>
<divclass="line"><aname="l00555"></a><spanclass="lineno"> 555</span> <spanclass="comment">// up during the course of a Solve().</span></div>
<divclass="line"><aname="l00557"></a><spanclass="lineno"> 557</span> <spanclass="comment">// Since initially we saturate all the outgoing arcs of the source, we can</span></div>
<divclass="line"><aname="l00558"></a><spanclass="lineno"> 558</span> <spanclass="comment">// never reach the sink from the source in the residual graph. Initially we</span></div>
<divclass="line"><aname="l00559"></a><spanclass="lineno"> 559</span> <spanclass="comment">// set the height of the source to n (the number of node of the graph) and it</span></div>
<divclass="line"><aname="l00560"></a><spanclass="lineno"> 560</span> <spanclass="comment">// never changes. If a node as an height >= n, then this node can't reach the</span></div>
<divclass="line"><aname="l00561"></a><spanclass="lineno"> 561</span> <spanclass="comment">// sink and its height minus n is a lower bound on the shortest path length</span></div>
<divclass="line"><aname="l00562"></a><spanclass="lineno"> 562</span> <spanclass="comment">// from this node to the source in the residual graph.</span></div>
<divclass="line"><aname="l00565"></a><spanclass="lineno"> 565</span> <spanclass="comment">// An array representing the residual_capacity for each arc in graph_.</span></div>
<divclass="line"><aname="l00566"></a><spanclass="lineno"> 566</span> <spanclass="comment">// Residual capacities enable one to represent the capacity and flow for all</span></div>
<divclass="line"><aname="l00567"></a><spanclass="lineno"> 567</span> <spanclass="comment">// arcs in the graph in the following manner.</span></div>
<divclass="line"><aname="l00568"></a><spanclass="lineno"> 568</span> <spanclass="comment">// For all arc, residual_arc_capacity_[arc] = capacity[arc] - flow[arc]</span></div>
<divclass="line"><aname="l00569"></a><spanclass="lineno"> 569</span> <spanclass="comment">// Moreover, for reverse arcs, capacity[arc] = 0 by definition,</span></div>
<divclass="line"><aname="l00570"></a><spanclass="lineno"> 570</span> <spanclass="comment">// Also flow[Opposite(arc)] = -flow[arc] by definition.</span></div>
<divclass="line"><aname="l00578"></a><spanclass="lineno"> 578</span> <spanclass="comment">// Using these facts enables one to only maintain residual_arc_capacity_,</span></div>
<divclass="line"><aname="l00579"></a><spanclass="lineno"> 579</span> <spanclass="comment">// instead of both capacity and flow, for each direct and indirect arc. This</span></div>
<divclass="line"><aname="l00580"></a><spanclass="lineno"> 580</span> <spanclass="comment">// reduces the amount of memory for this information by a factor 2.</span></div>
<divclass="line"><aname="l00583"></a><spanclass="lineno"> 583</span> <spanclass="comment">// An array representing the first admissible arc for each node in graph_.</span></div>
<divclass="line"><aname="l00586"></a><spanclass="lineno"> 586</span> <spanclass="comment">// A stack used for managing active nodes in the algorithm.</span></div>
<divclass="line"><aname="l00587"></a><spanclass="lineno"> 587</span> <spanclass="comment">// Note that the papers cited above recommend the use of a queue, but</span></div>
<divclass="line"><aname="l00588"></a><spanclass="lineno"> 588</span> <spanclass="comment">// benchmarking so far has not proved it is better. In particular, processing</span></div>
<divclass="line"><aname="l00589"></a><spanclass="lineno"> 589</span> <spanclass="comment">// nodes in LIFO order has better cache locality.</span></div>
<divclass="line"><aname="l00592"></a><spanclass="lineno"> 592</span> <spanclass="comment">// A priority queue used for managing active nodes in the algorithm. It allows</span></div>
<divclass="line"><aname="l00593"></a><spanclass="lineno"> 593</span> <spanclass="comment">// to select the active node with highest height before each Discharge().</span></div>
<divclass="line"><aname="l00594"></a><spanclass="lineno"> 594</span> <spanclass="comment">// Moreover, since all pushes from this node will be to nodes with height</span></div>
<divclass="line"><aname="l00595"></a><spanclass="lineno"> 595</span> <spanclass="comment">// greater or equal to the initial discharged node height minus one, the</span></div>
<divclass="line"><aname="l00596"></a><spanclass="lineno"> 596</span> <spanclass="comment">// PriorityQueueWithRestrictedPush is a perfect fit.</span></div>
<divclass="line"><aname="l00608"></a><spanclass="lineno"> 608</span> <spanclass="comment">// BFS queue used by the GlobalUpdate() function. We do not use a C++ queue</span></div>
<divclass="line"><aname="l00609"></a><spanclass="lineno"> 609</span> <spanclass="comment">// because we need access to the vector for different optimizations.</span></div>
<divclass="line"><aname="l00616"></a><spanclass="lineno"> 616</span> <spanclass="comment">// Whether or not we use a two-phase algorithm:</span></div>
<divclass="line"><aname="l00617"></a><spanclass="lineno"> 617</span> <spanclass="comment">// 1/ Only deal with nodes that can reach the sink. At the end we know the</span></div>
<divclass="line"><aname="l00618"></a><spanclass="lineno"> 618</span> <spanclass="comment">// value of the maximum flow and we have a min-cut.</span></div>
<divclass="line"><aname="l00619"></a><spanclass="lineno"> 619</span> <spanclass="comment">// 2/ Call PushFlowExcessBackToSource() to obtain a max-flow. This is usually</span></div>
<divclass="line"><aname="l00620"></a><spanclass="lineno"> 620</span> <spanclass="comment">// a lot faster than the first phase.</span></div>
<divclass="line"><aname="l00623"></a><spanclass="lineno"> 623</span> <spanclass="comment">// Whether or not we use the PriorityQueueWithRestrictedPush to process the</span></div>
<divclass="line"><aname="l00624"></a><spanclass="lineno"> 624</span> <spanclass="comment">// active nodes rather than a simple queue. This can only be true if</span></div>
<divclass="line"><aname="l00625"></a><spanclass="lineno"> 625</span> <spanclass="comment">// use_global_update_ is true.</span></div>
<divclass="line"><aname="l00627"></a><spanclass="lineno"> 627</span> <spanclass="comment">// Note(user): using a template will be slightly faster, but since we test</span></div>
<divclass="line"><aname="l00628"></a><spanclass="lineno"> 628</span> <spanclass="comment">// this in a non-critical path, this only has a minor impact.</span></div>
<divclass="line"><aname="l00631"></a><spanclass="lineno"> 631</span> <spanclass="comment">// Whether or not we check the input, this is a small price to pay for</span></div>
<divclass="line"><aname="l00632"></a><spanclass="lineno"> 632</span> <spanclass="comment">// robustness. Disable only if you know the input is valid because an invalid</span></div>
<divclass="line"><aname="l00633"></a><spanclass="lineno"> 633</span> <spanclass="comment">// input can cause the algorithm to run into an infinite loop!</span></div>
<divclass="line"><aname="l00636"></a><spanclass="lineno"> 636</span> <spanclass="comment">// Whether or not we check the result.</span></div>
<divclass="line"><aname="l00637"></a><spanclass="lineno"> 637</span> <spanclass="comment">// TODO(user): Make the check more exhaustive by checking the optimality?</span></div>
<divclass="line"><aname="l00649"></a><spanclass="lineno"> 649</span> <spanclass="comment">// Default instance MaxFlow that uses StarGraph. Note that we cannot just use a</span></div>
<divclass="line"><aname="l00650"></a><spanclass="lineno"> 650</span> <spanclass="comment">// typedef because of dependent code expecting MaxFlow to be a real class.</span></div>
<divclass="line"><aname="l00651"></a><spanclass="lineno"> 651</span> <spanclass="comment">// TODO(user): Modify this code and remove it.</span></div>
<divclass="line"><aname="l00674"></a><spanclass="lineno"> 674</span>  Element element, IntegerPriority priority) {</div>
<divclass="line"><aname="l00675"></a><spanclass="lineno"> 675</span> <spanclass="comment">// Since users may rely on it, we DCHECK the exact condition.</span></div>
<divclass="line"><aname="l00679"></a><spanclass="lineno"> 679</span> <spanclass="comment">// Note that the DCHECK() below are less restrictive than the ones above but</span></div>
<divclass="line"><aname="l00680"></a><spanclass="lineno"> 680</span> <spanclass="comment">// check a necessary and sufficient condition for the priority queue to behave</span></div>
<divclass="line"><aname="l00681"></a><spanclass="lineno"> 681</span> <spanclass="comment">// as expected.</span></div>
<divclass="line"><aname="l00682"></a><spanclass="lineno"> 682</span> <spanclass="keywordflow">if</span> (priority & 1) {</div>