<ahref="min__cost__flow_8h.html">Go to the documentation of this file.</a><divclass="fragment"><divclass="line"><aid="l00001"name="l00001"></a><spanclass="lineno"> 1</span><spanclass="comment">// Copyright 2010-2021 Google LLC</span></div>
<divclass="line"><aid="l00002"name="l00002"></a><spanclass="lineno"> 2</span><spanclass="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div>
<divclass="line"><aid="l00003"name="l00003"></a><spanclass="lineno"> 3</span><spanclass="comment">// you may not use this file except in compliance with the License.</span></div>
<divclass="line"><aid="l00004"name="l00004"></a><spanclass="lineno"> 4</span><spanclass="comment">// You may obtain a copy of the License at</span></div>
<divclass="line"><aid="l00008"name="l00008"></a><spanclass="lineno"> 8</span><spanclass="comment">// Unless required by applicable law or agreed to in writing, software</span></div>
<divclass="line"><aid="l00009"name="l00009"></a><spanclass="lineno"> 9</span><spanclass="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div>
<divclass="line"><aid="l00010"name="l00010"></a><spanclass="lineno"> 10</span><spanclass="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<divclass="line"><aid="l00011"name="l00011"></a><spanclass="lineno"> 11</span><spanclass="comment">// See the License for the specific language governing permissions and</span></div>
<divclass="line"><aid="l00012"name="l00012"></a><spanclass="lineno"> 12</span><spanclass="comment">// limitations under the License.</span></div>
<divclass="line"><aid="l00014"name="l00014"></a><spanclass="lineno"> 14</span><spanclass="comment">// An implementation of a cost-scaling push-relabel algorithm for</span></div>
<divclass="line"><aid="l00015"name="l00015"></a><spanclass="lineno"> 15</span><spanclass="comment">// the min-cost flow problem.</span></div>
<divclass="line"><aid="l00017"name="l00017"></a><spanclass="lineno"> 17</span><spanclass="comment">// In the following, we consider a graph G = (V,E) where V denotes the set</span></div>
<divclass="line"><aid="l00018"name="l00018"></a><spanclass="lineno"> 18</span><spanclass="comment">// of nodes (vertices) in the graph, E denotes the set of arcs (edges).</span></div>
<divclass="line"><aid="l00019"name="l00019"></a><spanclass="lineno"> 19</span><spanclass="comment">// n = |V| denotes the number of nodes in the graph, and m = |E| denotes the</span></div>
<divclass="line"><aid="l00020"name="l00020"></a><spanclass="lineno"> 20</span><spanclass="comment">// number of arcs in the graph.</span></div>
<divclass="line"><aid="l00022"name="l00022"></a><spanclass="lineno"> 22</span><spanclass="comment">// With each arc (v,w) is associated a nonnegative capacity u(v,w)</span></div>
<divclass="line"><aid="l00023"name="l00023"></a><spanclass="lineno"> 23</span><spanclass="comment">// (where 'u' stands for "upper bound") and a unit cost c(v,w). With</span></div>
<divclass="line"><aid="l00024"name="l00024"></a><spanclass="lineno"> 24</span><spanclass="comment">// each node v is associated a quantity named supply(v), which</span></div>
<divclass="line"><aid="l00025"name="l00025"></a><spanclass="lineno"> 25</span><spanclass="comment">// represents a supply of fluid (if >0) or a demand (if <0).</span></div>
<divclass="line"><aid="l00026"name="l00026"></a><spanclass="lineno"> 26</span><spanclass="comment">// Furthermore, no fluid is created in the graph so</span></div>
<divclass="line"><aid="l00027"name="l00027"></a><spanclass="lineno"> 27</span><spanclass="comment">// sum_{v in V} supply(v) = 0.</span></div>
<divclass="line"><aid="l00029"name="l00029"></a><spanclass="lineno"> 29</span><spanclass="comment">// A flow is a function from E to R such that:</span></div>
<divclass="line"><aid="l00030"name="l00030"></a><spanclass="lineno"> 30</span><spanclass="comment">// a) f(v,w) <= u(v,w) for all (v,w) in E (capacity constraint).</span></div>
<divclass="line"><aid="l00031"name="l00031"></a><spanclass="lineno"> 31</span><spanclass="comment">// b) f(v,w) = -f(w,v) for all (v,w) in E (flow antisymmetry constraint).</span></div>
<divclass="line"><aid="l00032"name="l00032"></a><spanclass="lineno"> 32</span><spanclass="comment">// c) sum on v f(v,w) + supply(w) = 0 (flow conservation).</span></div>
<divclass="line"><aid="l00034"name="l00034"></a><spanclass="lineno"> 34</span><spanclass="comment">// The cost of a flow is sum on (v,w) in E ( f(v,w) * c(v,w) ) [Note:</span></div>
<divclass="line"><aid="l00035"name="l00035"></a><spanclass="lineno"> 35</span><spanclass="comment">// It can be confusing to beginners that the cost is actually double</span></div>
<divclass="line"><aid="l00036"name="l00036"></a><spanclass="lineno"> 36</span><spanclass="comment">// the amount that it might seem at first because of flow</span></div>
<divclass="line"><aid="l00039"name="l00039"></a><spanclass="lineno"> 39</span><spanclass="comment">// The problem to solve: find a flow of minimum cost such that all the</span></div>
<divclass="line"><aid="l00040"name="l00040"></a><spanclass="lineno"> 40</span><spanclass="comment">// fluid flows from the supply nodes to the demand nodes.</span></div>
<divclass="line"><aid="l00042"name="l00042"></a><spanclass="lineno"> 42</span><spanclass="comment">// The principles behind this algorithm are the following:</span></div>
<divclass="line"><aid="l00043"name="l00043"></a><spanclass="lineno"> 43</span><spanclass="comment">// 1/ handle pseudo-flows instead of flows and refine pseudo-flows until an</span></div>
<divclass="line"><aid="l00044"name="l00044"></a><spanclass="lineno"> 44</span><spanclass="comment">// epsilon-optimal minimum-cost flow is obtained,</span></div>
<divclass="line"><aid="l00045"name="l00045"></a><spanclass="lineno"> 45</span><spanclass="comment">// 2/ deal with epsilon-optimal pseudo-flows.</span></div>
<divclass="line"><aid="l00047"name="l00047"></a><spanclass="lineno"> 47</span><spanclass="comment">// 1/ A pseudo-flow is like a flow, except that a node's outflow minus</span></div>
<divclass="line"><aid="l00048"name="l00048"></a><spanclass="lineno"> 48</span><spanclass="comment">// its inflow can be different from its supply. If it is the case at a</span></div>
<divclass="line"><aid="l00049"name="l00049"></a><spanclass="lineno"> 49</span><spanclass="comment">// given node v, it is said that there is an excess (or deficit) at</span></div>
<divclass="line"><aid="l00050"name="l00050"></a><spanclass="lineno"> 50</span><spanclass="comment">// node v. A deficit is denoted by a negative excess and inflow =</span></div>
<divclass="line"><aid="l00052"name="l00052"></a><spanclass="lineno"> 52</span><spanclass="comment">// (Look at ortools/graph/max_flow.h to see that the definition</span></div>
<divclass="line"><aid="l00053"name="l00053"></a><spanclass="lineno"> 53</span><spanclass="comment">// of preflow is more restrictive than the one for pseudo-flow in that a preflow</span></div>
<divclass="line"><aid="l00054"name="l00054"></a><spanclass="lineno"> 54</span><spanclass="comment">// only allows non-negative excesses, i.e., no deficit.)</span></div>
<divclass="line"><aid="l00055"name="l00055"></a><spanclass="lineno"> 55</span><spanclass="comment">// More formally, a pseudo-flow is a function f such that:</span></div>
<divclass="line"><aid="l00056"name="l00056"></a><spanclass="lineno"> 56</span><spanclass="comment">// a) f(v,w) <= u(v,w) for all (v,w) in E (capacity constraint).</span></div>
<divclass="line"><aid="l00057"name="l00057"></a><spanclass="lineno"> 57</span><spanclass="comment">// b) f(v,w) = -f(w,v) for all (v,w) in E (flow antisymmetry constraint).</span></div>
<divclass="line"><aid="l00059"name="l00059"></a><spanclass="lineno"> 59</span><spanclass="comment">// For each v in E, we also define the excess at node v, the algebraic sum of</span></div>
<divclass="line"><aid="l00060"name="l00060"></a><spanclass="lineno"> 60</span><spanclass="comment">// all the incoming preflows at this node, added together with the supply at v.</span></div>
<divclass="line"><aid="l00061"name="l00061"></a><spanclass="lineno"> 61</span><spanclass="comment">// excess(v) = sum on u f(u,v) + supply(v)</span></div>
<divclass="line"><aid="l00063"name="l00063"></a><spanclass="lineno"> 63</span><spanclass="comment">// The goal of the algorithm is to obtain excess(v) = 0 for all v in V, while</span></div>
<divclass="line"><aid="l00064"name="l00064"></a><spanclass="lineno"> 64</span><spanclass="comment">// consuming capacity on some arcs, at the lowest possible cost.</span></div>
<divclass="line"><aid="l00066"name="l00066"></a><spanclass="lineno"> 66</span><spanclass="comment">// 2/ Internally to the algorithm and its analysis (but invisibly to</span></div>
<divclass="line"><aid="l00067"name="l00067"></a><spanclass="lineno"> 67</span><spanclass="comment">// the client), each node has an associated "price" (or potential), in</span></div>
<divclass="line"><aid="l00068"name="l00068"></a><spanclass="lineno"> 68</span><spanclass="comment">// addition to its excess. It is formally a function from E to R (the</span></div>
<divclass="line"><aid="l00069"name="l00069"></a><spanclass="lineno"> 69</span><spanclass="comment">// set of real numbers.). For a given price function p, the reduced</span></div>
<divclass="line"><aid="l00070"name="l00070"></a><spanclass="lineno"> 70</span><spanclass="comment">// cost of an arc (v,w) is:</span></div>
<divclass="line"><aid="l00072"name="l00072"></a><spanclass="lineno"> 72</span><spanclass="comment">// (c(v,w) is the cost of arc (v,w).) For those familiar with linear</span></div>
<divclass="line"><aid="l00073"name="l00073"></a><spanclass="lineno"> 73</span><spanclass="comment">// programming, the price function can be viewed as a set of dual</span></div>
<divclass="line"><aid="l00076"name="l00076"></a><spanclass="lineno"> 76</span><spanclass="comment">// For a constant epsilon >= 0, a pseudo-flow f is said to be epsilon-optimal</span></div>
<divclass="line"><aid="l00077"name="l00077"></a><spanclass="lineno"> 77</span><spanclass="comment">// with respect to a price function p if for every residual arc (v,w) in E,</span></div>
<divclass="line"><aid="l00080"name="l00080"></a><spanclass="lineno"> 80</span><spanclass="comment">// A flow f is optimal if and only if there exists a price function p such that</span></div>
<divclass="line"><aid="l00081"name="l00081"></a><spanclass="lineno"> 81</span><spanclass="comment">// no arc is admissible with respect to f and p.</span></div>
<divclass="line"><aid="l00083"name="l00083"></a><spanclass="lineno"> 83</span><spanclass="comment">// If the arc costs are integers, and epsilon < 1/n, any epsilon-optimal flow</span></div>
<divclass="line"><aid="l00084"name="l00084"></a><spanclass="lineno"> 84</span><spanclass="comment">// is optimal. The integer cost case is handled by multiplying all the arc costs</span></div>
<divclass="line"><aid="l00085"name="l00085"></a><spanclass="lineno"> 85</span><spanclass="comment">// and the initial value of epsilon by (n+1). When epsilon reaches 1, and</span></div>
<divclass="line"><aid="l00086"name="l00086"></a><spanclass="lineno"> 86</span><spanclass="comment">// the solution is epsilon-optimal, it means: for all residual arc (v,w) in E,</span></div>
<divclass="line"><aid="l00090"name="l00090"></a><spanclass="lineno"> 90</span><spanclass="comment">// A node v is said to be *active* if excess(v) > 0.</span></div>
<divclass="line"><aid="l00091"name="l00091"></a><spanclass="lineno"> 91</span><spanclass="comment">// In this case the following operations can be applied to it:</span></div>
<divclass="line"><aid="l00092"name="l00092"></a><spanclass="lineno"> 92</span><spanclass="comment">// - if there are *admissible* incident arcs, i.e. arcs which are not saturated,</span></div>
<divclass="line"><aid="l00093"name="l00093"></a><spanclass="lineno"> 93</span><spanclass="comment">// and whose reduced costs are negative, a PushFlow operation can</span></div>
<divclass="line"><aid="l00094"name="l00094"></a><spanclass="lineno"> 94</span><spanclass="comment">// be applied. It consists in sending as much flow as both the excess at the</span></div>
<divclass="line"><aid="l00095"name="l00095"></a><spanclass="lineno"> 95</span><spanclass="comment">// node and the capacity of the arc permit.</span></div>
<divclass="line"><aid="l00096"name="l00096"></a><spanclass="lineno"> 96</span><spanclass="comment">// - if there are no admissible arcs, the active node considered is relabeled,</span></div>
<divclass="line"><aid="l00097"name="l00097"></a><spanclass="lineno"> 97</span><spanclass="comment">// This is implemented in Discharge, which itself calls PushFlow and Relabel.</span></div>
<divclass="line"><aid="l00099"name="l00099"></a><spanclass="lineno"> 99</span><spanclass="comment">// Discharge itself is called by Refine. Refine first saturates all the</span></div>
<divclass="line"><aid="l00100"name="l00100"></a><spanclass="lineno"> 100</span><spanclass="comment">// admissible arcs, then builds a stack of active nodes. It then applies</span></div>
<divclass="line"><aid="l00101"name="l00101"></a><spanclass="lineno"> 101</span><spanclass="comment">// Discharge for each active node, possibly adding new ones in the process,</span></div>
<divclass="line"><aid="l00102"name="l00102"></a><spanclass="lineno"> 102</span><spanclass="comment">// until no nodes are active. In that case an epsilon-optimal flow is obtained.</span></div>
<divclass="line"><aid="l00104"name="l00104"></a><spanclass="lineno"> 104</span><spanclass="comment">// Optimize iteratively calls Refine, while epsilon > 1, and divides epsilon by</span></div>
<divclass="line"><aid="l00105"name="l00105"></a><spanclass="lineno"> 105</span><spanclass="comment">// alpha (set by default to 5) before each iteration.</span></div>
<divclass="line"><aid="l00107"name="l00107"></a><spanclass="lineno"> 107</span><spanclass="comment">// The algorithm starts with epsilon = C, where C is the maximum absolute value</span></div>
<divclass="line"><aid="l00108"name="l00108"></a><spanclass="lineno"> 108</span><spanclass="comment">// of the arc costs. In the integer case which we are dealing with, since all</span></div>
<divclass="line"><aid="l00109"name="l00109"></a><spanclass="lineno"> 109</span><spanclass="comment">// costs are multiplied by (n+1), the initial value of epsilon is (n+1)*C.</span></div>
<divclass="line"><aid="l00110"name="l00110"></a><spanclass="lineno"> 110</span><spanclass="comment">// The algorithm terminates when epsilon = 1, and Refine() has been called.</span></div>
<divclass="line"><aid="l00111"name="l00111"></a><spanclass="lineno"> 111</span><spanclass="comment">// In this case, a minimum-cost flow is obtained.</span></div>
<divclass="line"><aid="l00113"name="l00113"></a><spanclass="lineno"> 113</span><spanclass="comment">// The complexity of the algorithm is O(n^2*m*log(n*C)) where C is the value of</span></div>
<divclass="line"><aid="l00114"name="l00114"></a><spanclass="lineno"> 114</span><spanclass="comment">// the largest arc cost in the graph.</span></div>
<divclass="line"><aid="l00117"name="l00117"></a><spanclass="lineno"> 117</span><spanclass="comment">// The algorithm is not able to detect the infeasibility of a problem (i.e.,</span></div>
<divclass="line"><aid="l00118"name="l00118"></a><spanclass="lineno"> 118</span><spanclass="comment">// when a bottleneck in the network prohibits sending all the supplies.)</span></div>
<divclass="line"><aid="l00119"name="l00119"></a><spanclass="lineno"> 119</span><spanclass="comment">// Worse, it could in some cases loop forever. This is why feasibility checking</span></div>
<divclass="line"><aid="l00120"name="l00120"></a><spanclass="lineno"> 120</span><spanclass="comment">// is enabled by default (FLAGS_min_cost_flow_check_feasibility=true.)</span></div>
<divclass="line"><aid="l00121"name="l00121"></a><spanclass="lineno"> 121</span><spanclass="comment">// Feasibility checking is implemented using a max-flow, which has a much lower</span></div>
<divclass="line"><aid="l00122"name="l00122"></a><spanclass="lineno"> 122</span><spanclass="comment">// complexity. The impact on performance is negligible, while the risk of being</span></div>
<divclass="line"><aid="l00123"name="l00123"></a><spanclass="lineno"> 123</span><spanclass="comment">// caught in an endless loop is removed. Note that using the feasibility checker</span></div>
<divclass="line"><aid="l00124"name="l00124"></a><spanclass="lineno"> 124</span><spanclass="comment">// roughly doubles the memory consumption.</span></div>
<divclass="line"><aid="l00126"name="l00126"></a><spanclass="lineno"> 126</span><spanclass="comment">// The starting reference for this class of algorithms is:</span></div>
<divclass="line"><aid="l00137"name="l00137"></a><spanclass="lineno"> 137</span><spanclass="comment">// A.V. Goldberg and M. Kharitonov, "On Implementing Scaling Push-Relabel</span></div>
<divclass="line"><aid="l00138"name="l00138"></a><spanclass="lineno"> 138</span><spanclass="comment">// Algorithms for the Minimum-Cost Flow Problem", Network flows and matching:</span></div>
<divclass="line"><aid="l00139"name="l00139"></a><spanclass="lineno"> 139</span><spanclass="comment">// First DIMACS implementation challenge, DIMACS Series in Discrete Mathematics</span></div>
<divclass="line"><aid="l00140"name="l00140"></a><spanclass="lineno"> 140</span><spanclass="comment">// and Theoretical Computer Science, (1993) 12:157-198.</span></div>
<divclass="line"><aid="l00142"name="l00142"></a><spanclass="lineno"> 142</span><spanclass="comment">// and in:</span></div>
<divclass="line"><aid="l00143"name="l00143"></a><spanclass="lineno"> 143</span><spanclass="comment">// U. Bunnagel, B. Korte, and J. Vygen. “Efficient implementation of the</span></div>
<divclass="line"><aid="l00148"name="l00148"></a><spanclass="lineno"> 148</span><spanclass="comment">// We have tried as much as possible in this implementation to keep the</span></div>
<divclass="line"><aid="l00149"name="l00149"></a><spanclass="lineno"> 149</span><spanclass="comment">// notations and namings of the papers cited above, except for 'demand' or</span></div>
<divclass="line"><aid="l00150"name="l00150"></a><spanclass="lineno"> 150</span><spanclass="comment">// 'balance' which have been replaced by 'supply', with the according sign</span></div>
<divclass="line"><aid="l00151"name="l00151"></a><spanclass="lineno"> 151</span><spanclass="comment">// changes to better accommodate with the API of the rest of our tools. A demand</span></div>
<divclass="line"><aid="l00152"name="l00152"></a><spanclass="lineno"> 152</span><spanclass="comment">// is denoted by a negative supply.</span></div>
<divclass="line"><aid="l00154"name="l00154"></a><spanclass="lineno"> 154</span><spanclass="comment">// TODO(user): See whether the following can bring any improvements on real-life</span></div>
<divclass="line"><aid="l00160"name="l00160"></a><spanclass="lineno"> 160</span><spanclass="comment">// An interesting general reference on network flows is:</span></div>
<divclass="line"><aid="l00161"name="l00161"></a><spanclass="lineno"> 161</span><spanclass="comment">// R. K. Ahuja, T. L. Magnanti, J. B. Orlin, "Network Flows: Theory, Algorithms,</span></div>
<divclass="line"><aid="l00162"name="l00162"></a><spanclass="lineno"> 162</span><spanclass="comment">// and Applications," Prentice Hall, 1993, ISBN: 978-0136175490,</span></div>
<divclass="line"><aid="l00191"name="l00191"></a><spanclass="lineno"> 191</span><spanclass="comment">// Different statuses for a solved problem.</span></div>
<divclass="line"><aid="l00192"name="l00192"></a><spanclass="lineno"> 192</span><spanclass="comment">// We use a base class to share it between our different interfaces.</span></div>
<divclass="line"><aid="l00206"name="l00206"></a><spanclass="lineno"> 206</span><spanclass="comment">// A simple and efficient min-cost flow interface. This is as fast as</span></div>
<divclass="line"><aid="l00207"name="l00207"></a><spanclass="lineno"> 207</span><spanclass="comment">// GenericMinCostFlow<ReverseArcStaticGraph>, which is the fastest, but is uses</span></div>
<divclass="line"><aid="l00208"name="l00208"></a><spanclass="lineno"> 208</span><spanclass="comment">// more memory in order to hide the somewhat involved construction of the</span></div>
<divclass="line"><aid="l00211"name="l00211"></a><spanclass="lineno"> 211</span><spanclass="comment">// TODO(user): If the need arises, extend this interface to support warm start</span></div>
<divclass="line"><aid="l00212"name="l00212"></a><spanclass="lineno"> 212</span><spanclass="comment">// and incrementality between solves. Note that this is already supported by the</span></div>
<divclass="line"><aid="l00216"name="l00216"></a><spanclass="lineno"> 216</span><spanclass="comment">// By default, the constructor takes no size. New node indices are created</span></div>
<divclass="line"><aid="l00217"name="l00217"></a><spanclass="lineno"> 217</span><spanclass="comment">// lazily by AddArcWithCapacityAndUnitCost() or SetNodeSupply() such that the</span></div>
<divclass="line"><aid="l00218"name="l00218"></a><spanclass="lineno"> 218</span><spanclass="comment">// set of valid nodes will always be [0, NumNodes()).</span></div>
<divclass="line"><aid="l00220"name="l00220"></a><spanclass="lineno"> 220</span><spanclass="comment">// You may pre-reserve the internal data structures with a given expected</span></div>
<divclass="line"><aid="l00221"name="l00221"></a><spanclass="lineno"> 221</span><spanclass="comment">// number of nodes and arcs, to potentially gain performance.</span></div>
<divclass="line"><aid="l00225"name="l00225"></a><spanclass="lineno"> 225</span><spanclass="comment">// Adds a directed arc from tail to head to the underlying graph with</span></div>
<divclass="line"><aid="l00226"name="l00226"></a><spanclass="lineno"> 226</span><spanclass="comment">// a given capacity and cost per unit of flow.</span></div>
<divclass="line"><aid="l00227"name="l00227"></a><spanclass="lineno"> 227</span><spanclass="comment">// * Node indices and the capacity must be non-negative (>= 0).</span></div>
<divclass="line"><aid="l00228"name="l00228"></a><spanclass="lineno"> 228</span><spanclass="comment">// * The unit cost can take any integer value (even negative).</span></div>
<divclass="line"><aid="l00229"name="l00229"></a><spanclass="lineno"> 229</span><spanclass="comment">// * Self-looping and duplicate arcs are supported.</span></div>
<divclass="line"><aid="l00230"name="l00230"></a><spanclass="lineno"> 230</span><spanclass="comment">// * After the method finishes, NumArcs() == the returned ArcIndex + 1.</span></div>
<divclass="line"><aid="l00235"name="l00235"></a><spanclass="lineno"> 235</span><spanclass="comment">// Sets the supply of the given node. The node index must be non-negative (>=</span></div>
<divclass="line"><aid="l00236"name="l00236"></a><spanclass="lineno"> 236</span><spanclass="comment">// 0). Nodes implicitly created will have a default supply set to 0. A demand</span></div>
<divclass="line"><aid="l00237"name="l00237"></a><spanclass="lineno"> 237</span><spanclass="comment">// is modeled as a negative supply.</span></div>
<divclass="line"><aid="l00240"name="l00240"></a><spanclass="lineno"> 240</span><spanclass="comment">// Solves the problem, and returns the problem status. This function</span></div>
<divclass="line"><aid="l00241"name="l00241"></a><spanclass="lineno"> 241</span><spanclass="comment">// requires that the sum of all node supply minus node demand is zero and</span></div>
<divclass="line"><aid="l00242"name="l00242"></a><spanclass="lineno"> 242</span><spanclass="comment">// that the graph has enough capacity to send all supplies and serve all</span></div>
<divclass="line"><aid="l00243"name="l00243"></a><spanclass="lineno"> 243</span><spanclass="comment">// demands. Otherwise, it will return INFEASIBLE.</span></div>
<divclass="line"><aid="l00248"name="l00248"></a><spanclass="lineno"> 248</span><spanclass="comment">// Same as Solve(), but does not have the restriction that the supply</span></div>
<divclass="line"><aid="l00249"name="l00249"></a><spanclass="lineno"> 249</span><spanclass="comment">// must match the demand or that the graph has enough capacity to serve</span></div>
<divclass="line"><aid="l00250"name="l00250"></a><spanclass="lineno"> 250</span><spanclass="comment">// all the demand or use all the supply. This will compute a maximum-flow</span></div>
<divclass="line"><aid="l00251"name="l00251"></a><spanclass="lineno"> 251</span><spanclass="comment">// with minimum cost. The value of the maximum-flow will be given by</span></div>
<divclass="line"><aid="l00257"name="l00257"></a><spanclass="lineno"> 257</span><spanclass="comment">// Returns the cost of the minimum-cost flow found by the algorithm when</span></div>
<divclass="line"><aid="l00258"name="l00258"></a><spanclass="lineno"> 258</span><spanclass="comment">// the returned Status is OPTIMAL.</span></div>
<divclass="line"><aid="l00261"name="l00261"></a><spanclass="lineno"> 261</span><spanclass="comment">// Returns the total flow of the minimum-cost flow found by the algorithm</span></div>
<divclass="line"><aid="l00262"name="l00262"></a><spanclass="lineno"> 262</span><spanclass="comment">// when the returned Status is OPTIMAL.</span></div>
<divclass="line"><aid="l00265"name="l00265"></a><spanclass="lineno"> 265</span><spanclass="comment">// Returns the flow on arc, this only make sense for a successful Solve().</span></div>
<divclass="line"><aid="l00267"name="l00267"></a><spanclass="lineno"> 267</span><spanclass="comment">// Note: It is possible that there is more than one optimal solution. The</span></div>
<divclass="line"><aid="l00268"name="l00268"></a><spanclass="lineno"> 268</span><spanclass="comment">// algorithm is deterministic so it will always return the same solution for</span></div>
<divclass="line"><aid="l00269"name="l00269"></a><spanclass="lineno"> 269</span><spanclass="comment">// a given problem. However, there is no guarantee of this from one code</span></div>
<divclass="line"><aid="l00270"name="l00270"></a><spanclass="lineno"> 270</span><spanclass="comment">// version to the next (but the code does not change often).</span></div>
<divclass="line"><aid="l00273"name="l00273"></a><spanclass="lineno"> 273</span><spanclass="comment">// Accessors for the user given data. The implementation will crash if "arc"</span></div>
<divclass="line"><aid="l00274"name="l00274"></a><spanclass="lineno"> 274</span><spanclass="comment">// is not in [0, NumArcs()) or "node" is not in [0, NumNodes()).</span></div>
<divclass="line"><aid="l00287"name="l00287"></a><spanclass="lineno"> 287</span><spanclass="comment">// Applies the permutation in arc_permutation_ to the given arc index.</span></div>
<divclass="line"><aid="l00307"name="l00307"></a><spanclass="lineno"> 307</span><spanclass="comment">// Generic MinCostFlow that works with StarGraph and all the graphs handling</span></div>
<divclass="line"><aid="l00308"name="l00308"></a><spanclass="lineno"> 308</span><spanclass="comment">// reverse arcs from graph.h, see the end of min_cost_flow.cc for the exact</span></div>
<divclass="line"><aid="l00309"name="l00309"></a><spanclass="lineno"> 309</span><spanclass="comment">// types this class is compiled for.</span></div>
<divclass="line"><aid="l00311"name="l00311"></a><spanclass="lineno"> 311</span><spanclass="comment">// One can greatly decrease memory usage by using appropriately small integer</span></div>
<divclass="line"><aid="l00313"name="l00313"></a><spanclass="lineno"> 313</span><spanclass="comment">// - For the Graph<> types, i.e. NodeIndexType and ArcIndexType, see graph.h.</span></div>
<divclass="line"><aid="l00314"name="l00314"></a><spanclass="lineno"> 314</span><spanclass="comment">// - ArcFlowType is used for the *per-arc* flow quantity. It must be signed, and</span></div>
<divclass="line"><aid="l00315"name="l00315"></a><spanclass="lineno"> 315</span><spanclass="comment">// large enough to hold the maximum arc capacity and its negation.</span></div>
<divclass="line"><aid="l00316"name="l00316"></a><spanclass="lineno"> 316</span><spanclass="comment">// - ArcScaledCostType is used for a per-arc scaled cost. It must be signed</span></div>
<divclass="line"><aid="l00317"name="l00317"></a><spanclass="lineno"> 317</span><spanclass="comment">// and large enough to hold the maximum unit cost of an arc times</span></div>
<divclass="line"><aid="l00320"name="l00320"></a><spanclass="lineno"> 320</span><spanclass="comment">// Note that the latter two are different than FlowQuantity and CostValue, which</span></div>
<divclass="line"><aid="l00321"name="l00321"></a><spanclass="lineno"> 321</span><spanclass="comment">// are used for global, aggregated values and may need to be larger.</span></div>
<divclass="line"><aid="l00323"name="l00323"></a><spanclass="lineno"> 323</span><spanclass="comment">// TODO(user): Avoid using the globally defined type CostValue and FlowQuantity.</span></div>
<divclass="line"><aid="l00324"name="l00324"></a><spanclass="lineno"> 324</span><spanclass="comment">// Also uses the Arc*Type where there is no risk of overflow in more places.</span></div>
<divclass="line"><aid="l00336"name="l00336"></a><spanclass="lineno"> 336</span><spanclass="comment">// Initialize a MinCostFlow instance on the given graph. The graph does not</span></div>
<divclass="line"><aid="l00337"name="l00337"></a><spanclass="lineno"> 337</span><spanclass="comment">// need to be fully built yet, but its capacity reservation is used to</span></div>
<divclass="line"><aid="l00338"name="l00338"></a><spanclass="lineno"> 338</span><spanclass="comment">// initialize the memory of this class.</span></div>
<divclass="line"><aid="l00341"name="l00341"></a><spanclass="lineno"> 341</span><spanclass="comment">// Returns the graph associated to the current object.</span></div>
<divclass="line"><aid="l00344"name="l00344"></a><spanclass="lineno"> 344</span><spanclass="comment">// Returns the status of last call to Solve(). NOT_SOLVED is returned if</span></div>
<divclass="line"><aid="l00345"name="l00345"></a><spanclass="lineno"> 345</span><spanclass="comment">// Solve() has never been called or if the problem has been modified in such a</span></div>
<divclass="line"><aid="l00346"name="l00346"></a><spanclass="lineno"> 346</span><spanclass="comment">// way that the previous solution becomes invalid.</span></div>
<divclass="line"><aid="l00349"name="l00349"></a><spanclass="lineno"> 349</span><spanclass="comment">// Sets the supply corresponding to node. A demand is modeled as a negative</span></div>
<divclass="line"><aid="l00353"name="l00353"></a><spanclass="lineno"> 353</span><spanclass="comment">// Sets the unit cost for the given arc.</span></div>
<divclass="line"><aid="l00356"name="l00356"></a><spanclass="lineno"> 356</span><spanclass="comment">// Sets the capacity for the given arc.</span></div>
<divclass="line"><aid="l00359"name="l00359"></a><spanclass="lineno"> 359</span><spanclass="comment">// Sets the flow for the given arc. Note that new_flow must be smaller than</span></div>
<divclass="line"><aid="l00360"name="l00360"></a><spanclass="lineno"> 360</span><spanclass="comment">// the capacity of the arc.</span></div>
<divclass="line"><aid="l00363"name="l00363"></a><spanclass="lineno"> 363</span><spanclass="comment">// Solves the problem, returning true if a min-cost flow could be found.</span></div>
<divclass="line"><aid="l00366"name="l00366"></a><spanclass="lineno"> 366</span><spanclass="comment">// Checks for feasibility, i.e., that all the supplies and demands can be</span></div>
<divclass="line"><aid="l00367"name="l00367"></a><spanclass="lineno"> 367</span><spanclass="comment">// matched without exceeding bottlenecks in the network.</span></div>
<divclass="line"><aid="l00368"name="l00368"></a><spanclass="lineno"> 368</span><spanclass="comment">// If infeasible_supply_node (resp. infeasible_demand_node) are not NULL,</span></div>
<divclass="line"><aid="l00369"name="l00369"></a><spanclass="lineno"> 369</span><spanclass="comment">// they are populated with the indices of the nodes where the initial supplies</span></div>
<divclass="line"><aid="l00370"name="l00370"></a><spanclass="lineno"> 370</span><spanclass="comment">// (resp. demands) are too large. Feasible values for the supplies and</span></div>
<divclass="line"><aid="l00371"name="l00371"></a><spanclass="lineno"> 371</span><spanclass="comment">// demands are accessible through FeasibleSupply.</span></div>
<divclass="line"><aid="l00372"name="l00372"></a><spanclass="lineno"> 372</span><spanclass="comment">// Note that CheckFeasibility is called by Solve() when the flag</span></div>
<divclass="line"><aid="l00373"name="l00373"></a><spanclass="lineno"> 373</span><spanclass="comment">// min_cost_flow_check_feasibility is set to true (which is the default.)</span></div>
<divclass="line"><aid="l00377"name="l00377"></a><spanclass="lineno"> 377</span><spanclass="comment">// Makes the min-cost flow problem solvable by truncating supplies and</span></div>
<divclass="line"><aid="l00378"name="l00378"></a><spanclass="lineno"> 378</span><spanclass="comment">// demands to a level acceptable by the network. There may be several ways to</span></div>
<divclass="line"><aid="l00379"name="l00379"></a><spanclass="lineno"> 379</span><spanclass="comment">// do it. In our case, the levels are computed from the result of the max-flow</span></div>
<divclass="line"><aid="l00380"name="l00380"></a><spanclass="lineno"> 380</span><spanclass="comment">// algorithm run in CheckFeasibility().</span></div>
<divclass="line"><aid="l00381"name="l00381"></a><spanclass="lineno"> 381</span><spanclass="comment">// MakeFeasible returns false if CheckFeasibility() was not called before.</span></div>
<divclass="line"><aid="l00384"name="l00384"></a><spanclass="lineno"> 384</span><spanclass="comment">// Returns the cost of the minimum-cost flow found by the algorithm.</span></div>
<divclass="line"><aid="l00387"name="l00387"></a><spanclass="lineno"> 387</span><spanclass="comment">// Returns the flow on the given arc using the equations given in the</span></div>
<divclass="line"><aid="l00388"name="l00388"></a><spanclass="lineno"> 388</span><spanclass="comment">// comment on residual_arc_capacity_.</span></div>
<divclass="line"><aid="l00391"name="l00391"></a><spanclass="lineno"> 391</span><spanclass="comment">// Returns the capacity of the given arc.</span></div>
<divclass="line"><aid="l00394"name="l00394"></a><spanclass="lineno"> 394</span><spanclass="comment">// Returns the unscaled cost for the given arc.</span></div>
<divclass="line"><aid="l00397"name="l00397"></a><spanclass="lineno"> 397</span><spanclass="comment">// Returns the supply at a given node. Demands are modelled as negative</span></div>
<divclass="line"><aid="l00401"name="l00401"></a><spanclass="lineno"> 401</span><spanclass="comment">// Returns the initial supply at a given node.</span></div>
<divclass="line"><aid="l00404"name="l00404"></a><spanclass="lineno"> 404</span><spanclass="comment">// Returns the largest supply (if > 0) or largest demand in absolute value</span></div>
<divclass="line"><aid="l00405"name="l00405"></a><spanclass="lineno"> 405</span><spanclass="comment">// (if < 0) admissible at node. If the problem is not feasible, some of these</span></div>
<divclass="line"><aid="l00406"name="l00406"></a><spanclass="lineno"> 406</span><spanclass="comment">// values will be smaller (in absolute value) than the initial supplies</span></div>
<divclass="line"><aid="l00407"name="l00407"></a><spanclass="lineno"> 407</span><spanclass="comment">// and demand given as input.</span></div>
<divclass="line"><aid="l00410"name="l00410"></a><spanclass="lineno"> 410</span><spanclass="comment">// Whether to use the UpdatePrices() heuristic.</span></div>
<divclass="line"><aid="l00413"name="l00413"></a><spanclass="lineno"> 413</span><spanclass="comment">// Whether to check the feasibility of the problem with a max-flow, prior to</span></div>
<divclass="line"><aid="l00414"name="l00414"></a><spanclass="lineno"> 414</span><spanclass="comment">// solving it. This uses about twice as much memory, but detects infeasible</span></div>
<divclass="line"><aid="l00415"name="l00415"></a><spanclass="lineno"> 415</span><spanclass="comment">// problems (where the flow can't be satisfied) and makes Solve() return</span></div>
<divclass="line"><aid="l00416"name="l00416"></a><spanclass="lineno"> 416</span><spanclass="comment">// INFEASIBLE. If you disable this check, you will spare memory but you must</span></div>
<divclass="line"><aid="l00417"name="l00417"></a><spanclass="lineno"> 417</span><spanclass="comment">// make sure that your problem is feasible, otherwise the code can loop</span></div>
<divclass="line"><aid="l00422"name="l00422"></a><spanclass="lineno"> 422</span><spanclass="comment">// Returns true if the given arc is admissible i.e. if its residual capacity</span></div>
<divclass="line"><aid="l00423"name="l00423"></a><spanclass="lineno"> 423</span><spanclass="comment">// is strictly positive, and its reduced cost strictly negative, i.e., pushing</span></div>
<divclass="line"><aid="l00424"name="l00424"></a><spanclass="lineno"> 424</span><spanclass="comment">// more flow into it will result in a reduction of the total cost.</span></div>
<divclass="line"><aid="l00428"name="l00428"></a><spanclass="lineno"> 428</span><spanclass="comment">// Returns true if node is active, i.e., if its supply is positive.</span></div>
<divclass="line"><aid="l00431"name="l00431"></a><spanclass="lineno"> 431</span><spanclass="comment">// Returns the reduced cost for a given arc.</span></div>
<divclass="line"><aid="l00435"name="l00435"></a><spanclass="lineno"> 435</span><spanclass="comment">// Returns the first incident arc of a given node.</span></div>
<divclass="line"><aid="l00438"name="l00438"></a><spanclass="lineno"> 438</span><spanclass="comment">// Checks the consistency of the input, i.e., whether the sum of the supplies</span></div>
<divclass="line"><aid="l00439"name="l00439"></a><spanclass="lineno"> 439</span><spanclass="comment">// for all nodes is equal to zero. To be used in a DCHECK.</span></div>
<divclass="line"><aid="l00442"name="l00442"></a><spanclass="lineno"> 442</span><spanclass="comment">// Checks whether the result is valid, i.e. whether for each arc,</span></div>
<divclass="line"><aid="l00444"name="l00444"></a><spanclass="lineno"> 444</span><spanclass="comment">// (A solution is epsilon-optimal if ReducedCost(arc) >= -epsilon.)</span></div>
<divclass="line"><aid="l00445"name="l00445"></a><spanclass="lineno"> 445</span><spanclass="comment">// To be used in a DCHECK.</span></div>
<divclass="line"><aid="l00448"name="l00448"></a><spanclass="lineno"> 448</span><spanclass="comment">// Checks that the cost range fits in the range of int64_t's.</span></div>
<divclass="line"><aid="l00449"name="l00449"></a><spanclass="lineno"> 449</span><spanclass="comment">// To be used in a DCHECK.</span></div>
<divclass="line"><aid="l00452"name="l00452"></a><spanclass="lineno"> 452</span><spanclass="comment">// Checks the relabel precondition (to be used in a DCHECK):</span></div>
<divclass="line"><aid="l00453"name="l00453"></a><spanclass="lineno"> 453</span><spanclass="comment">// - The node must be active, or have a 0 excess (relaxation for the Push</span></div>
<divclass="line"><aid="l00455"name="l00455"></a><spanclass="lineno"> 455</span><spanclass="comment">// - The node must have no admissible arcs.</span></div>
<divclass="line"><aid="l00458"name="l00458"></a><spanclass="lineno"> 458</span><spanclass="comment">// Returns context concatenated with information about a given arc</span></div>
<divclass="line"><aid="l00459"name="l00459"></a><spanclass="lineno"> 459</span><spanclass="comment">// in a human-friendly way.</span></div>
<divclass="line"><aid="l00462"name="l00462"></a><spanclass="lineno"> 462</span><spanclass="comment">// Resets the first_admissible_arc_ array to the first incident arc of each</span></div>
<divclass="line"><aid="l00466"name="l00466"></a><spanclass="lineno"> 466</span><spanclass="comment">// Scales the costs, by multiplying them by (graph_->num_nodes() + 1).</span></div>
<divclass="line"><aid="l00469"name="l00469"></a><spanclass="lineno"> 469</span><spanclass="comment">// Unscales the costs, by dividing them by (graph_->num_nodes() + 1).</span></div>
<divclass="line"><aid="l00472"name="l00472"></a><spanclass="lineno"> 472</span><spanclass="comment">// Optimizes the cost by dividing epsilon_ by alpha_ and calling Refine().</span></div>
<divclass="line"><aid="l00475"name="l00475"></a><spanclass="lineno"> 475</span><spanclass="comment">// Saturates the admissible arcs, i.e., push as much flow as possible.</span></div>
<divclass="line"><aid="l00478"name="l00478"></a><spanclass="lineno"> 478</span><spanclass="comment">// Pushes flow on a given arc, i.e., consumes flow on</span></div>
<divclass="line"><aid="l00479"name="l00479"></a><spanclass="lineno"> 479</span><spanclass="comment">// residual_arc_capacity_[arc], and consumes -flow on</span></div>
<divclass="line"><aid="l00480"name="l00480"></a><spanclass="lineno"> 480</span><spanclass="comment">// residual_arc_capacity_[Opposite(arc)]. Updates node_excess_ at the tail</span></div>
<divclass="line"><aid="l00481"name="l00481"></a><spanclass="lineno"> 481</span><spanclass="comment">// and head of the arc accordingly.</span></div>
<divclass="line"><aid="l00488"name="l00488"></a><spanclass="lineno"> 488</span><spanclass="comment">// Price update heuristics as described in A.V. Goldberg, "An Efficient</span></div>
<divclass="line"><aid="l00489"name="l00489"></a><spanclass="lineno"> 489</span><spanclass="comment">// Implementation of a Scaling Minimum-Cost Flow Algorithm," Journal of</span></div>
<divclass="line"><aid="l00494"name="l00494"></a><spanclass="lineno"> 494</span><spanclass="comment">// Performs an epsilon-optimization step by saturating admissible arcs</span></div>
<divclass="line"><aid="l00495"name="l00495"></a><spanclass="lineno"> 495</span><spanclass="comment">// and discharging the active nodes.</span></div>
<divclass="line"><aid="l00498"name="l00498"></a><spanclass="lineno"> 498</span><spanclass="comment">// Discharges an active node by saturating its admissible adjacent arcs,</span></div>
<divclass="line"><aid="l00499"name="l00499"></a><spanclass="lineno"> 499</span><spanclass="comment">// if any, and by relabelling it when it becomes inactive.</span></div>
<divclass="line"><aid="l00502"name="l00502"></a><spanclass="lineno"> 502</span><spanclass="comment">// Part of the Push LookAhead heuristic. When we are about to push on the</span></div>
<divclass="line"><aid="l00503"name="l00503"></a><spanclass="lineno"> 503</span><spanclass="comment">// in_arc, we check that the head (i.e node here) can accept the flow and</span></div>
<divclass="line"><aid="l00504"name="l00504"></a><spanclass="lineno"> 504</span><spanclass="comment">// return true if this is the case:</span></div>
<divclass="line"><aid="l00505"name="l00505"></a><spanclass="lineno"> 505</span><spanclass="comment">// - Returns true if the node excess is < 0.</span></div>
<divclass="line"><aid="l00506"name="l00506"></a><spanclass="lineno"> 506</span><spanclass="comment">// - Returns true if node is an admissible arc at its current potential.</span></div>
<divclass="line"><aid="l00507"name="l00507"></a><spanclass="lineno"> 507</span><spanclass="comment">// - If the two conditions above are false, the node can be relabeled. We</span></div>
<divclass="line"><aid="l00508"name="l00508"></a><spanclass="lineno"> 508</span><spanclass="comment">// do that and return true if the in_arc is still admissible.</span></div>
<divclass="line"><aid="l00511"name="l00511"></a><spanclass="lineno"> 511</span><spanclass="comment">// Relabels node, i.e., decreases its potential while keeping the</span></div>
<divclass="line"><aid="l00512"name="l00512"></a><spanclass="lineno"> 512</span><spanclass="comment">// epsilon-optimality of the pseudo flow. See CheckRelabelPrecondition() for</span></div>
<divclass="line"><aid="l00513"name="l00513"></a><spanclass="lineno"> 513</span><spanclass="comment">// details on the preconditions.</span></div>
<divclass="line"><aid="l00516"name="l00516"></a><spanclass="lineno"> 516</span><spanclass="comment">// Handy member functions to make the code more compact.</span></div>
<divclass="line"><aid="l00523"name="l00523"></a><spanclass="lineno"> 523</span><spanclass="comment">// Pointer to the graph passed as argument.</span></div>
<divclass="line"><aid="l00526"name="l00526"></a><spanclass="lineno"> 526</span><spanclass="comment">// An array representing the supply (if > 0) or the demand (if < 0)</span></div>
<divclass="line"><aid="l00527"name="l00527"></a><spanclass="lineno"> 527</span><spanclass="comment">// for each node in graph_.</span></div>
<divclass="line"><aid="l00534"name="l00534"></a><spanclass="lineno"> 534</span><spanclass="comment">// An array representing the residual_capacity for each arc in graph_.</span></div>
<divclass="line"><aid="l00535"name="l00535"></a><spanclass="lineno"> 535</span><spanclass="comment">// Residual capacities enable one to represent the capacity and flow for all</span></div>
<divclass="line"><aid="l00536"name="l00536"></a><spanclass="lineno"> 536</span><spanclass="comment">// arcs in the graph in the following manner.</span></div>
<divclass="line"><aid="l00537"name="l00537"></a><spanclass="lineno"> 537</span><spanclass="comment">// For all arcs, residual_arc_capacity_[arc] = capacity[arc] - flow[arc]</span></div>
<divclass="line"><aid="l00538"name="l00538"></a><spanclass="lineno"> 538</span><spanclass="comment">// Moreover, for reverse arcs, capacity[arc] = 0 by definition.</span></div>
<divclass="line"><aid="l00539"name="l00539"></a><spanclass="lineno"> 539</span><spanclass="comment">// Also flow[Opposite(arc)] = -flow[arc] by definition.</span></div>
<divclass="line"><aid="l00547"name="l00547"></a><spanclass="lineno"> 547</span><spanclass="comment">// Using these facts enables one to only maintain residual_arc_capacity_,</span></div>
<divclass="line"><aid="l00548"name="l00548"></a><spanclass="lineno"> 548</span><spanclass="comment">// instead of both capacity and flow, for each direct and indirect arc. This</span></div>
<divclass="line"><aid="l00549"name="l00549"></a><spanclass="lineno"> 549</span><spanclass="comment">// reduces the amount of memory for this information by a factor 2.</span></div>
<divclass="line"><aid="l00550"name="l00550"></a><spanclass="lineno"> 550</span><spanclass="comment">// Note that the sum of the largest capacity of an arc in the graph and of</span></div>
<divclass="line"><aid="l00551"name="l00551"></a><spanclass="lineno"> 551</span><spanclass="comment">// the total flow in the graph mustn't exceed the largest 64 bit integer</span></div>
<divclass="line"><aid="l00552"name="l00552"></a><spanclass="lineno"> 552</span><spanclass="comment">// to avoid errors. CheckInputConsistency() verifies this constraint.</span></div>
<divclass="line"><aid="l00555"name="l00555"></a><spanclass="lineno"> 555</span><spanclass="comment">// An array representing the first admissible arc for each node in graph_.</span></div>
<divclass="line"><aid="l00558"name="l00558"></a><spanclass="lineno"> 558</span><spanclass="comment">// A stack used for managing active nodes in the algorithm.</span></div>
<divclass="line"><aid="l00559"name="l00559"></a><spanclass="lineno"> 559</span><spanclass="comment">// Note that the papers cited above recommend the use of a queue, but</span></div>
<divclass="line"><aid="l00560"name="l00560"></a><spanclass="lineno"> 560</span><spanclass="comment">// benchmarking so far has not proved it is better.</span></div>
<divclass="line"><aid="l00563"name="l00563"></a><spanclass="lineno"> 563</span><spanclass="comment">// epsilon_ is the tolerance for optimality.</span></div>
<divclass="line"><aid="l00566"name="l00566"></a><spanclass="lineno"> 566</span><spanclass="comment">// alpha_ is the factor by which epsilon_ is divided at each iteration of</span></div>
<divclass="line"><aid="l00570"name="l00570"></a><spanclass="lineno"> 570</span><spanclass="comment">// cost_scaling_factor_ is the scaling factor for cost.</span></div>
<divclass="line"><aid="l00573"name="l00573"></a><spanclass="lineno"> 573</span><spanclass="comment">// An array representing the scaled unit cost for each arc in graph_.</span></div>
<divclass="line"><aid="l00582"name="l00582"></a><spanclass="lineno"> 582</span><spanclass="comment">// An array containing the initial excesses (i.e. the supplies) for each</span></div>
<divclass="line"><aid="l00583"name="l00583"></a><spanclass="lineno"> 583</span><spanclass="comment">// node. This is used to create the max-flow-based feasibility checker.</span></div>
<divclass="line"><aid="l00586"name="l00586"></a><spanclass="lineno"> 586</span><spanclass="comment">// An array containing the best acceptable excesses for each of the</span></div>
<divclass="line"><aid="l00587"name="l00587"></a><spanclass="lineno"> 587</span><spanclass="comment">// nodes. These excesses are imposed by the result of the max-flow-based</span></div>
<divclass="line"><aid="l00588"name="l00588"></a><spanclass="lineno"> 588</span><spanclass="comment">// feasibility checker for the nodes with an initial supply != 0. For the</span></div>
<divclass="line"><aid="l00589"name="l00589"></a><spanclass="lineno"> 589</span><spanclass="comment">// other nodes, the excess is simply 0.</span></div>
<divclass="line"><aid="l00595"name="l00595"></a><spanclass="lineno"> 595</span><spanclass="comment">// Number of Relabel() since last UpdatePrices().</span></div>
<divclass="line"><aid="l00598"name="l00598"></a><spanclass="lineno"> 598</span><spanclass="comment">// A Boolean which is true when feasibility has been checked.</span></div>
<divclass="line"><aid="l00601"name="l00601"></a><spanclass="lineno"> 601</span><spanclass="comment">// Whether to use the UpdatePrices() heuristic.</span></div>
<divclass="line"><aid="l00604"name="l00604"></a><spanclass="lineno"> 604</span><spanclass="comment">// Whether to check the problem feasibility with a max-flow.</span></div>
<divclass="line"><aid="l00612"name="l00612"></a><spanclass="lineno"> 612</span><spanclass="comment">// Default MinCostFlow instance that uses StarGraph.</span></div>
<divclass="line"><aid="l00613"name="l00613"></a><spanclass="lineno"> 613</span><spanclass="comment">// New clients should use SimpleMinCostFlow if they can.</span></div>
<divclass="ttc"id="anamespaceoperations__research_html"><divclass="ttname"><ahref="namespaceoperations__research.html">operations_research</a></div><divclass="ttdoc">Collection of objects used to extend the Constraint Solver library.</div><divclass="ttdef"><b>Definition:</b><ahref="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>