<ahref="revised__simplex_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">// Solves a Linear Programming problem using the Revised Simplex algorithm</span></div>
<divclass="line"><aid="l00015"name="l00015"></a><spanclass="lineno"> 15</span><spanclass="comment">// as described by G.B. Dantzig.</span></div>
<divclass="line"><aid="l00016"name="l00016"></a><spanclass="lineno"> 16</span><spanclass="comment">// The general form is:</span></div>
<divclass="line"><aid="l00017"name="l00017"></a><spanclass="lineno"> 17</span><spanclass="comment">// min c.x where c and x are n-vectors,</span></div>
<divclass="line"><aid="l00018"name="l00018"></a><spanclass="lineno"> 18</span><spanclass="comment">// subject to Ax = b where A is an mxn-matrix, b an m-vector,</span></div>
<divclass="line"><aid="l00019"name="l00019"></a><spanclass="lineno"> 19</span><spanclass="comment">// with l <= x <= u, i.e.</span></div>
<divclass="line"><aid="l00020"name="l00020"></a><spanclass="lineno"> 20</span><spanclass="comment">// l_i <= x_i <= u_i for all i in {1 .. m}.</span></div>
<divclass="line"><aid="l00022"name="l00022"></a><spanclass="lineno"> 22</span><spanclass="comment">// c.x is called the objective function.</span></div>
<divclass="line"><aid="l00023"name="l00023"></a><spanclass="lineno"> 23</span><spanclass="comment">// Each row a_i of A is an n-vector, and a_i.x = b_i is a linear constraint.</span></div>
<divclass="line"><aid="l00024"name="l00024"></a><spanclass="lineno"> 24</span><spanclass="comment">// A is called the constraint matrix.</span></div>
<divclass="line"><aid="l00025"name="l00025"></a><spanclass="lineno"> 25</span><spanclass="comment">// b is called the right hand side (rhs) of the problem.</span></div>
<divclass="line"><aid="l00026"name="l00026"></a><spanclass="lineno"> 26</span><spanclass="comment">// The constraints l_i <= x_i <= u_i are called the generalized bounds</span></div>
<divclass="line"><aid="l00027"name="l00027"></a><spanclass="lineno"> 27</span><spanclass="comment">// of the problem (most introductory textbooks only deal with x_i >= 0, as</span></div>
<divclass="line"><aid="l00028"name="l00028"></a><spanclass="lineno"> 28</span><spanclass="comment">// did the first version of the Simplex algorithm). Note that l_i and u_i</span></div>
<divclass="line"><aid="l00029"name="l00029"></a><spanclass="lineno"> 29</span><spanclass="comment">// can be -infinity and +infinity, respectively.</span></div>
<divclass="line"><aid="l00031"name="l00031"></a><spanclass="lineno"> 31</span><spanclass="comment">// To simplify the entry of data, this code actually handles problems in the</span></div>
<divclass="line"><aid="l00033"name="l00033"></a><spanclass="lineno"> 33</span><spanclass="comment">// min c.x where c and x are n-vectors,</span></div>
<divclass="line"><aid="l00040"name="l00040"></a><spanclass="lineno"> 40</span><spanclass="comment">// It transforms the above problem into</span></div>
<divclass="line"><aid="l00041"name="l00041"></a><spanclass="lineno"> 41</span><spanclass="comment">// min c.x where c and x are n-vectors,</span></div>
<divclass="line"><aid="l00048"name="l00048"></a><spanclass="lineno"> 48</span><spanclass="comment">// where xT = (x1, x2, x3),</span></div>
<divclass="line"><aid="l00049"name="l00049"></a><spanclass="lineno"> 49</span><spanclass="comment">// s1 is an m1-vector (m1 being the height of A1),</span></div>
<divclass="line"><aid="l00050"name="l00050"></a><spanclass="lineno"> 50</span><spanclass="comment">// s2 is an m2-vector (m2 being the height of A2).</span></div>
<divclass="line"><aid="l00052"name="l00052"></a><spanclass="lineno"> 52</span><spanclass="comment">// The following are very good references for terminology, data structures,</span></div>
<divclass="line"><aid="l00053"name="l00053"></a><spanclass="lineno"> 53</span><spanclass="comment">// and algorithms. They all contain a wealth of references.</span></div>
<divclass="line"><aid="l00058"name="l00058"></a><spanclass="lineno"> 58</span><spanclass="comment">// Robert J. Vanderbei, "Linear Programming: Foundations and Extensions,"</span></div>
<divclass="line"><aid="l00067"name="l00067"></a><spanclass="lineno"> 67</span><spanclass="comment">// Short description of the dual simplex algorithm.</span></div>
<divclass="line"><aid="l00069"name="l00069"></a><spanclass="lineno"> 69</span><spanclass="comment">// The dual simplex algorithm uses the same data structure as the primal, but</span></div>
<divclass="line"><aid="l00070"name="l00070"></a><spanclass="lineno"> 70</span><spanclass="comment">// progresses towards the optimal solution in a different way:</span></div>
<divclass="line"><aid="l00071"name="l00071"></a><spanclass="lineno"> 71</span><spanclass="comment">// * It tries to keep the dual values dual-feasible at all time which means that</span></div>
<divclass="line"><aid="l00072"name="l00072"></a><spanclass="lineno"> 72</span><spanclass="comment">// the reduced costs are of the correct sign depending on the bounds of the</span></div>
<divclass="line"><aid="l00073"name="l00073"></a><spanclass="lineno"> 73</span><spanclass="comment">// non-basic variables. As a consequence the values of the basic variable are</span></div>
<divclass="line"><aid="l00074"name="l00074"></a><spanclass="lineno"> 74</span><spanclass="comment">// out of bound until the optimal is reached.</span></div>
<divclass="line"><aid="l00075"name="l00075"></a><spanclass="lineno"> 75</span><spanclass="comment">// * A basic leaving variable is selected first (dual pricing) and then a</span></div>
<divclass="line"><aid="l00076"name="l00076"></a><spanclass="lineno"> 76</span><spanclass="comment">// corresponding entering variable is selected. This is done in such a way</span></div>
<divclass="line"><aid="l00077"name="l00077"></a><spanclass="lineno"> 77</span><spanclass="comment">// that the dual objective value increases (lower bound on the optimal</span></div>
<divclass="line"><aid="l00079"name="l00079"></a><spanclass="lineno"> 79</span><spanclass="comment">// * Once the basis pivot is chosen, the variable values and the reduced costs</span></div>
<divclass="line"><aid="l00080"name="l00080"></a><spanclass="lineno"> 80</span><spanclass="comment">// are updated the same way as in the primal algorithm.</span></div>
<divclass="line"><aid="l00082"name="l00082"></a><spanclass="lineno"> 82</span><spanclass="comment">// Good references on the Dual simplex algorithm are:</span></div>
<divclass="line"><aid="l00084"name="l00084"></a><spanclass="lineno"> 84</span><spanclass="comment">// Robert Fourer, "Notes on the Dual simplex Method", March 14, 1994.</span></div>
<divclass="line"><aid="l00087"name="l00087"></a><spanclass="lineno"> 87</span><spanclass="comment">// Achim Koberstein, "The dual simplex method, techniques for a fast and stable</span></div>
<divclass="line"><aid="l00124"name="l00124"></a><spanclass="lineno"> 124</span><spanclass="comment">// Entry point of the revised simplex algorithm implementation.</span></div>
<divclass="line"><aid="l00129"name="l00129"></a><spanclass="lineno"> 129</span><spanclass="comment">// Sets or gets the algorithm parameters to be used on the next Solve().</span></div>
<divclass="line"><aid="l00135"name="l00135"></a><spanclass="lineno"> 135</span><spanclass="comment">// We accept two forms of LinearProgram:</span></div>
<divclass="line"><aid="l00136"name="l00136"></a><spanclass="lineno"> 136</span><spanclass="comment">// - The lp can be in the equations form Ax = 0 created by</span></div>
<divclass="line"><aid="l00137"name="l00137"></a><spanclass="lineno"> 137</span><spanclass="comment">// LinearProgram::AddSlackVariablesForAllRows(), i.e. the rightmost square</span></div>
<divclass="line"><aid="l00138"name="l00138"></a><spanclass="lineno"> 138</span><spanclass="comment">// submatrix of A is an identity matrix, all its columns have been marked as</span></div>
<divclass="line"><aid="l00139"name="l00139"></a><spanclass="lineno"> 139</span><spanclass="comment">// slack variables, and the bounds of all constraints have been set to 0.</span></div>
<divclass="line"><aid="l00140"name="l00140"></a><spanclass="lineno"> 140</span><spanclass="comment">// - If not, we will convert it internally while copying it to the internal</span></div>
<divclass="line"><aid="l00143"name="l00143"></a><spanclass="lineno"> 143</span><spanclass="comment">// By default, the algorithm tries to exploit the computation done during the</span></div>
<divclass="line"><aid="l00144"name="l00144"></a><spanclass="lineno"> 144</span><spanclass="comment">// last Solve() call. It will analyze the difference of the new linear program</span></div>
<divclass="line"><aid="l00145"name="l00145"></a><spanclass="lineno"> 145</span><spanclass="comment">// and try to use the previously computed solution as a warm-start. To disable</span></div>
<divclass="line"><aid="l00146"name="l00146"></a><spanclass="lineno"> 146</span><spanclass="comment">// this behavior or give explicit warm-start data, use one of the State*()</span></div>
<divclass="line"><aid="l00151"name="l00151"></a><spanclass="lineno"> 151</span><spanclass="comment">// Do not use the current solution as a warm-start for the next Solve(). The</span></div>
<divclass="line"><aid="l00152"name="l00152"></a><spanclass="lineno"> 152</span><spanclass="comment">// next Solve() will behave as if the class just got created.</span></div>
<divclass="line"><aid="l00155"name="l00155"></a><spanclass="lineno"> 155</span><spanclass="comment">// Uses the given state as a warm-start for the next Solve() call.</span></div>
<divclass="line"><aid="l00158"name="l00158"></a><spanclass="lineno"> 158</span><spanclass="comment">// Advanced usage. While constructing the initial basis, if this is called</span></div>
<divclass="line"><aid="l00159"name="l00159"></a><spanclass="lineno"> 159</span><spanclass="comment">// then we will use these values as the initial starting value for the FREE</span></div>
<divclass="line"><aid="l00163"name="l00163"></a><spanclass="lineno"> 163</span><spanclass="comment">// Advanced usage. Tells the next Solve() that the matrix inside the linear</span></div>
<divclass="line"><aid="l00164"name="l00164"></a><spanclass="lineno"> 164</span><spanclass="comment">// program will not change compared to the one used the last time Solve() was</span></div>
<divclass="line"><aid="l00165"name="l00165"></a><spanclass="lineno"> 165</span><spanclass="comment">// called. This allows to bypass the somewhat costly check of comparing both</span></div>
<divclass="line"><aid="l00166"name="l00166"></a><spanclass="lineno"> 166</span><spanclass="comment">// matrices. Note that this call will be ignored if Solve() was never called</span></div>
<divclass="line"><aid="l00167"name="l00167"></a><spanclass="lineno"> 167</span><spanclass="comment">// or if ClearStateForNextSolve() was called.</span></div>
<divclass="line"><aid="l00170"name="l00170"></a><spanclass="lineno"> 170</span><spanclass="comment">// Getters to retrieve all the information computed by the last Solve().</span></div>
<divclass="line"><aid="l00187"name="l00187"></a><spanclass="lineno"> 187</span><spanclass="comment">// If the problem status is PRIMAL_UNBOUNDED (respectively DUAL_UNBOUNDED),</span></div>
<divclass="line"><aid="l00188"name="l00188"></a><spanclass="lineno"> 188</span><spanclass="comment">// then the solver has a corresponding primal (respectively dual) ray to show</span></div>
<divclass="line"><aid="l00189"name="l00189"></a><spanclass="lineno"> 189</span><spanclass="comment">// the unboundness. From a primal (respectively dual) feasible solution any</span></div>
<divclass="line"><aid="l00190"name="l00190"></a><spanclass="lineno"> 190</span><spanclass="comment">// positive multiple of this ray can be added to the solution and keep it</span></div>
<divclass="line"><aid="l00191"name="l00191"></a><spanclass="lineno"> 191</span><spanclass="comment">// feasible. Moreover, by doing so, the objective of the problem will improve</span></div>
<divclass="line"><aid="l00192"name="l00192"></a><spanclass="lineno"> 192</span><spanclass="comment">// and its magnitude will go to infinity.</span></div>
<divclass="line"><aid="l00194"name="l00194"></a><spanclass="lineno"> 194</span><spanclass="comment">// Note that when the problem is DUAL_UNBOUNDED, the dual ray is also known as</span></div>
<divclass="line"><aid="l00195"name="l00195"></a><spanclass="lineno"> 195</span><spanclass="comment">// the Farkas proof of infeasibility of the problem.</span></div>
<divclass="line"><aid="l00199"name="l00199"></a><spanclass="lineno"> 199</span><spanclass="comment">// This is the "dual ray" linear combination of the matrix rows.</span></div>
<divclass="line"><aid="l00202"name="l00202"></a><spanclass="lineno"> 202</span><spanclass="comment">// Returns the index of the column in the basis and the basis factorization.</span></div>
<divclass="line"><aid="l00203"name="l00203"></a><spanclass="lineno"> 203</span><spanclass="comment">// Note that the order of the column in the basis is important since it is the</span></div>
<divclass="line"><aid="l00204"name="l00204"></a><spanclass="lineno"> 204</span><spanclass="comment">// one used by the various solve functions provided by the BasisFactorization</span></div>
<divclass="line"><aid="l00212"name="l00212"></a><spanclass="lineno"> 212</span><spanclass="comment">// Returns a copy of basis_ vector for outside applications (like cuts) to</span></div>
<divclass="line"><aid="l00213"name="l00213"></a><spanclass="lineno"> 213</span><spanclass="comment">// have the correspondence between rows and columns of the dictionary.</span></div>
<divclass="line"><aid="l00218"name="l00218"></a><spanclass="lineno"> 218</span><spanclass="comment">// Returns statistics about this class as a string.</span></div>
<divclass="line"><aid="l00221"name="l00221"></a><spanclass="lineno"> 221</span><spanclass="comment">// Computes the dictionary B^-1*N on-the-fly row by row. Returns the resulting</span></div>
<divclass="line"><aid="l00222"name="l00222"></a><spanclass="lineno"> 222</span><spanclass="comment">// matrix as a vector of sparse rows so that it is easy to use it on the left</span></div>
<divclass="line"><aid="l00223"name="l00223"></a><spanclass="lineno"> 223</span><spanclass="comment">// side in the matrix multiplication. Runs in O(num_non_zeros_in_matrix).</span></div>
<divclass="line"><aid="l00224"name="l00224"></a><spanclass="lineno"> 224</span><spanclass="comment">// TODO(user): Use row scales as well.</span></div>
<divclass="line"><aid="l00227"name="l00227"></a><spanclass="lineno"> 227</span><spanclass="comment">// Initializes the matrix for the given 'linear_program' and 'state' and</span></div>
<divclass="line"><aid="l00228"name="l00228"></a><spanclass="lineno"> 228</span><spanclass="comment">// computes the variable values for basic variables using non-basic variables.</span></div>
<divclass="line"><aid="l00232"name="l00232"></a><spanclass="lineno"> 232</span><spanclass="comment">// This is used in a MIP context to polish the final basis. We assume that the</span></div>
<divclass="line"><aid="l00233"name="l00233"></a><spanclass="lineno"> 233</span><spanclass="comment">// columns for which SetIntegralityScale() has been called correspond to</span></div>
<divclass="line"><aid="l00234"name="l00234"></a><spanclass="lineno"> 234</span><spanclass="comment">// integral variable once multiplied by the given factor.</span></div>
<divclass="line"><aid="l00281"name="l00281"></a><spanclass="lineno"> 281</span><spanclass="comment">// Propagates parameters_ to all the other classes that need it.</span></div>
<divclass="line"><aid="l00283"name="l00283"></a><spanclass="lineno"> 283</span><spanclass="comment">// TODO(user): Maybe a better design is for them to have a reference to a</span></div>
<divclass="line"><aid="l00284"name="l00284"></a><spanclass="lineno"> 284</span><spanclass="comment">// unique parameters object? It will clutter a bit more these classes'</span></div>
<divclass="line"><aid="l00288"name="l00288"></a><spanclass="lineno"> 288</span><spanclass="comment">// Returns a string containing the same information as with GetSolverStats,</span></div>
<divclass="line"><aid="l00289"name="l00289"></a><spanclass="lineno"> 289</span><spanclass="comment">// but in a much more human-readable format. For example:</span></div>
<divclass="line"><aid="l00290"name="l00290"></a><spanclass="lineno"> 290</span><spanclass="comment">// Problem status : Optimal</span></div>
<divclass="line"><aid="l00291"name="l00291"></a><spanclass="lineno"> 291</span><spanclass="comment">// Solving time : 1.843</span></div>
<divclass="line"><aid="l00292"name="l00292"></a><spanclass="lineno"> 292</span><spanclass="comment">// Number of iterations : 12345</span></div>
<divclass="line"><aid="l00293"name="l00293"></a><spanclass="lineno"> 293</span><spanclass="comment">// Time for solvability (first phase) : 1.343</span></div>
<divclass="line"><aid="l00294"name="l00294"></a><spanclass="lineno"> 294</span><spanclass="comment">// Number of iterations for solvability : 10000</span></div>
<divclass="line"><aid="l00295"name="l00295"></a><spanclass="lineno"> 295</span><spanclass="comment">// Time for optimization : 0.5</span></div>
<divclass="line"><aid="l00296"name="l00296"></a><spanclass="lineno"> 296</span><spanclass="comment">// Number of iterations for optimization : 2345</span></div>
<divclass="line"><aid="l00297"name="l00297"></a><spanclass="lineno"> 297</span><spanclass="comment">// Maximum time allowed in seconds : 6000</span></div>
<divclass="line"><aid="l00298"name="l00298"></a><spanclass="lineno"> 298</span><spanclass="comment">// Maximum number of iterations : 1000000</span></div>
<divclass="line"><aid="l00299"name="l00299"></a><spanclass="lineno"> 299</span><spanclass="comment">// Stop after first basis : 0</span></div>
<divclass="line"><aid="l00302"name="l00302"></a><spanclass="lineno"> 302</span><spanclass="comment">// Returns a string containing formatted information about the variable</span></div>
<divclass="line"><aid="l00303"name="l00303"></a><spanclass="lineno"> 303</span><spanclass="comment">// corresponding to column col.</span></div>
<divclass="line"><aid="l00306"name="l00306"></a><spanclass="lineno"> 306</span><spanclass="comment">// Displays a short string with the current iteration and objective value.</span></div>
<divclass="line"><aid="l00309"name="l00309"></a><spanclass="lineno"> 309</span><spanclass="comment">// Displays the error bounds of the current solution.</span></div>
<divclass="line"><aid="l00312"name="l00312"></a><spanclass="lineno"> 312</span><spanclass="comment">// Displays the status of the variables.</span></div>
<divclass="line"><aid="l00315"name="l00315"></a><spanclass="lineno"> 315</span><spanclass="comment">// Displays the bounds of the variables.</span></div>
<divclass="line"><aid="l00318"name="l00318"></a><spanclass="lineno"> 318</span><spanclass="comment">// Displays the following information:</span></div>
<divclass="line"><aid="l00319"name="l00319"></a><spanclass="lineno"> 319</span><spanclass="comment">// * Linear Programming problem as a dictionary, taking into</span></div>
<divclass="line"><aid="l00320"name="l00320"></a><spanclass="lineno"> 320</span><spanclass="comment">// account the iterations that have been made;</span></div>
<divclass="line"><aid="l00324"name="l00324"></a><spanclass="lineno"> 324</span><spanclass="comment">// A dictionary is in the form:</span></div>
<divclass="line"><aid="l00325"name="l00325"></a><spanclass="lineno"> 325</span><spanclass="comment">// xB = value + sum_{j in N} pa_ij x_j</span></div>
<divclass="line"><aid="l00326"name="l00326"></a><spanclass="lineno"> 326</span><spanclass="comment">// z = objective_value + sum_{i in N} rc_i x_i</span></div>
<divclass="line"><aid="l00327"name="l00327"></a><spanclass="lineno"> 327</span><spanclass="comment">// where the pa's are the coefficients of the matrix after the pivotings</span></div>
<divclass="line"><aid="l00328"name="l00328"></a><spanclass="lineno"> 328</span><spanclass="comment">// and the rc's are the reduced costs, i.e. the coefficients of the objective</span></div>
<divclass="line"><aid="l00329"name="l00329"></a><spanclass="lineno"> 329</span><spanclass="comment">// after the pivotings.</span></div>
<divclass="line"><aid="l00330"name="l00330"></a><spanclass="lineno"> 330</span><spanclass="comment">// Dictionaries are the modern way of presenting the result of an iteration</span></div>
<divclass="line"><aid="l00331"name="l00331"></a><spanclass="lineno"> 331</span><spanclass="comment">// of the Simplex algorithm in the literature.</span></div>
<divclass="line"><aid="l00334"name="l00334"></a><spanclass="lineno"> 334</span><spanclass="comment">// Displays the Linear Programming problem as it was input.</span></div>
<divclass="line"><aid="l00337"name="l00337"></a><spanclass="lineno"> 337</span><spanclass="comment">// Returns the current objective value. This is just the sum of the current</span></div>
<divclass="line"><aid="l00338"name="l00338"></a><spanclass="lineno"> 338</span><spanclass="comment">// variable values times their current cost.</span></div>
<divclass="line"><aid="l00341"name="l00341"></a><spanclass="lineno"> 341</span><spanclass="comment">// Returns the current objective of the linear program given to Solve() using</span></div>
<divclass="line"><aid="l00342"name="l00342"></a><spanclass="lineno"> 342</span><spanclass="comment">// the initial costs, maximization direction, objective offset and objective</span></div>
<divclass="line"><aid="l00346"name="l00346"></a><spanclass="lineno"> 346</span><spanclass="comment">// Assigns names to variables. Variables in the input will be named</span></div>
<divclass="line"><aid="l00347"name="l00347"></a><spanclass="lineno"> 347</span><spanclass="comment">// x1..., slack variables will be s1... .</span></div>
<divclass="line"><aid="l00350"name="l00350"></a><spanclass="lineno"> 350</span><spanclass="comment">// Sets the variable status and derives the variable value according to the</span></div>
<divclass="line"><aid="l00351"name="l00351"></a><spanclass="lineno"> 351</span><spanclass="comment">// exact status definition. This can only be called for non-basic variables</span></div>
<divclass="line"><aid="l00352"name="l00352"></a><spanclass="lineno"> 352</span><spanclass="comment">// because the value of a basic variable is computed from the values of the</span></div>
<divclass="line"><aid="l00357"name="l00357"></a><spanclass="lineno"> 357</span><spanclass="comment">// Checks if the basis_ and is_basic_ arrays are well formed. Also checks that</span></div>
<divclass="line"><aid="l00358"name="l00358"></a><spanclass="lineno"> 358</span><spanclass="comment">// the variable statuses are consistent with this basis. Returns true if this</span></div>
<divclass="line"><aid="l00359"name="l00359"></a><spanclass="lineno"> 359</span><spanclass="comment">// is the case. This is meant to be used in debug mode only.</span></div>
<divclass="line"><aid="l00362"name="l00362"></a><spanclass="lineno"> 362</span><spanclass="comment">// Moves the column entering_col into the basis at position basis_row. Removes</span></div>
<divclass="line"><aid="l00363"name="l00363"></a><spanclass="lineno"> 363</span><spanclass="comment">// the current basis column at position basis_row from the basis and sets its</span></div>
<divclass="line"><aid="l00364"name="l00364"></a><spanclass="lineno"> 364</span><spanclass="comment">// status to leaving_variable_status.</span></div>
<divclass="line"><aid="l00368"name="l00368"></a><spanclass="lineno"> 368</span><spanclass="comment">// Initializes matrix-related internal data. Returns true if this data was</span></div>
<divclass="line"><aid="l00369"name="l00369"></a><spanclass="lineno"> 369</span><spanclass="comment">// unchanged. If not, also sets only_change_is_new_rows to true if compared</span></div>
<divclass="line"><aid="l00370"name="l00370"></a><spanclass="lineno"> 370</span><spanclass="comment">// to the current matrix, the only difference is that new rows have been</span></div>
<divclass="line"><aid="l00371"name="l00371"></a><spanclass="lineno"> 371</span><spanclass="comment">// added (with their corresponding extra slack variables). Similarly, sets</span></div>
<divclass="line"><aid="l00372"name="l00372"></a><spanclass="lineno"> 372</span><spanclass="comment">// only_change_is_new_cols to true if the only difference is that new columns</span></div>
<divclass="line"><aid="l00373"name="l00373"></a><spanclass="lineno"> 373</span><spanclass="comment">// have been added, in which case also sets num_new_cols to the number of</span></div>
<divclass="line"><aid="l00374"name="l00374"></a><spanclass="lineno"> 374</span><spanclass="comment">// new columns.</span></div>
<divclass="line"><aid="l00381"name="l00381"></a><spanclass="lineno"> 381</span><spanclass="comment">// Checks if the only change to the bounds is the addition of new columns,</span></div>
<divclass="line"><aid="l00382"name="l00382"></a><spanclass="lineno"> 382</span><spanclass="comment">// and that the new columns have at least one bound equal to zero.</span></div>
<divclass="line"><aid="l00390"name="l00390"></a><spanclass="lineno"> 390</span><spanclass="comment">// Computes the stopping criterion on the problem objective value.</span></div>
<divclass="line"><aid="l00393"name="l00393"></a><spanclass="lineno"> 393</span><spanclass="comment">// Initializes the starting basis. In most cases it starts by the all slack</span></div>
<divclass="line"><aid="l00394"name="l00394"></a><spanclass="lineno"> 394</span><spanclass="comment">// basis and tries to apply some heuristics to replace fixed variables.</span></div>
<divclass="line"><aid="l00395"name="l00395"></a><spanclass="lineno"> 395</span> ABSL_MUST_USE_RESULT Status CreateInitialBasis();</div>
<divclass="line"><aid="l00397"name="l00397"></a><spanclass="lineno"> 397</span><spanclass="comment">// Sets the initial basis to the given columns, try to factorize it and</span></div>
<divclass="line"><aid="l00398"name="l00398"></a><spanclass="lineno"> 398</span><spanclass="comment">// recompute the basic variable values.</span></div>
<divclass="line"><aid="l00402"name="l00402"></a><spanclass="lineno"> 402</span><spanclass="comment">// Entry point for the solver initialization.</span></div>
<divclass="line"><aid="l00403"name="l00403"></a><spanclass="lineno"> 403</span> ABSL_MUST_USE_RESULT Status Initialize(<spanclass="keyword">const</span> LinearProgram& lp);</div>
<divclass="line"><aid="l00405"name="l00405"></a><spanclass="lineno"> 405</span><spanclass="comment">// Saves the current variable statuses in solution_state_.</span></div>
<divclass="line"><aid="l00408"name="l00408"></a><spanclass="lineno"> 408</span><spanclass="comment">// Displays statistics on what kinds of variables are in the current basis.</span></div>
<divclass="line"><aid="l00411"name="l00411"></a><spanclass="lineno"> 411</span><spanclass="comment">// Tries to reduce the initial infeasibility (stored in error_) by using the</span></div>
<divclass="line"><aid="l00412"name="l00412"></a><spanclass="lineno"> 412</span><spanclass="comment">// singleton columns present in the problem. A singleton column is a column</span></div>
<divclass="line"><aid="l00413"name="l00413"></a><spanclass="lineno"> 413</span><spanclass="comment">// with only one non-zero. This is used by CreateInitialBasis().</span></div>
<divclass="line"><aid="l00416"name="l00416"></a><spanclass="lineno"> 416</span><spanclass="comment">// Returns the number of empty rows in the matrix, i.e. rows where all</span></div>
<divclass="line"><aid="l00417"name="l00417"></a><spanclass="lineno"> 417</span><spanclass="comment">// the coefficients are zero.</span></div>
<divclass="line"><aid="l00420"name="l00420"></a><spanclass="lineno"> 420</span><spanclass="comment">// Returns the number of empty columns in the matrix, i.e. columns where all</span></div>
<divclass="line"><aid="l00421"name="l00421"></a><spanclass="lineno"> 421</span><spanclass="comment">// the coefficients are zero.</span></div>
<divclass="line"><aid="l00424"name="l00424"></a><spanclass="lineno"> 424</span><spanclass="comment">// Returns the number of super-basic variables. These are non-basic variables</span></div>
<divclass="line"><aid="l00425"name="l00425"></a><spanclass="lineno"> 425</span><spanclass="comment">// that are not at their bounds (if they have bounds), or non-basic free</span></div>
<divclass="line"><aid="l00426"name="l00426"></a><spanclass="lineno"> 426</span><spanclass="comment">// variables that are not at zero.</span></div>
<divclass="line"><aid="l00429"name="l00429"></a><spanclass="lineno"> 429</span><spanclass="comment">// This method transforms a basis for the first phase, with the optimal</span></div>
<divclass="line"><aid="l00430"name="l00430"></a><spanclass="lineno"> 430</span><spanclass="comment">// value at zero, into a feasible basis for the initial problem, thus</span></div>
<divclass="line"><aid="l00431"name="l00431"></a><spanclass="lineno"> 431</span><spanclass="comment">// preparing the execution of phase-II of the algorithm.</span></div>
<divclass="line"><aid="l00434"name="l00434"></a><spanclass="lineno"> 434</span><spanclass="comment">// If the primal maximum residual is too large, recomputes the basic variable</span></div>
<divclass="line"><aid="l00435"name="l00435"></a><spanclass="lineno"> 435</span><spanclass="comment">// value from the non-basic ones. This function also perturbs the bounds</span></div>
<divclass="line"><aid="l00436"name="l00436"></a><spanclass="lineno"> 436</span><spanclass="comment">// during the primal simplex if too many iterations are degenerate.</span></div>
<divclass="line"><aid="l00438"name="l00438"></a><spanclass="lineno"> 438</span><spanclass="comment">// Only call this on a refactorized basis to have the best precision.</span></div>
<divclass="line"><aid="l00444"name="l00444"></a><spanclass="lineno"> 444</span><spanclass="comment">// Solves the system B.d = a where a is the entering column (given by col).</span></div>
<divclass="line"><aid="l00445"name="l00445"></a><spanclass="lineno"> 445</span><spanclass="comment">// Known as FTRAN (Forward transformation) in FORTRAN codes.</span></div>
<divclass="line"><aid="l00446"name="l00446"></a><spanclass="lineno"> 446</span><spanclass="comment">// See Chvatal's book for more detail (Chapter 7).</span></div>
<divclass="line"><aid="l00449"name="l00449"></a><spanclass="lineno"> 449</span><spanclass="comment">// Computes a - B.d in error_ and return the maximum std::abs() of its coeffs.</span></div>
<divclass="line"><aid="l00452"name="l00452"></a><spanclass="lineno"> 452</span><spanclass="comment">// Computes the ratio of the basic variable corresponding to 'row'. A target</span></div>
<divclass="line"><aid="l00453"name="l00453"></a><spanclass="lineno"> 453</span><spanclass="comment">// bound (upper or lower) is chosen depending on the sign of the entering</span></div>
<divclass="line"><aid="l00454"name="l00454"></a><spanclass="lineno"> 454</span><spanclass="comment">// reduced cost and the sign of the direction 'd_[row]'. The ratio is such</span></div>
<divclass="line"><aid="l00455"name="l00455"></a><spanclass="lineno"> 455</span><spanclass="comment">// that adding 'ratio * d_[row]' to the variable value changes it to its</span></div>
<divclass="line"><aid="l00461"name="l00461"></a><spanclass="lineno"> 461</span><spanclass="comment">// First pass of the Harris ratio test. Returns the harris ratio value which</span></div>
<divclass="line"><aid="l00462"name="l00462"></a><spanclass="lineno"> 462</span><spanclass="comment">// is an upper bound on the ratio value that the leaving variable can take.</span></div>
<divclass="line"><aid="l00463"name="l00463"></a><spanclass="lineno"> 463</span><spanclass="comment">// Fills leaving_candidates with the ratio and row index of a super-set of the</span></div>
<divclass="line"><aid="l00464"name="l00464"></a><spanclass="lineno"> 464</span><spanclass="comment">// columns with a ratio <= harris_ratio.</span></div>
<divclass="line"><aid="l00469"name="l00469"></a><spanclass="lineno"> 469</span><spanclass="comment">// Chooses the leaving variable, considering the entering column and its</span></div>
<divclass="line"><aid="l00470"name="l00470"></a><spanclass="lineno"> 470</span><spanclass="comment">// associated reduced cost. If there was a precision issue and the basis is</span></div>
<divclass="line"><aid="l00471"name="l00471"></a><spanclass="lineno"> 471</span><spanclass="comment">// not refactorized, set refactorize to true. Otherwise, the row number of the</span></div>
<divclass="line"><aid="l00472"name="l00472"></a><spanclass="lineno"> 472</span><spanclass="comment">// leaving variable is written in *leaving_row, and the step length</span></div>
<divclass="line"><aid="l00473"name="l00473"></a><spanclass="lineno"> 473</span><spanclass="comment">// is written in *step_length.</span></div>
<divclass="line"><aid="l00474"name="l00474"></a><spanclass="lineno"> 474</span> Status ChooseLeavingVariableRow(ColIndex entering_col,</div>
<divclass="line"><aid="l00480"name="l00480"></a><spanclass="lineno"> 480</span><spanclass="comment">// Chooses the leaving variable for the primal phase-I algorithm. The</span></div>
<divclass="line"><aid="l00481"name="l00481"></a><spanclass="lineno"> 481</span><spanclass="comment">// algorithm follows more or less what is described in Istvan Maros's book in</span></div>
<divclass="line"><aid="l00482"name="l00482"></a><spanclass="lineno"> 482</span><spanclass="comment">// chapter 9.6 and what is done for the dual phase-I algorithm which was</span></div>
<divclass="line"><aid="l00483"name="l00483"></a><spanclass="lineno"> 483</span><spanclass="comment">// derived from Koberstein's PhD. Both references can be found at the top of</span></div>
<divclass="line"><aid="l00484"name="l00484"></a><spanclass="lineno"> 484</span><spanclass="comment">// this file.</span></div>
<divclass="line"><aid="l00492"name="l00492"></a><spanclass="lineno"> 492</span><spanclass="comment">// Chooses an infeasible basic variable. The returned values are:</span></div>
<divclass="line"><aid="l00493"name="l00493"></a><spanclass="lineno"> 493</span><spanclass="comment">// - leaving_row: the basic index of the infeasible leaving variable</span></div>
<divclass="line"><aid="l00494"name="l00494"></a><spanclass="lineno"> 494</span><spanclass="comment">// or kNoLeavingVariable if no such row exists: the dual simplex algorithm</span></div>
<divclass="line"><aid="l00495"name="l00495"></a><spanclass="lineno"> 495</span><spanclass="comment">// has terminated and the optimal has been reached.</span></div>
<divclass="line"><aid="l00496"name="l00496"></a><spanclass="lineno"> 496</span><spanclass="comment">// - cost_variation: how much do we improve the objective by moving one unit</span></div>
<divclass="line"><aid="l00497"name="l00497"></a><spanclass="lineno"> 497</span><spanclass="comment">// along this dual edge.</span></div>
<divclass="line"><aid="l00498"name="l00498"></a><spanclass="lineno"> 498</span><spanclass="comment">// - target_bound: the bound at which the leaving variable should go when</span></div>
<divclass="line"><aid="l00499"name="l00499"></a><spanclass="lineno"> 499</span><spanclass="comment">// leaving the basis.</span></div>
<divclass="line"><aid="l00500"name="l00500"></a><spanclass="lineno"> 500</span> ABSL_MUST_USE_RESULT Status DualChooseLeavingVariableRow(</div>
<divclass="line"><aid="l00504"name="l00504"></a><spanclass="lineno"> 504</span><spanclass="comment">// Updates the prices used by DualChooseLeavingVariableRow() after a simplex</span></div>
<divclass="line"><aid="l00505"name="l00505"></a><spanclass="lineno"> 505</span><spanclass="comment">// iteration by using direction_. The prices are stored in</span></div>
<divclass="line"><aid="l00506"name="l00506"></a><spanclass="lineno"> 506</span><spanclass="comment">// dual_pricing_vector_. Note that this function only takes care of the</span></div>
<divclass="line"><aid="l00507"name="l00507"></a><spanclass="lineno"> 507</span><spanclass="comment">// entering and leaving column dual feasibility status change and that other</span></div>
<divclass="line"><aid="l00508"name="l00508"></a><spanclass="lineno"> 508</span><spanclass="comment">// changes will be dealt with by DualPhaseIUpdatePriceOnReducedCostsChange().</span></div>
<divclass="line"><aid="l00511"name="l00511"></a><spanclass="lineno"> 511</span><spanclass="comment">// This must be called each time the dual_pricing_vector_ is changed at</span></div>
<divclass="line"><aid="l00512"name="l00512"></a><spanclass="lineno"> 512</span><spanclass="comment">// position row.</span></div>
<divclass="line"><aid="l00517"name="l00517"></a><spanclass="lineno"> 517</span><spanclass="comment">// Updates the prices used by DualChooseLeavingVariableRow() when the reduced</span></div>
<divclass="line"><aid="l00518"name="l00518"></a><spanclass="lineno"> 518</span><spanclass="comment">// costs of the given columns have changed.</span></div>
<divclass="line"><aid="l00522"name="l00522"></a><spanclass="lineno"> 522</span><spanclass="comment">// Same as DualChooseLeavingVariableRow() but for the phase I of the dual</span></div>
<divclass="line"><aid="l00523"name="l00523"></a><spanclass="lineno"> 523</span><spanclass="comment">// simplex. Here the objective is not to minimize the primal infeasibility,</span></div>
<divclass="line"><aid="l00524"name="l00524"></a><spanclass="lineno"> 524</span><spanclass="comment">// but the dual one, so the variable is not chosen in the same way. See</span></div>
<divclass="line"><aid="l00525"name="l00525"></a><spanclass="lineno"> 525</span><spanclass="comment">// "Notes on the Dual simplex Method" or Istvan Maros, "A Piecewise Linear</span></div>
<divclass="line"><aid="l00526"name="l00526"></a><spanclass="lineno"> 526</span><spanclass="comment">// Dual Phase-1 Algorithm for the Simplex Method", Computational Optimization</span></div>
<divclass="line"><aid="l00527"name="l00527"></a><spanclass="lineno"> 527</span><spanclass="comment">// and Applications, October 2003, Volume 26, Issue 1, pp 63-81.</span></div>
<divclass="line"><aid="l00533"name="l00533"></a><spanclass="lineno"> 533</span><spanclass="comment">// Makes sure the boxed variable are dual-feasible by setting them to the</span></div>
<divclass="line"><aid="l00534"name="l00534"></a><spanclass="lineno"> 534</span><spanclass="comment">// correct bound according to their reduced costs. This is called</span></div>
<divclass="line"><aid="l00535"name="l00535"></a><spanclass="lineno"> 535</span><spanclass="comment">// Dual feasibility correction in the literature.</span></div>
<divclass="line"><aid="l00537"name="l00537"></a><spanclass="lineno"> 537</span><spanclass="comment">// Note that this function is also used as a part of the bound flipping ratio</span></div>
<divclass="line"><aid="l00538"name="l00538"></a><spanclass="lineno"> 538</span><spanclass="comment">// test by flipping the boxed dual-infeasible variables at each iteration.</span></div>
<divclass="line"><aid="l00540"name="l00540"></a><spanclass="lineno"> 540</span><spanclass="comment">// If update_basic_values is true, the basic variable values are updated.</span></div>
<divclass="line"><aid="l00545"name="l00545"></a><spanclass="lineno"> 545</span><spanclass="comment">// Computes the step needed to move the leaving_row basic variable to the</span></div>
<divclass="line"><aid="l00546"name="l00546"></a><spanclass="lineno"> 546</span><spanclass="comment">// given target bound.</span></div>
<divclass="line"><aid="l00550"name="l00550"></a><spanclass="lineno"> 550</span><spanclass="comment">// Returns true if the basis obtained after the given pivot can be factorized.</span></div>
<divclass="line"><aid="l00553"name="l00553"></a><spanclass="lineno"> 553</span><spanclass="comment">// Gets the current LU column permutation from basis_representation,</span></div>
<divclass="line"><aid="l00554"name="l00554"></a><spanclass="lineno"> 554</span><spanclass="comment">// applies it to basis_ and then sets it to the identity permutation since</span></div>
<divclass="line"><aid="l00555"name="l00555"></a><spanclass="lineno"> 555</span><spanclass="comment">// it will no longer be needed during solves. This function also updates all</span></div>
<divclass="line"><aid="l00556"name="l00556"></a><spanclass="lineno"> 556</span><spanclass="comment">// the data that depends on the column order in basis_.</span></div>
<divclass="line"><aid="l00559"name="l00559"></a><spanclass="lineno"> 559</span><spanclass="comment">// Updates the system state according to the given basis pivot.</span></div>
<divclass="line"><aid="l00560"name="l00560"></a><spanclass="lineno"> 560</span><spanclass="comment">// Returns an error if the update could not be done because of some precision</span></div>
<divclass="line"><aid="l00566"name="l00566"></a><spanclass="lineno"> 566</span><spanclass="comment">// Displays all the timing stats related to the calling object.</span></div>
<divclass="line"><aid="l00569"name="l00569"></a><spanclass="lineno"> 569</span><spanclass="comment">// Calls basis_factorization_.Refactorize() if refactorize is true, and</span></div>
<divclass="line"><aid="l00570"name="l00570"></a><spanclass="lineno"> 570</span><spanclass="comment">// returns its status. This also sets refactorize to false and invalidates any</span></div>
<divclass="line"><aid="l00571"name="l00571"></a><spanclass="lineno"> 571</span><spanclass="comment">// data structure that depends on the current factorization.</span></div>
<divclass="line"><aid="l00573"name="l00573"></a><spanclass="lineno"> 573</span><spanclass="comment">// The general idea is that if a refactorization is going to be needed during</span></div>
<divclass="line"><aid="l00574"name="l00574"></a><spanclass="lineno"> 574</span><spanclass="comment">// a simplex iteration, it is better to do it as soon as possible so that</span></div>
<divclass="line"><aid="l00575"name="l00575"></a><spanclass="lineno"> 575</span><spanclass="comment">// every component can take advantage of it.</span></div>
<divclass="line"><aid="l00576"name="l00576"></a><spanclass="lineno"> 576</span> Status RefactorizeBasisIfNeeded(<spanclass="keywordtype">bool</span>* refactorize);</div>
<divclass="line"><aid="l00578"name="l00578"></a><spanclass="lineno"> 578</span><spanclass="comment">// Main iteration loop of the primal simplex.</span></div>
<divclass="line"><aid="l00579"name="l00579"></a><spanclass="lineno"> 579</span> ABSL_MUST_USE_RESULT Status PrimalMinimize(TimeLimit* <aclass="code hl_variable"href="cp__model__solver_8cc.html#aec8af5c1be4e1b6d4330e1161028de21">time_limit</a>);</div>
<divclass="line"><aid="l00581"name="l00581"></a><spanclass="lineno"> 581</span><spanclass="comment">// Main iteration loop of the dual simplex.</span></div>
<divclass="line"><aid="l00582"name="l00582"></a><spanclass="lineno"> 582</span> ABSL_MUST_USE_RESULT Status DualMinimize(<spanclass="keywordtype">bool</span> feasibility_phase,</div>
<divclass="line"><aid="l00585"name="l00585"></a><spanclass="lineno"> 585</span><spanclass="comment">// Pushes all super-basic variables to bounds (if applicable) or to zero (if</span></div>
<divclass="line"><aid="l00586"name="l00586"></a><spanclass="lineno"> 586</span><spanclass="comment">// unconstrained). This is part of a "crossover" procedure to find a vertex</span></div>
<divclass="line"><aid="l00587"name="l00587"></a><spanclass="lineno"> 587</span><spanclass="comment">// solution given a (near) optimal solution. Assumes that Minimize() or</span></div>
<divclass="line"><aid="l00588"name="l00588"></a><spanclass="lineno"> 588</span><spanclass="comment">// DualMinimize() has already run, i.e., that we are at an optimal solution</span></div>
<divclass="line"><aid="l00589"name="l00589"></a><spanclass="lineno"> 589</span><spanclass="comment">// within numerical tolerances.</span></div>
<divclass="line"><aid="l00590"name="l00590"></a><spanclass="lineno"> 590</span> ABSL_MUST_USE_RESULT Status PrimalPush(TimeLimit* <aclass="code hl_variable"href="cp__model__solver_8cc.html#aec8af5c1be4e1b6d4330e1161028de21">time_limit</a>);</div>
<divclass="line"><aid="l00592"name="l00592"></a><spanclass="lineno"> 592</span><spanclass="comment">// Experimental. This is useful in a MIP context. It performs a few degenerate</span></div>
<divclass="line"><aid="l00593"name="l00593"></a><spanclass="lineno"> 593</span><spanclass="comment">// pivot to try to mimize the fractionality of the optimal basis.</span></div>
<divclass="line"><aid="l00595"name="l00595"></a><spanclass="lineno"> 595</span><spanclass="comment">// We assume that the columns for which SetIntegralityScale() has been called</span></div>
<divclass="line"><aid="l00596"name="l00596"></a><spanclass="lineno"> 596</span><spanclass="comment">// correspond to integral variable once scaled by the given factor.</span></div>
<divclass="line"><aid="l00598"name="l00598"></a><spanclass="lineno"> 598</span><spanclass="comment">// I could only find slides for the reference of this "LP Solution Polishing</span></div>
<divclass="line"><aid="l00599"name="l00599"></a><spanclass="lineno"> 599</span><spanclass="comment">// to improve MIP Performance", Matthias Miltenberger, Zuse Institute Berlin.</span></div>
<divclass="line"><aid="l00600"name="l00600"></a><spanclass="lineno"> 600</span> ABSL_MUST_USE_RESULT Status Polish(TimeLimit* <aclass="code hl_variable"href="cp__model__solver_8cc.html#aec8af5c1be4e1b6d4330e1161028de21">time_limit</a>);</div>
<divclass="line"><aid="l00602"name="l00602"></a><spanclass="lineno"> 602</span><spanclass="comment">// Utility functions to return the current ColIndex of the slack column with</span></div>
<divclass="line"><aid="l00603"name="l00603"></a><spanclass="lineno"> 603</span><spanclass="comment">// given number. Note that currently, such columns are always present in the</span></div>
<divclass="line"><aid="l00604"name="l00604"></a><spanclass="lineno"> 604</span><spanclass="comment">// internal representation of a linear program.</span></div>
<divclass="line"><aid="l00607"name="l00607"></a><spanclass="lineno"> 607</span><spanclass="comment">// Advances the deterministic time in time_limit with the difference between</span></div>
<divclass="line"><aid="l00608"name="l00608"></a><spanclass="lineno"> 608</span><spanclass="comment">// the current internal deterministic time and the internal deterministic time</span></div>
<divclass="line"><aid="l00609"name="l00609"></a><spanclass="lineno"> 609</span><spanclass="comment">// during the last call to this method.</span></div>
<divclass="line"><aid="l00610"name="l00610"></a><spanclass="lineno"> 610</span><spanclass="comment">// TODO(user): Update the internals of revised simplex so that the time</span></div>
<divclass="line"><aid="l00611"name="l00611"></a><spanclass="lineno"> 611</span><spanclass="comment">// limit is updated at the source and remove this method.</span></div>
<divclass="line"><aid="l00617"name="l00617"></a><spanclass="lineno"> 617</span><spanclass="comment">// Current number of rows in the problem.</span></div>
<divclass="line"><aid="l00620"name="l00620"></a><spanclass="lineno"> 620</span><spanclass="comment">// Current number of columns in the problem.</span></div>
<divclass="line"><aid="l00623"name="l00623"></a><spanclass="lineno"> 623</span><spanclass="comment">// Index of the first slack variable in the input problem. We assume that all</span></div>
<divclass="line"><aid="l00624"name="l00624"></a><spanclass="lineno"> 624</span><spanclass="comment">// variables with index greater or equal to first_slack_col_ are slack</span></div>
<divclass="line"><aid="l00628"name="l00628"></a><spanclass="lineno"> 628</span><spanclass="comment">// We're using vectors after profiling and looking at the generated assembly</span></div>
<divclass="line"><aid="l00629"name="l00629"></a><spanclass="lineno"> 629</span><spanclass="comment">// it's as fast as std::unique_ptr as long as the size is properly reserved</span></div>
<divclass="line"><aid="l00632"name="l00632"></a><spanclass="lineno"> 632</span><spanclass="comment">// Compact version of the matrix given to Solve().</span></div>
<divclass="line"><aid="l00635"name="l00635"></a><spanclass="lineno"> 635</span><spanclass="comment">// The transpose of compact_matrix_, it may be empty if it is not needed.</span></div>
<divclass="line"><aid="l00638"name="l00638"></a><spanclass="lineno"> 638</span><spanclass="comment">// Stop the algorithm and report feasibility if:</span></div>
<divclass="line"><aid="l00639"name="l00639"></a><spanclass="lineno"> 639</span><spanclass="comment">// - The primal simplex is used, the problem is primal-feasible and the</span></div>
<divclass="line"><aid="l00640"name="l00640"></a><spanclass="lineno"> 640</span><spanclass="comment">// current objective value is strictly lower than primal_objective_limit_.</span></div>
<divclass="line"><aid="l00641"name="l00641"></a><spanclass="lineno"> 641</span><spanclass="comment">// - The dual simplex is used, the problem is dual-feasible and the current</span></div>
<divclass="line"><aid="l00642"name="l00642"></a><spanclass="lineno"> 642</span><spanclass="comment">// objective value is strictly greater than dual_objective_limit_.</span></div>
<divclass="line"><aid="l00646"name="l00646"></a><spanclass="lineno"> 646</span><spanclass="comment">// Current objective (feasibility for Phase-I, user-provided for Phase-II).</span></div>
<divclass="line"><aid="l00649"name="l00649"></a><spanclass="lineno"> 649</span><spanclass="comment">// Array of coefficients for the user-defined objective.</span></div>
<divclass="line"><aid="l00650"name="l00650"></a><spanclass="lineno"> 650</span><spanclass="comment">// Indexed by column number. Used in Phase-II.</span></div>
<divclass="line"><aid="l00653"name="l00653"></a><spanclass="lineno"> 653</span><spanclass="comment">// Objective offset and scaling factor of the linear program given to Solve().</span></div>
<divclass="line"><aid="l00654"name="l00654"></a><spanclass="lineno"> 654</span><spanclass="comment">// This is used to display the correct objective values in the logs with</span></div>
<divclass="line"><aid="l00659"name="l00659"></a><spanclass="lineno"> 659</span><spanclass="comment">// Used in dual phase I to keep track of the non-basic dual infeasible</span></div>
<divclass="line"><aid="l00660"name="l00660"></a><spanclass="lineno"> 660</span><spanclass="comment">// columns and their sign of infeasibility (+1 or -1).</span></div>
<divclass="line"><aid="l00664"name="l00664"></a><spanclass="lineno"> 664</span><spanclass="comment">// A temporary scattered column that is always reset to all zero after use.</span></div>
<divclass="line"><aid="l00667"name="l00667"></a><spanclass="lineno"> 667</span><spanclass="comment">// Array of column index, giving the column number corresponding</span></div>
<divclass="line"><aid="l00668"name="l00668"></a><spanclass="lineno"> 668</span><spanclass="comment">// to a given basis row.</span></div>
<divclass="line"><aid="l00671"name="l00671"></a><spanclass="lineno"> 671</span><spanclass="comment">// Vector of strings containing the names of variables.</span></div>
<divclass="line"><aid="l00672"name="l00672"></a><spanclass="lineno"> 672</span><spanclass="comment">// Indexed by column number.</span></div>
<divclass="line"><aid="l00675"name="l00675"></a><spanclass="lineno"> 675</span><spanclass="comment">// Information about the solution computed by the last Solve().</span></div>
<divclass="line"><aid="l00685"name="l00685"></a><spanclass="lineno"> 685</span><spanclass="comment">// If this is cleared, we assume they are none.</span></div>
<divclass="line"><aid="l00688"name="l00688"></a><spanclass="lineno"> 688</span><spanclass="comment">// Flag used by NotifyThatMatrixIsUnchangedForNextSolve() and changing</span></div>
<divclass="line"><aid="l00689"name="l00689"></a><spanclass="lineno"> 689</span><spanclass="comment">// the behavior of Initialize().</span></div>
<divclass="line"><aid="l00692"name="l00692"></a><spanclass="lineno"> 692</span><spanclass="comment">// This is known as 'd' in the literature and is set during each pivot to the</span></div>
<divclass="line"><aid="l00693"name="l00693"></a><spanclass="lineno"> 693</span><spanclass="comment">// right inverse of the basic entering column of A by ComputeDirection().</span></div>
<divclass="line"><aid="l00694"name="l00694"></a><spanclass="lineno"> 694</span><spanclass="comment">// ComputeDirection() also fills direction_.non_zeros with the position of the</span></div>
<divclass="line"><aid="l00699"name="l00699"></a><spanclass="lineno"> 699</span><spanclass="comment">// Used to compute the error 'b - A.x' or 'a - B.d'.</span></div>
<divclass="line"><aid="l00702"name="l00702"></a><spanclass="lineno"> 702</span><spanclass="comment">// A random number generator. In test we use absl_random_ to have a</span></div>
<divclass="line"><aid="l00703"name="l00703"></a><spanclass="lineno"> 703</span><spanclass="comment">// non-deterministic behavior and avoid client depending on a golden optimal</span></div>
<divclass="line"><aid="l00704"name="l00704"></a><spanclass="lineno"> 704</span><spanclass="comment">// solution which prevent us from easily changing the solver.</span></div>
<divclass="line"><aid="l00711"name="l00711"></a><spanclass="lineno"> 711</span><spanclass="comment">// Helpers for logging the solve progress.</span></div>
<divclass="line"><aid="l00715"name="l00715"></a><spanclass="lineno"> 715</span><spanclass="comment">// Representation of matrix B using eta matrices and LU decomposition.</span></div>
<divclass="line"><aid="l00718"name="l00718"></a><spanclass="lineno"> 718</span><spanclass="comment">// Classes responsible for maintaining the data of the corresponding names.</span></div>
<divclass="line"><aid="l00729"name="l00729"></a><spanclass="lineno"> 729</span><spanclass="comment">// Used in dual phase I to hold the price of each possible leaving choices.</span></div>
<divclass="line"><aid="l00732"name="l00732"></a><spanclass="lineno"> 732</span><spanclass="comment">// Temporary memory used by DualMinimize().</span></div>
<divclass="line"><aid="l00735"name="l00735"></a><spanclass="lineno"> 735</span><spanclass="comment">// Total number of iterations performed.</span></div>
<divclass="line"><aid="l00738"name="l00738"></a><spanclass="lineno"> 738</span><spanclass="comment">// Number of iterations performed during the first (feasibility) phase.</span></div>
<divclass="line"><aid="l00741"name="l00741"></a><spanclass="lineno"> 741</span><spanclass="comment">// Number of iterations performed during the second (optimization) phase.</span></div>
<divclass="line"><aid="l00744"name="l00744"></a><spanclass="lineno"> 744</span><spanclass="comment">// Number of iterations performed during the push/crossover phase.</span></div>
<divclass="line"><aid="l00747"name="l00747"></a><spanclass="lineno"> 747</span><spanclass="comment">// Deterministic time for DualPhaseIUpdatePriceOnReducedCostChange().</span></div>
<divclass="line"><aid="l00753"name="l00753"></a><spanclass="lineno"> 753</span><spanclass="comment">// Time spent in the first (feasibility) phase.</span></div>
<divclass="line"><aid="l00756"name="l00756"></a><spanclass="lineno"> 756</span><spanclass="comment">// Time spent in the second (optimization) phase.</span></div>
<divclass="line"><aid="l00759"name="l00759"></a><spanclass="lineno"> 759</span><spanclass="comment">// Time spent in the push/crossover phase.</span></div>
<divclass="line"><aid="l00762"name="l00762"></a><spanclass="lineno"> 762</span><spanclass="comment">// The internal deterministic time during the most recent call to</span></div>
<divclass="line"><aid="l00766"name="l00766"></a><spanclass="lineno"> 766</span><spanclass="comment">// Statistics about the iterations done by PrimalMinimize().</span></div>
<divclass="line"><aid="l00771"name="l00771"></a><spanclass="lineno"> 771</span><spanclass="comment">// Placeholder for all the function timing stats.</span></div>
<divclass="line"><aid="l00772"name="l00772"></a><spanclass="lineno"> 772</span><spanclass="comment">// Mutable because we time const functions like ChooseLeavingVariableRow().</span></div>
<divclass="line"><aid="l00775"name="l00775"></a><spanclass="lineno"> 775</span><spanclass="comment">// Proto holding all the parameters of this algorithm.</span></div>
<divclass="line"><aid="l00777"name="l00777"></a><spanclass="lineno"> 777</span><spanclass="comment">// Note that parameters_ may actually change during a solve as the solver may</span></div>
<divclass="line"><aid="l00778"name="l00778"></a><spanclass="lineno"> 778</span><spanclass="comment">// dynamically adapt some values. It is why we store the argument of the last</span></div>
<divclass="line"><aid="l00779"name="l00779"></a><spanclass="lineno"> 779</span><spanclass="comment">// SetParameters() call in initial_parameters_ so the next Solve() can reset</span></div>
<divclass="line"><aid="l00780"name="l00780"></a><spanclass="lineno"> 780</span><spanclass="comment">// it correctly.</span></div>
<divclass="line"><aid="l00784"name="l00784"></a><spanclass="lineno"> 784</span><spanclass="comment">// LuFactorization used to test if a pivot will cause the new basis to</span></div>
<divclass="line"><aid="l00785"name="l00785"></a><spanclass="lineno"> 785</span><spanclass="comment">// not be factorizable.</span></div>
<divclass="line"><aid="l00788"name="l00788"></a><spanclass="lineno"> 788</span><spanclass="comment">// Number of degenerate iterations made just before the current iteration.</span></div>
<divclass="line"><aid="l00791"name="l00791"></a><spanclass="lineno"> 791</span><spanclass="comment">// Indicate the current phase of the solve.</span></div>
<divclass="line"><aid="l00794"name="l00794"></a><spanclass="lineno"> 794</span><spanclass="comment">// Indicates whether simplex ended due to the objective limit being reached.</span></div>
<divclass="line"><aid="l00795"name="l00795"></a><spanclass="lineno"> 795</span><spanclass="comment">// Note that it's not enough to compare the final objective value with the</span></div>
<divclass="line"><aid="l00796"name="l00796"></a><spanclass="lineno"> 796</span><spanclass="comment">// limit due to numerical issues (i.e., the limit which is reached within</span></div>
<divclass="line"><aid="l00797"name="l00797"></a><spanclass="lineno"> 797</span><spanclass="comment">// given tolerance on the internal objective may no longer be reached when the</span></div>
<divclass="line"><aid="l00798"name="l00798"></a><spanclass="lineno"> 798</span><spanclass="comment">// objective scaling and offset are taken into account).</span></div>
<divclass="line"><aid="l00801"name="l00801"></a><spanclass="lineno"> 801</span><spanclass="comment">// Temporary SparseColumn used by ChooseLeavingVariableRow().</span></div>
<divclass="line"><aid="l00804"name="l00804"></a><spanclass="lineno"> 804</span><spanclass="comment">// Temporary vector used to hold the best leaving column candidates that are</span></div>
<divclass="line"><aid="l00805"name="l00805"></a><spanclass="lineno"> 805</span><spanclass="comment">// tied using the current choosing criteria. We actually only store the tied</span></div>
<divclass="line"><aid="l00806"name="l00806"></a><spanclass="lineno"> 806</span><spanclass="comment">// candidate #2, #3, ...; because the first tied candidate is remembered</span></div>
<divclass="line"><aid="l00816"name="l00816"></a><spanclass="lineno"> 816</span><spanclass="comment">// Hides the details of the dictionary matrix implementation. In the future,</span></div>
<divclass="line"><aid="l00817"name="l00817"></a><spanclass="lineno"> 817</span><spanclass="comment">// GLOP will support generating the dictionary one row at a time without having</span></div>
<divclass="line"><aid="l00818"name="l00818"></a><spanclass="lineno"> 818</span><spanclass="comment">// to store the whole matrix in memory.</span></div>
<divclass="line"><aid="l00823"name="l00823"></a><spanclass="lineno"> 823</span><spanclass="comment">// RevisedSimplex cannot be passed const because we have to call a non-const</span></div>
<divclass="line"><aid="l00825"name="l00825"></a><spanclass="lineno"> 825</span><spanclass="comment">// TODO(user): Overload this to take RevisedSimplex* alone when the</span></div>
<divclass="line"><aid="l00826"name="l00826"></a><spanclass="lineno"> 826</span><spanclass="comment">// caller would normally pass a nullptr for col_scales so this and</span></div>
<divclass="line"><aid="l00827"name="l00827"></a><spanclass="lineno"> 827</span><spanclass="comment">// ComputeDictionary can take a const& argument.</span></div>
<divclass="line"><aid="l00839"name="l00839"></a><spanclass="lineno"> 839</span><spanclass="comment">// TODO(user): This function is a better fit for the future custom iterator.</span></div>
<divclass="line"><aid="l00849"name="l00849"></a><spanclass="lineno"> 849</span><spanclass="comment">// TODO(user): When a row-by-row generation of the dictionary is supported,</span></div>
<divclass="line"><aid="l00850"name="l00850"></a><spanclass="lineno"> 850</span><spanclass="comment">// implement DictionaryIterator class that would call it inside operator*().</span></div>
<divclass="ttc"id="aclassoperations__research_1_1_time_limit_html"><divclass="ttname"><ahref="classoperations__research_1_1_time_limit.html">operations_research::TimeLimit</a></div><divclass="ttdoc">A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...</div><divclass="ttdef"><b>Definition:</b><ahref="time__limit_8h_source.html#l00106">time_limit.h:106</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a01f64f8af66c6c5a66d3b4ebc868cab6"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a01f64f8af66c6c5a66d3b4ebc868cab6">operations_research::glop::RevisedSimplex::GetParameters</a></div><divclass="ttdeci">const GlopParameters & GetParameters() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8h_source.html#l00131">revised_simplex.h:131</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a0e35521f3d40e263173626ecc8c21b06"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a0e35521f3d40e263173626ecc8c21b06">operations_research::glop::RevisedSimplex::GetDualRayRowCombination</a></div><divclass="ttdeci">const DenseRow & GetDualRayRowCombination() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00663">revised_simplex.cc:663</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a26689abee13abb7fc0d0cf99c1c7809b"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a26689abee13abb7fc0d0cf99c1c7809b">operations_research::glop::RevisedSimplex::GetReducedCosts</a></div><divclass="ttdeci">const DenseRow & GetReducedCosts() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00621">revised_simplex.cc:621</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a3854b494976761a458a17523bb4fe5cf"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a3854b494976761a458a17523bb4fe5cf">operations_research::glop::RevisedSimplex::GetPrimalRay</a></div><divclass="ttdeci">const DenseRow & GetPrimalRay() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00654">revised_simplex.cc:654</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a66da73868da92948f57a83e261066ca6"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a66da73868da92948f57a83e261066ca6">operations_research::glop::RevisedSimplex::GetDualRay</a></div><divclass="ttdeci">const DenseColumn & GetDualRay() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00658">revised_simplex.cc:658</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a95e8c74f6630e598f7a9e8032479ab11"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a95e8c74f6630e598f7a9e8032479ab11">operations_research::glop::RevisedSimplex::GetUnitRowLeftInverse</a></div><divclass="ttdeci">const ScatteredRow & GetUnitRowLeftInverse(RowIndex row)</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8h_source.html#l00208">revised_simplex.h:208</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_ad463af979d0c220bb473d4f8df2ec345"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#ad463af979d0c220bb473d4f8df2ec345">operations_research::glop::RevisedSimplex::GetBasisFactorization</a></div><divclass="ttdeci">const BasisFactorization & GetBasisFactorization() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00670">revised_simplex.cc:670</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_adfbae19f81ecf38f67643dc8b7dcec25"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#adfbae19f81ecf38f67643dc8b7dcec25">operations_research::glop::RevisedSimplex::GetState</a></div><divclass="ttdeci">const BasisState & GetState() const</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00633">revised_simplex.cc:633</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_update_row_html_a2355c817cae2bbd316f28aea2e842761"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_update_row.html#a2355c817cae2bbd316f28aea2e842761">operations_research::glop::UpdateRow::ComputeAndGetUnitRowLeftInverse</a></div><divclass="ttdeci">const ScatteredRow & ComputeAndGetUnitRowLeftInverse(RowIndex leaving_row)</div><divclass="ttdef"><b>Definition:</b><ahref="update__row_8cc_source.html#l00049">update_row.cc:49</a></div></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>