<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="l00123"name="l00123"></a><spanclass="lineno"> 123</span><spanclass="comment">// Entry point of the revised simplex algorithm implementation.</span></div>
<divclass="line"><aid="l00128"name="l00128"></a><spanclass="lineno"> 128</span><spanclass="comment">// Sets or gets the algorithm parameters to be used on the next Solve().</span></div>
<divclass="line"><aid="l00134"name="l00134"></a><spanclass="lineno"> 134</span><spanclass="comment">// We accept two forms of LinearProgram:</span></div>
<divclass="line"><aid="l00135"name="l00135"></a><spanclass="lineno"> 135</span><spanclass="comment">// - The lp can be in the equations form Ax = 0 created by</span></div>
<divclass="line"><aid="l00136"name="l00136"></a><spanclass="lineno"> 136</span><spanclass="comment">// LinearProgram::AddSlackVariablesForAllRows(), i.e. the rightmost square</span></div>
<divclass="line"><aid="l00137"name="l00137"></a><spanclass="lineno"> 137</span><spanclass="comment">// submatrix of A is an identity matrix, all its columns have been marked as</span></div>
<divclass="line"><aid="l00138"name="l00138"></a><spanclass="lineno"> 138</span><spanclass="comment">// slack variables, and the bounds of all constraints have been set to 0.</span></div>
<divclass="line"><aid="l00139"name="l00139"></a><spanclass="lineno"> 139</span><spanclass="comment">// - If not, we will convert it internally while copying it to the internal</span></div>
<divclass="line"><aid="l00142"name="l00142"></a><spanclass="lineno"> 142</span><spanclass="comment">// By default, the algorithm tries to exploit the computation done during the</span></div>
<divclass="line"><aid="l00143"name="l00143"></a><spanclass="lineno"> 143</span><spanclass="comment">// last Solve() call. It will analyze the difference of the new linear program</span></div>
<divclass="line"><aid="l00144"name="l00144"></a><spanclass="lineno"> 144</span><spanclass="comment">// and try to use the previously computed solution as a warm-start. To disable</span></div>
<divclass="line"><aid="l00145"name="l00145"></a><spanclass="lineno"> 145</span><spanclass="comment">// this behavior or give explicit warm-start data, use one of the State*()</span></div>
<divclass="line"><aid="l00150"name="l00150"></a><spanclass="lineno"> 150</span><spanclass="comment">// Do not use the current solution as a warm-start for the next Solve(). The</span></div>
<divclass="line"><aid="l00151"name="l00151"></a><spanclass="lineno"> 151</span><spanclass="comment">// next Solve() will behave as if the class just got created.</span></div>
<divclass="line"><aid="l00154"name="l00154"></a><spanclass="lineno"> 154</span><spanclass="comment">// Uses the given state as a warm-start for the next Solve() call.</span></div>
<divclass="line"><aid="l00157"name="l00157"></a><spanclass="lineno"> 157</span><spanclass="comment">// Advanced usage. While constructing the initial basis, if this is called</span></div>
<divclass="line"><aid="l00158"name="l00158"></a><spanclass="lineno"> 158</span><spanclass="comment">// then we will use these values as the initial starting value for the FREE</span></div>
<divclass="line"><aid="l00162"name="l00162"></a><spanclass="lineno"> 162</span><spanclass="comment">// Advanced usage. Tells the next Solve() that the matrix inside the linear</span></div>
<divclass="line"><aid="l00163"name="l00163"></a><spanclass="lineno"> 163</span><spanclass="comment">// program will not change compared to the one used the last time Solve() was</span></div>
<divclass="line"><aid="l00164"name="l00164"></a><spanclass="lineno"> 164</span><spanclass="comment">// called. This allows to bypass the somewhat costly check of comparing both</span></div>
<divclass="line"><aid="l00165"name="l00165"></a><spanclass="lineno"> 165</span><spanclass="comment">// matrices. Note that this call will be ignored if Solve() was never called</span></div>
<divclass="line"><aid="l00166"name="l00166"></a><spanclass="lineno"> 166</span><spanclass="comment">// or if ClearStateForNextSolve() was called.</span></div>
<divclass="line"><aid="l00169"name="l00169"></a><spanclass="lineno"> 169</span><spanclass="comment">// Getters to retrieve all the information computed by the last Solve().</span></div>
<divclass="line"><aid="l00186"name="l00186"></a><spanclass="lineno"> 186</span><spanclass="comment">// If the problem status is PRIMAL_UNBOUNDED (respectively DUAL_UNBOUNDED),</span></div>
<divclass="line"><aid="l00187"name="l00187"></a><spanclass="lineno"> 187</span><spanclass="comment">// then the solver has a corresponding primal (respectively dual) ray to show</span></div>
<divclass="line"><aid="l00188"name="l00188"></a><spanclass="lineno"> 188</span><spanclass="comment">// the unboundness. From a primal (respectively dual) feasible solution any</span></div>
<divclass="line"><aid="l00189"name="l00189"></a><spanclass="lineno"> 189</span><spanclass="comment">// positive multiple of this ray can be added to the solution and keep it</span></div>
<divclass="line"><aid="l00190"name="l00190"></a><spanclass="lineno"> 190</span><spanclass="comment">// feasible. Moreover, by doing so, the objective of the problem will improve</span></div>
<divclass="line"><aid="l00191"name="l00191"></a><spanclass="lineno"> 191</span><spanclass="comment">// and its magnitude will go to infinity.</span></div>
<divclass="line"><aid="l00193"name="l00193"></a><spanclass="lineno"> 193</span><spanclass="comment">// Note that when the problem is DUAL_UNBOUNDED, the dual ray is also known as</span></div>
<divclass="line"><aid="l00194"name="l00194"></a><spanclass="lineno"> 194</span><spanclass="comment">// the Farkas proof of infeasibility of the problem.</span></div>
<divclass="line"><aid="l00198"name="l00198"></a><spanclass="lineno"> 198</span><spanclass="comment">// This is the "dual ray" linear combination of the matrix rows.</span></div>
<divclass="line"><aid="l00201"name="l00201"></a><spanclass="lineno"> 201</span><spanclass="comment">// Returns the index of the column in the basis and the basis factorization.</span></div>
<divclass="line"><aid="l00202"name="l00202"></a><spanclass="lineno"> 202</span><spanclass="comment">// Note that the order of the column in the basis is important since it is the</span></div>
<divclass="line"><aid="l00203"name="l00203"></a><spanclass="lineno"> 203</span><spanclass="comment">// one used by the various solve functions provided by the BasisFactorization</span></div>
<divclass="line"><aid="l00211"name="l00211"></a><spanclass="lineno"> 211</span><spanclass="comment">// Returns a copy of basis_ vector for outside applications (like cuts) to</span></div>
<divclass="line"><aid="l00212"name="l00212"></a><spanclass="lineno"> 212</span><spanclass="comment">// have the correspondence between rows and columns of the dictionary.</span></div>
<divclass="line"><aid="l00217"name="l00217"></a><spanclass="lineno"> 217</span><spanclass="comment">// Returns statistics about this class as a string.</span></div>
<divclass="line"><aid="l00220"name="l00220"></a><spanclass="lineno"> 220</span><spanclass="comment">// Computes the dictionary B^-1*N on-the-fly row by row. Returns the resulting</span></div>
<divclass="line"><aid="l00221"name="l00221"></a><spanclass="lineno"> 221</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="l00222"name="l00222"></a><spanclass="lineno"> 222</span><spanclass="comment">// side in the matrix multiplication. Runs in O(num_non_zeros_in_matrix).</span></div>
<divclass="line"><aid="l00223"name="l00223"></a><spanclass="lineno"> 223</span><spanclass="comment">// TODO(user): Use row scales as well.</span></div>
<divclass="line"><aid="l00226"name="l00226"></a><spanclass="lineno"> 226</span><spanclass="comment">// Initializes the matrix for the given 'linear_program' and 'state' and</span></div>
<divclass="line"><aid="l00227"name="l00227"></a><spanclass="lineno"> 227</span><spanclass="comment">// computes the variable values for basic variables using non-basic variables.</span></div>
<divclass="line"><aid="l00231"name="l00231"></a><spanclass="lineno"> 231</span><spanclass="comment">// This is used in a MIP context to polish the final basis. We assume that the</span></div>
<divclass="line"><aid="l00232"name="l00232"></a><spanclass="lineno"> 232</span><spanclass="comment">// columns for which SetIntegralityScale() has been called correspond to</span></div>
<divclass="line"><aid="l00233"name="l00233"></a><spanclass="lineno"> 233</span><spanclass="comment">// integral variable once multiplied by the given factor.</span></div>
<divclass="line"><aid="l00278"name="l00278"></a><spanclass="lineno"> 278</span><spanclass="comment">// Propagates parameters_ to all the other classes that need it.</span></div>
<divclass="line"><aid="l00280"name="l00280"></a><spanclass="lineno"> 280</span><spanclass="comment">// TODO(user): Maybe a better design is for them to have a reference to a</span></div>
<divclass="line"><aid="l00281"name="l00281"></a><spanclass="lineno"> 281</span><spanclass="comment">// unique parameters object? It will clutter a bit more these classes'</span></div>
<divclass="line"><aid="l00285"name="l00285"></a><spanclass="lineno"> 285</span><spanclass="comment">// Returns a string containing the same information as with GetSolverStats,</span></div>
<divclass="line"><aid="l00286"name="l00286"></a><spanclass="lineno"> 286</span><spanclass="comment">// but in a much more human-readable format. For example:</span></div>
<divclass="line"><aid="l00287"name="l00287"></a><spanclass="lineno"> 287</span><spanclass="comment">// Problem status : Optimal</span></div>
<divclass="line"><aid="l00288"name="l00288"></a><spanclass="lineno"> 288</span><spanclass="comment">// Solving time : 1.843</span></div>
<divclass="line"><aid="l00289"name="l00289"></a><spanclass="lineno"> 289</span><spanclass="comment">// Number of iterations : 12345</span></div>
<divclass="line"><aid="l00290"name="l00290"></a><spanclass="lineno"> 290</span><spanclass="comment">// Time for solvability (first phase) : 1.343</span></div>
<divclass="line"><aid="l00291"name="l00291"></a><spanclass="lineno"> 291</span><spanclass="comment">// Number of iterations for solvability : 10000</span></div>
<divclass="line"><aid="l00292"name="l00292"></a><spanclass="lineno"> 292</span><spanclass="comment">// Time for optimization : 0.5</span></div>
<divclass="line"><aid="l00293"name="l00293"></a><spanclass="lineno"> 293</span><spanclass="comment">// Number of iterations for optimization : 2345</span></div>
<divclass="line"><aid="l00294"name="l00294"></a><spanclass="lineno"> 294</span><spanclass="comment">// Maximum time allowed in seconds : 6000</span></div>
<divclass="line"><aid="l00295"name="l00295"></a><spanclass="lineno"> 295</span><spanclass="comment">// Maximum number of iterations : 1000000</span></div>
<divclass="line"><aid="l00296"name="l00296"></a><spanclass="lineno"> 296</span><spanclass="comment">// Stop after first basis : 0</span></div>
<divclass="line"><aid="l00299"name="l00299"></a><spanclass="lineno"> 299</span><spanclass="comment">// Returns a string containing formatted information about the variable</span></div>
<divclass="line"><aid="l00300"name="l00300"></a><spanclass="lineno"> 300</span><spanclass="comment">// corresponding to column col.</span></div>
<divclass="line"><aid="l00303"name="l00303"></a><spanclass="lineno"> 303</span><spanclass="comment">// Displays a short string with the current iteration and objective value.</span></div>
<divclass="line"><aid="l00306"name="l00306"></a><spanclass="lineno"> 306</span><spanclass="comment">// Displays the error bounds of the current solution.</span></div>
<divclass="line"><aid="l00309"name="l00309"></a><spanclass="lineno"> 309</span><spanclass="comment">// Displays the status of the variables.</span></div>
<divclass="line"><aid="l00312"name="l00312"></a><spanclass="lineno"> 312</span><spanclass="comment">// Displays the bounds of the variables.</span></div>
<divclass="line"><aid="l00315"name="l00315"></a><spanclass="lineno"> 315</span><spanclass="comment">// Displays the following information:</span></div>
<divclass="line"><aid="l00316"name="l00316"></a><spanclass="lineno"> 316</span><spanclass="comment">// * Linear Programming problem as a dictionary, taking into</span></div>
<divclass="line"><aid="l00317"name="l00317"></a><spanclass="lineno"> 317</span><spanclass="comment">// account the iterations that have been made;</span></div>
<divclass="line"><aid="l00321"name="l00321"></a><spanclass="lineno"> 321</span><spanclass="comment">// A dictionary is in the form:</span></div>
<divclass="line"><aid="l00322"name="l00322"></a><spanclass="lineno"> 322</span><spanclass="comment">// xB = value + sum_{j in N} pa_ij x_j</span></div>
<divclass="line"><aid="l00323"name="l00323"></a><spanclass="lineno"> 323</span><spanclass="comment">// z = objective_value + sum_{i in N} rc_i x_i</span></div>
<divclass="line"><aid="l00324"name="l00324"></a><spanclass="lineno"> 324</span><spanclass="comment">// where the pa's are the coefficients of the matrix after the pivotings</span></div>
<divclass="line"><aid="l00325"name="l00325"></a><spanclass="lineno"> 325</span><spanclass="comment">// and the rc's are the reduced costs, i.e. the coefficients of the objective</span></div>
<divclass="line"><aid="l00326"name="l00326"></a><spanclass="lineno"> 326</span><spanclass="comment">// after the pivotings.</span></div>
<divclass="line"><aid="l00327"name="l00327"></a><spanclass="lineno"> 327</span><spanclass="comment">// Dictionaries are the modern way of presenting the result of an iteration</span></div>
<divclass="line"><aid="l00328"name="l00328"></a><spanclass="lineno"> 328</span><spanclass="comment">// of the Simplex algorithm in the literature.</span></div>
<divclass="line"><aid="l00331"name="l00331"></a><spanclass="lineno"> 331</span><spanclass="comment">// Displays the Linear Programming problem as it was input.</span></div>
<divclass="line"><aid="l00334"name="l00334"></a><spanclass="lineno"> 334</span><spanclass="comment">// Returns the current objective value. This is just the sum of the current</span></div>
<divclass="line"><aid="l00335"name="l00335"></a><spanclass="lineno"> 335</span><spanclass="comment">// variable values times their current cost.</span></div>
<divclass="line"><aid="l00338"name="l00338"></a><spanclass="lineno"> 338</span><spanclass="comment">// Returns the current objective of the linear program given to Solve() using</span></div>
<divclass="line"><aid="l00339"name="l00339"></a><spanclass="lineno"> 339</span><spanclass="comment">// the initial costs, maximization direction, objective offset and objective</span></div>
<divclass="line"><aid="l00343"name="l00343"></a><spanclass="lineno"> 343</span><spanclass="comment">// Assigns names to variables. Variables in the input will be named</span></div>
<divclass="line"><aid="l00344"name="l00344"></a><spanclass="lineno"> 344</span><spanclass="comment">// x1..., slack variables will be s1... .</span></div>
<divclass="line"><aid="l00347"name="l00347"></a><spanclass="lineno"> 347</span><spanclass="comment">// Sets the variable status and derives the variable value according to the</span></div>
<divclass="line"><aid="l00348"name="l00348"></a><spanclass="lineno"> 348</span><spanclass="comment">// exact status definition. This can only be called for non-basic variables</span></div>
<divclass="line"><aid="l00349"name="l00349"></a><spanclass="lineno"> 349</span><spanclass="comment">// because the value of a basic variable is computed from the values of the</span></div>
<divclass="line"><aid="l00354"name="l00354"></a><spanclass="lineno"> 354</span><spanclass="comment">// Checks if the basis_ and is_basic_ arrays are well formed. Also checks that</span></div>
<divclass="line"><aid="l00355"name="l00355"></a><spanclass="lineno"> 355</span><spanclass="comment">// the variable statuses are consistent with this basis. Returns true if this</span></div>
<divclass="line"><aid="l00356"name="l00356"></a><spanclass="lineno"> 356</span><spanclass="comment">// is the case. This is meant to be used in debug mode only.</span></div>
<divclass="line"><aid="l00359"name="l00359"></a><spanclass="lineno"> 359</span><spanclass="comment">// Moves the column entering_col into the basis at position basis_row. Removes</span></div>
<divclass="line"><aid="l00360"name="l00360"></a><spanclass="lineno"> 360</span><spanclass="comment">// the current basis column at position basis_row from the basis and sets its</span></div>
<divclass="line"><aid="l00361"name="l00361"></a><spanclass="lineno"> 361</span><spanclass="comment">// status to leaving_variable_status.</span></div>
<divclass="line"><aid="l00365"name="l00365"></a><spanclass="lineno"> 365</span><spanclass="comment">// Initializes matrix-related internal data. Returns true if this data was</span></div>
<divclass="line"><aid="l00366"name="l00366"></a><spanclass="lineno"> 366</span><spanclass="comment">// unchanged. If not, also sets only_change_is_new_rows to true if compared</span></div>
<divclass="line"><aid="l00367"name="l00367"></a><spanclass="lineno"> 367</span><spanclass="comment">// to the current matrix, the only difference is that new rows have been</span></div>
<divclass="line"><aid="l00368"name="l00368"></a><spanclass="lineno"> 368</span><spanclass="comment">// added (with their corresponding extra slack variables). Similarly, sets</span></div>
<divclass="line"><aid="l00369"name="l00369"></a><spanclass="lineno"> 369</span><spanclass="comment">// only_change_is_new_cols to true if the only difference is that new columns</span></div>
<divclass="line"><aid="l00370"name="l00370"></a><spanclass="lineno"> 370</span><spanclass="comment">// have been added, in which case also sets num_new_cols to the number of</span></div>
<divclass="line"><aid="l00371"name="l00371"></a><spanclass="lineno"> 371</span><spanclass="comment">// new columns.</span></div>
<divclass="line"><aid="l00378"name="l00378"></a><spanclass="lineno"> 378</span><spanclass="comment">// Checks if the only change to the bounds is the addition of new columns,</span></div>
<divclass="line"><aid="l00379"name="l00379"></a><spanclass="lineno"> 379</span><spanclass="comment">// and that the new columns have at least one bound equal to zero.</span></div>
<divclass="line"><aid="l00387"name="l00387"></a><spanclass="lineno"> 387</span><spanclass="comment">// Computes the stopping criterion on the problem objective value.</span></div>
<divclass="line"><aid="l00390"name="l00390"></a><spanclass="lineno"> 390</span><spanclass="comment">// Initializes the starting basis. In most cases it starts by the all slack</span></div>
<divclass="line"><aid="l00391"name="l00391"></a><spanclass="lineno"> 391</span><spanclass="comment">// basis and tries to apply some heuristics to replace fixed variables.</span></div>
<divclass="line"><aid="l00392"name="l00392"></a><spanclass="lineno"> 392</span> ABSL_MUST_USE_RESULT Status CreateInitialBasis();</div>
<divclass="line"><aid="l00394"name="l00394"></a><spanclass="lineno"> 394</span><spanclass="comment">// Sets the initial basis to the given columns, try to factorize it and</span></div>
<divclass="line"><aid="l00395"name="l00395"></a><spanclass="lineno"> 395</span><spanclass="comment">// recompute the basic variable values.</span></div>
<divclass="line"><aid="l00399"name="l00399"></a><spanclass="lineno"> 399</span><spanclass="comment">// Entry point for the solver initialization.</span></div>
<divclass="line"><aid="l00400"name="l00400"></a><spanclass="lineno"> 400</span> ABSL_MUST_USE_RESULT Status Initialize(<spanclass="keyword">const</span> LinearProgram& lp);</div>
<divclass="line"><aid="l00402"name="l00402"></a><spanclass="lineno"> 402</span><spanclass="comment">// Saves the current variable statuses in solution_state_.</span></div>
<divclass="line"><aid="l00405"name="l00405"></a><spanclass="lineno"> 405</span><spanclass="comment">// Displays statistics on what kinds of variables are in the current basis.</span></div>
<divclass="line"><aid="l00408"name="l00408"></a><spanclass="lineno"> 408</span><spanclass="comment">// Tries to reduce the initial infeasibility (stored in error_) by using the</span></div>
<divclass="line"><aid="l00409"name="l00409"></a><spanclass="lineno"> 409</span><spanclass="comment">// singleton columns present in the problem. A singleton column is a column</span></div>
<divclass="line"><aid="l00410"name="l00410"></a><spanclass="lineno"> 410</span><spanclass="comment">// with only one non-zero. This is used by CreateInitialBasis().</span></div>
<divclass="line"><aid="l00413"name="l00413"></a><spanclass="lineno"> 413</span><spanclass="comment">// Returns the number of empty rows in the matrix, i.e. rows where all</span></div>
<divclass="line"><aid="l00414"name="l00414"></a><spanclass="lineno"> 414</span><spanclass="comment">// the coefficients are zero.</span></div>
<divclass="line"><aid="l00417"name="l00417"></a><spanclass="lineno"> 417</span><spanclass="comment">// Returns the number of empty columns in the matrix, i.e. columns where all</span></div>
<divclass="line"><aid="l00418"name="l00418"></a><spanclass="lineno"> 418</span><spanclass="comment">// the coefficients are zero.</span></div>
<divclass="line"><aid="l00421"name="l00421"></a><spanclass="lineno"> 421</span><spanclass="comment">// Returns the number of super-basic variables. These are non-basic variables</span></div>
<divclass="line"><aid="l00422"name="l00422"></a><spanclass="lineno"> 422</span><spanclass="comment">// that are not at their bounds (if they have bounds), or non-basic free</span></div>
<divclass="line"><aid="l00423"name="l00423"></a><spanclass="lineno"> 423</span><spanclass="comment">// variables that are not at zero.</span></div>
<divclass="line"><aid="l00426"name="l00426"></a><spanclass="lineno"> 426</span><spanclass="comment">// This method transforms a basis for the first phase, with the optimal</span></div>
<divclass="line"><aid="l00427"name="l00427"></a><spanclass="lineno"> 427</span><spanclass="comment">// value at zero, into a feasible basis for the initial problem, thus</span></div>
<divclass="line"><aid="l00428"name="l00428"></a><spanclass="lineno"> 428</span><spanclass="comment">// preparing the execution of phase-II of the algorithm.</span></div>
<divclass="line"><aid="l00431"name="l00431"></a><spanclass="lineno"> 431</span><spanclass="comment">// If the primal maximum residual is too large, recomputes the basic variable</span></div>
<divclass="line"><aid="l00432"name="l00432"></a><spanclass="lineno"> 432</span><spanclass="comment">// value from the non-basic ones. This function also perturbs the bounds</span></div>
<divclass="line"><aid="l00433"name="l00433"></a><spanclass="lineno"> 433</span><spanclass="comment">// during the primal simplex if too many iterations are degenerate.</span></div>
<divclass="line"><aid="l00435"name="l00435"></a><spanclass="lineno"> 435</span><spanclass="comment">// Only call this on a refactorized basis to have the best precision.</span></div>
<divclass="line"><aid="l00441"name="l00441"></a><spanclass="lineno"> 441</span><spanclass="comment">// Solves the system B.d = a where a is the entering column (given by col).</span></div>
<divclass="line"><aid="l00442"name="l00442"></a><spanclass="lineno"> 442</span><spanclass="comment">// Known as FTRAN (Forward transformation) in FORTRAN codes.</span></div>
<divclass="line"><aid="l00443"name="l00443"></a><spanclass="lineno"> 443</span><spanclass="comment">// See Chvatal's book for more detail (Chapter 7).</span></div>
<divclass="line"><aid="l00446"name="l00446"></a><spanclass="lineno"> 446</span><spanclass="comment">// Computes a - B.d in error_ and return the maximum std::abs() of its coeffs.</span></div>
<divclass="line"><aid="l00449"name="l00449"></a><spanclass="lineno"> 449</span><spanclass="comment">// Computes the ratio of the basic variable corresponding to 'row'. A target</span></div>
<divclass="line"><aid="l00450"name="l00450"></a><spanclass="lineno"> 450</span><spanclass="comment">// bound (upper or lower) is chosen depending on the sign of the entering</span></div>
<divclass="line"><aid="l00451"name="l00451"></a><spanclass="lineno"> 451</span><spanclass="comment">// reduced cost and the sign of the direction 'd_[row]'. The ratio is such</span></div>
<divclass="line"><aid="l00452"name="l00452"></a><spanclass="lineno"> 452</span><spanclass="comment">// that adding 'ratio * d_[row]' to the variable value changes it to its</span></div>
<divclass="line"><aid="l00458"name="l00458"></a><spanclass="lineno"> 458</span><spanclass="comment">// First pass of the Harris ratio test. Returns the harris ratio value which</span></div>
<divclass="line"><aid="l00459"name="l00459"></a><spanclass="lineno"> 459</span><spanclass="comment">// is an upper bound on the ratio value that the leaving variable can take.</span></div>
<divclass="line"><aid="l00460"name="l00460"></a><spanclass="lineno"> 460</span><spanclass="comment">// Fills leaving_candidates with the ratio and row index of a super-set of the</span></div>
<divclass="line"><aid="l00461"name="l00461"></a><spanclass="lineno"> 461</span><spanclass="comment">// columns with a ratio <= harris_ratio.</span></div>
<divclass="line"><aid="l00466"name="l00466"></a><spanclass="lineno"> 466</span><spanclass="comment">// Chooses the leaving variable, considering the entering column and its</span></div>
<divclass="line"><aid="l00467"name="l00467"></a><spanclass="lineno"> 467</span><spanclass="comment">// associated reduced cost. If there was a precision issue and the basis is</span></div>
<divclass="line"><aid="l00468"name="l00468"></a><spanclass="lineno"> 468</span><spanclass="comment">// not refactorized, set refactorize to true. Otherwise, the row number of the</span></div>
<divclass="line"><aid="l00469"name="l00469"></a><spanclass="lineno"> 469</span><spanclass="comment">// leaving variable is written in *leaving_row, and the step length</span></div>
<divclass="line"><aid="l00470"name="l00470"></a><spanclass="lineno"> 470</span><spanclass="comment">// is written in *step_length.</span></div>
<divclass="line"><aid="l00471"name="l00471"></a><spanclass="lineno"> 471</span> Status ChooseLeavingVariableRow(ColIndex entering_col,</div>
<divclass="line"><aid="l00477"name="l00477"></a><spanclass="lineno"> 477</span><spanclass="comment">// Chooses the leaving variable for the primal phase-I algorithm. The</span></div>
<divclass="line"><aid="l00478"name="l00478"></a><spanclass="lineno"> 478</span><spanclass="comment">// algorithm follows more or less what is described in Istvan Maros's book in</span></div>
<divclass="line"><aid="l00479"name="l00479"></a><spanclass="lineno"> 479</span><spanclass="comment">// chapter 9.6 and what is done for the dual phase-I algorithm which was</span></div>
<divclass="line"><aid="l00480"name="l00480"></a><spanclass="lineno"> 480</span><spanclass="comment">// derived from Koberstein's PhD. Both references can be found at the top of</span></div>
<divclass="line"><aid="l00481"name="l00481"></a><spanclass="lineno"> 481</span><spanclass="comment">// this file.</span></div>
<divclass="line"><aid="l00489"name="l00489"></a><spanclass="lineno"> 489</span><spanclass="comment">// Chooses an infeasible basic variable. The returned values are:</span></div>
<divclass="line"><aid="l00490"name="l00490"></a><spanclass="lineno"> 490</span><spanclass="comment">// - leaving_row: the basic index of the infeasible leaving variable</span></div>
<divclass="line"><aid="l00491"name="l00491"></a><spanclass="lineno"> 491</span><spanclass="comment">// or kNoLeavingVariable if no such row exists: the dual simplex algorithm</span></div>
<divclass="line"><aid="l00492"name="l00492"></a><spanclass="lineno"> 492</span><spanclass="comment">// has terminated and the optimal has been reached.</span></div>
<divclass="line"><aid="l00493"name="l00493"></a><spanclass="lineno"> 493</span><spanclass="comment">// - cost_variation: how much do we improve the objective by moving one unit</span></div>
<divclass="line"><aid="l00494"name="l00494"></a><spanclass="lineno"> 494</span><spanclass="comment">// along this dual edge.</span></div>
<divclass="line"><aid="l00495"name="l00495"></a><spanclass="lineno"> 495</span><spanclass="comment">// - target_bound: the bound at which the leaving variable should go when</span></div>
<divclass="line"><aid="l00496"name="l00496"></a><spanclass="lineno"> 496</span><spanclass="comment">// leaving the basis.</span></div>
<divclass="line"><aid="l00497"name="l00497"></a><spanclass="lineno"> 497</span> ABSL_MUST_USE_RESULT Status DualChooseLeavingVariableRow(</div>
<divclass="line"><aid="l00501"name="l00501"></a><spanclass="lineno"> 501</span><spanclass="comment">// Updates the prices used by DualChooseLeavingVariableRow() after a simplex</span></div>
<divclass="line"><aid="l00502"name="l00502"></a><spanclass="lineno"> 502</span><spanclass="comment">// iteration by using direction_. The prices are stored in</span></div>
<divclass="line"><aid="l00503"name="l00503"></a><spanclass="lineno"> 503</span><spanclass="comment">// dual_pricing_vector_. Note that this function only takes care of the</span></div>
<divclass="line"><aid="l00504"name="l00504"></a><spanclass="lineno"> 504</span><spanclass="comment">// entering and leaving column dual feasibility status change and that other</span></div>
<divclass="line"><aid="l00505"name="l00505"></a><spanclass="lineno"> 505</span><spanclass="comment">// changes will be dealt with by DualPhaseIUpdatePriceOnReducedCostsChange().</span></div>
<divclass="line"><aid="l00508"name="l00508"></a><spanclass="lineno"> 508</span><spanclass="comment">// This must be called each time the dual_pricing_vector_ is changed at</span></div>
<divclass="line"><aid="l00509"name="l00509"></a><spanclass="lineno"> 509</span><spanclass="comment">// position row.</span></div>
<divclass="line"><aid="l00514"name="l00514"></a><spanclass="lineno"> 514</span><spanclass="comment">// Updates the prices used by DualChooseLeavingVariableRow() when the reduced</span></div>
<divclass="line"><aid="l00515"name="l00515"></a><spanclass="lineno"> 515</span><spanclass="comment">// costs of the given columns have changed.</span></div>
<divclass="line"><aid="l00519"name="l00519"></a><spanclass="lineno"> 519</span><spanclass="comment">// Same as DualChooseLeavingVariableRow() but for the phase I of the dual</span></div>
<divclass="line"><aid="l00520"name="l00520"></a><spanclass="lineno"> 520</span><spanclass="comment">// simplex. Here the objective is not to minimize the primal infeasibility,</span></div>
<divclass="line"><aid="l00521"name="l00521"></a><spanclass="lineno"> 521</span><spanclass="comment">// but the dual one, so the variable is not chosen in the same way. See</span></div>
<divclass="line"><aid="l00522"name="l00522"></a><spanclass="lineno"> 522</span><spanclass="comment">// "Notes on the Dual simplex Method" or Istvan Maros, "A Piecewise Linear</span></div>
<divclass="line"><aid="l00523"name="l00523"></a><spanclass="lineno"> 523</span><spanclass="comment">// Dual Phase-1 Algorithm for the Simplex Method", Computational Optimization</span></div>
<divclass="line"><aid="l00524"name="l00524"></a><spanclass="lineno"> 524</span><spanclass="comment">// and Applications, October 2003, Volume 26, Issue 1, pp 63-81.</span></div>
<divclass="line"><aid="l00530"name="l00530"></a><spanclass="lineno"> 530</span><spanclass="comment">// Makes sure the boxed variable are dual-feasible by setting them to the</span></div>
<divclass="line"><aid="l00531"name="l00531"></a><spanclass="lineno"> 531</span><spanclass="comment">// correct bound according to their reduced costs. This is called</span></div>
<divclass="line"><aid="l00532"name="l00532"></a><spanclass="lineno"> 532</span><spanclass="comment">// Dual feasibility correction in the literature.</span></div>
<divclass="line"><aid="l00534"name="l00534"></a><spanclass="lineno"> 534</span><spanclass="comment">// Note that this function is also used as a part of the bound flipping ratio</span></div>
<divclass="line"><aid="l00535"name="l00535"></a><spanclass="lineno"> 535</span><spanclass="comment">// test by flipping the boxed dual-infeasible variables at each iteration.</span></div>
<divclass="line"><aid="l00537"name="l00537"></a><spanclass="lineno"> 537</span><spanclass="comment">// If update_basic_values is true, the basic variable values are updated.</span></div>
<divclass="line"><aid="l00542"name="l00542"></a><spanclass="lineno"> 542</span><spanclass="comment">// Computes the step needed to move the leaving_row basic variable to the</span></div>
<divclass="line"><aid="l00543"name="l00543"></a><spanclass="lineno"> 543</span><spanclass="comment">// given target bound.</span></div>
<divclass="line"><aid="l00547"name="l00547"></a><spanclass="lineno"> 547</span><spanclass="comment">// Returns true if the basis obtained after the given pivot can be factorized.</span></div>
<divclass="line"><aid="l00550"name="l00550"></a><spanclass="lineno"> 550</span><spanclass="comment">// Gets the current LU column permutation from basis_representation,</span></div>
<divclass="line"><aid="l00551"name="l00551"></a><spanclass="lineno"> 551</span><spanclass="comment">// applies it to basis_ and then sets it to the identity permutation since</span></div>
<divclass="line"><aid="l00552"name="l00552"></a><spanclass="lineno"> 552</span><spanclass="comment">// it will no longer be needed during solves. This function also updates all</span></div>
<divclass="line"><aid="l00553"name="l00553"></a><spanclass="lineno"> 553</span><spanclass="comment">// the data that depends on the column order in basis_.</span></div>
<divclass="line"><aid="l00556"name="l00556"></a><spanclass="lineno"> 556</span><spanclass="comment">// Updates the system state according to the given basis pivot.</span></div>
<divclass="line"><aid="l00557"name="l00557"></a><spanclass="lineno"> 557</span><spanclass="comment">// Returns an error if the update could not be done because of some precision</span></div>
<divclass="line"><aid="l00563"name="l00563"></a><spanclass="lineno"> 563</span><spanclass="comment">// Displays all the timing stats related to the calling object.</span></div>
<divclass="line"><aid="l00566"name="l00566"></a><spanclass="lineno"> 566</span><spanclass="comment">// Calls basis_factorization_.Refactorize() if refactorize is true, and</span></div>
<divclass="line"><aid="l00567"name="l00567"></a><spanclass="lineno"> 567</span><spanclass="comment">// returns its status. This also sets refactorize to false and invalidates any</span></div>
<divclass="line"><aid="l00568"name="l00568"></a><spanclass="lineno"> 568</span><spanclass="comment">// data structure that depends on the current factorization.</span></div>
<divclass="line"><aid="l00570"name="l00570"></a><spanclass="lineno"> 570</span><spanclass="comment">// The general idea is that if a refactorization is going to be needed during</span></div>
<divclass="line"><aid="l00571"name="l00571"></a><spanclass="lineno"> 571</span><spanclass="comment">// a simplex iteration, it is better to do it as soon as possible so that</span></div>
<divclass="line"><aid="l00572"name="l00572"></a><spanclass="lineno"> 572</span><spanclass="comment">// every component can take advantage of it.</span></div>
<divclass="line"><aid="l00573"name="l00573"></a><spanclass="lineno"> 573</span> Status RefactorizeBasisIfNeeded(<spanclass="keywordtype">bool</span>* refactorize);</div>
<divclass="line"><aid="l00575"name="l00575"></a><spanclass="lineno"> 575</span><spanclass="comment">// Main iteration loop of the primal simplex.</span></div>
<divclass="line"><aid="l00576"name="l00576"></a><spanclass="lineno"> 576</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="l00578"name="l00578"></a><spanclass="lineno"> 578</span><spanclass="comment">// Main iteration loop of the dual simplex.</span></div>
<divclass="line"><aid="l00579"name="l00579"></a><spanclass="lineno"> 579</span> ABSL_MUST_USE_RESULT Status DualMinimize(<spanclass="keywordtype">bool</span> feasibility_phase,</div>
<divclass="line"><aid="l00582"name="l00582"></a><spanclass="lineno"> 582</span><spanclass="comment">// Pushes all super-basic variables to bounds (if applicable) or to zero (if</span></div>
<divclass="line"><aid="l00583"name="l00583"></a><spanclass="lineno"> 583</span><spanclass="comment">// unconstrained). This is part of a "crossover" procedure to find a vertex</span></div>
<divclass="line"><aid="l00584"name="l00584"></a><spanclass="lineno"> 584</span><spanclass="comment">// solution given a (near) optimal solution. Assumes that Minimize() or</span></div>
<divclass="line"><aid="l00585"name="l00585"></a><spanclass="lineno"> 585</span><spanclass="comment">// DualMinimize() has already run, i.e., that we are at an optimal solution</span></div>
<divclass="line"><aid="l00586"name="l00586"></a><spanclass="lineno"> 586</span><spanclass="comment">// within numerical tolerances.</span></div>
<divclass="line"><aid="l00587"name="l00587"></a><spanclass="lineno"> 587</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="l00589"name="l00589"></a><spanclass="lineno"> 589</span><spanclass="comment">// Experimental. This is useful in a MIP context. It performs a few degenerate</span></div>
<divclass="line"><aid="l00590"name="l00590"></a><spanclass="lineno"> 590</span><spanclass="comment">// pivot to try to mimize the fractionality of the optimal basis.</span></div>
<divclass="line"><aid="l00592"name="l00592"></a><spanclass="lineno"> 592</span><spanclass="comment">// We assume that the columns for which SetIntegralityScale() has been called</span></div>
<divclass="line"><aid="l00593"name="l00593"></a><spanclass="lineno"> 593</span><spanclass="comment">// correspond to integral variable once scaled by the given factor.</span></div>
<divclass="line"><aid="l00595"name="l00595"></a><spanclass="lineno"> 595</span><spanclass="comment">// I could only find slides for the reference of this "LP Solution Polishing</span></div>
<divclass="line"><aid="l00596"name="l00596"></a><spanclass="lineno"> 596</span><spanclass="comment">// to improve MIP Performance", Matthias Miltenberger, Zuse Institute Berlin.</span></div>
<divclass="line"><aid="l00597"name="l00597"></a><spanclass="lineno"> 597</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="l00599"name="l00599"></a><spanclass="lineno"> 599</span><spanclass="comment">// Utility functions to return the current ColIndex of the slack column with</span></div>
<divclass="line"><aid="l00600"name="l00600"></a><spanclass="lineno"> 600</span><spanclass="comment">// given number. Note that currently, such columns are always present in the</span></div>
<divclass="line"><aid="l00601"name="l00601"></a><spanclass="lineno"> 601</span><spanclass="comment">// internal representation of a linear program.</span></div>
<divclass="line"><aid="l00604"name="l00604"></a><spanclass="lineno"> 604</span><spanclass="comment">// Advances the deterministic time in time_limit with the difference between</span></div>
<divclass="line"><aid="l00605"name="l00605"></a><spanclass="lineno"> 605</span><spanclass="comment">// the current internal deterministic time and the internal deterministic time</span></div>
<divclass="line"><aid="l00606"name="l00606"></a><spanclass="lineno"> 606</span><spanclass="comment">// during the last call to this method.</span></div>
<divclass="line"><aid="l00607"name="l00607"></a><spanclass="lineno"> 607</span><spanclass="comment">// TODO(user): Update the internals of revised simplex so that the time</span></div>
<divclass="line"><aid="l00608"name="l00608"></a><spanclass="lineno"> 608</span><spanclass="comment">// limit is updated at the source and remove this method.</span></div>
<divclass="line"><aid="l00614"name="l00614"></a><spanclass="lineno"> 614</span><spanclass="comment">// Current number of rows in the problem.</span></div>
<divclass="line"><aid="l00617"name="l00617"></a><spanclass="lineno"> 617</span><spanclass="comment">// Current number of columns in the problem.</span></div>
<divclass="line"><aid="l00620"name="l00620"></a><spanclass="lineno"> 620</span><spanclass="comment">// Index of the first slack variable in the input problem. We assume that all</span></div>
<divclass="line"><aid="l00621"name="l00621"></a><spanclass="lineno"> 621</span><spanclass="comment">// variables with index greater or equal to first_slack_col_ are slack</span></div>
<divclass="line"><aid="l00625"name="l00625"></a><spanclass="lineno"> 625</span><spanclass="comment">// We're using vectors after profiling and looking at the generated assembly</span></div>
<divclass="line"><aid="l00626"name="l00626"></a><spanclass="lineno"> 626</span><spanclass="comment">// it's as fast as std::unique_ptr as long as the size is properly reserved</span></div>
<divclass="line"><aid="l00629"name="l00629"></a><spanclass="lineno"> 629</span><spanclass="comment">// Compact version of the matrix given to Solve().</span></div>
<divclass="line"><aid="l00632"name="l00632"></a><spanclass="lineno"> 632</span><spanclass="comment">// The transpose of compact_matrix_, it may be empty if it is not needed.</span></div>
<divclass="line"><aid="l00635"name="l00635"></a><spanclass="lineno"> 635</span><spanclass="comment">// Stop the algorithm and report feasibility if:</span></div>
<divclass="line"><aid="l00636"name="l00636"></a><spanclass="lineno"> 636</span><spanclass="comment">// - The primal simplex is used, the problem is primal-feasible and the</span></div>
<divclass="line"><aid="l00637"name="l00637"></a><spanclass="lineno"> 637</span><spanclass="comment">// current objective value is strictly lower than primal_objective_limit_.</span></div>
<divclass="line"><aid="l00638"name="l00638"></a><spanclass="lineno"> 638</span><spanclass="comment">// - The dual simplex is used, the problem is dual-feasible and the current</span></div>
<divclass="line"><aid="l00639"name="l00639"></a><spanclass="lineno"> 639</span><spanclass="comment">// objective value is strictly greater than dual_objective_limit_.</span></div>
<divclass="line"><aid="l00643"name="l00643"></a><spanclass="lineno"> 643</span><spanclass="comment">// Current objective (feasibility for Phase-I, user-provided for Phase-II).</span></div>
<divclass="line"><aid="l00646"name="l00646"></a><spanclass="lineno"> 646</span><spanclass="comment">// Array of coefficients for the user-defined objective.</span></div>
<divclass="line"><aid="l00647"name="l00647"></a><spanclass="lineno"> 647</span><spanclass="comment">// Indexed by column number. Used in Phase-II.</span></div>
<divclass="line"><aid="l00650"name="l00650"></a><spanclass="lineno"> 650</span><spanclass="comment">// Objective offset and scaling factor of the linear program given to Solve().</span></div>
<divclass="line"><aid="l00651"name="l00651"></a><spanclass="lineno"> 651</span><spanclass="comment">// This is used to display the correct objective values in the logs with</span></div>
<divclass="line"><aid="l00656"name="l00656"></a><spanclass="lineno"> 656</span><spanclass="comment">// Used in dual phase I to keep track of the non-basic dual infeasible</span></div>
<divclass="line"><aid="l00657"name="l00657"></a><spanclass="lineno"> 657</span><spanclass="comment">// columns and their sign of infeasibility (+1 or -1).</span></div>
<divclass="line"><aid="l00661"name="l00661"></a><spanclass="lineno"> 661</span><spanclass="comment">// A temporary scattered column that is always reset to all zero after use.</span></div>
<divclass="line"><aid="l00664"name="l00664"></a><spanclass="lineno"> 664</span><spanclass="comment">// Array of column index, giving the column number corresponding</span></div>
<divclass="line"><aid="l00665"name="l00665"></a><spanclass="lineno"> 665</span><spanclass="comment">// to a given basis row.</span></div>
<divclass="line"><aid="l00668"name="l00668"></a><spanclass="lineno"> 668</span><spanclass="comment">// Vector of strings containing the names of variables.</span></div>
<divclass="line"><aid="l00669"name="l00669"></a><spanclass="lineno"> 669</span><spanclass="comment">// Indexed by column number.</span></div>
<divclass="line"><aid="l00672"name="l00672"></a><spanclass="lineno"> 672</span><spanclass="comment">// Information about the solution computed by the last Solve().</span></div>
<divclass="line"><aid="l00682"name="l00682"></a><spanclass="lineno"> 682</span><spanclass="comment">// If this is cleared, we assume they are none.</span></div>
<divclass="line"><aid="l00685"name="l00685"></a><spanclass="lineno"> 685</span><spanclass="comment">// Flag used by NotifyThatMatrixIsUnchangedForNextSolve() and changing</span></div>
<divclass="line"><aid="l00686"name="l00686"></a><spanclass="lineno"> 686</span><spanclass="comment">// the behavior of Initialize().</span></div>
<divclass="line"><aid="l00689"name="l00689"></a><spanclass="lineno"> 689</span><spanclass="comment">// This is known as 'd' in the literature and is set during each pivot to the</span></div>
<divclass="line"><aid="l00690"name="l00690"></a><spanclass="lineno"> 690</span><spanclass="comment">// right inverse of the basic entering column of A by ComputeDirection().</span></div>
<divclass="line"><aid="l00691"name="l00691"></a><spanclass="lineno"> 691</span><spanclass="comment">// ComputeDirection() also fills direction_.non_zeros with the position of the</span></div>
<divclass="line"><aid="l00696"name="l00696"></a><spanclass="lineno"> 696</span><spanclass="comment">// Used to compute the error 'b - A.x' or 'a - B.d'.</span></div>
<divclass="line"><aid="l00699"name="l00699"></a><spanclass="lineno"> 699</span><spanclass="comment">// A random number generator. In test we use absl_random_ to have a</span></div>
<divclass="line"><aid="l00700"name="l00700"></a><spanclass="lineno"> 700</span><spanclass="comment">// non-deterministic behavior and avoid client depending on a golden optimal</span></div>
<divclass="line"><aid="l00701"name="l00701"></a><spanclass="lineno"> 701</span><spanclass="comment">// solution which prevent us from easily changing the solver.</span></div>
<divclass="line"><aid="l00708"name="l00708"></a><spanclass="lineno"> 708</span><spanclass="comment">// Representation of matrix B using eta matrices and LU decomposition.</span></div>
<divclass="line"><aid="l00711"name="l00711"></a><spanclass="lineno"> 711</span><spanclass="comment">// Classes responsible for maintaining the data of the corresponding names.</span></div>
<divclass="line"><aid="l00722"name="l00722"></a><spanclass="lineno"> 722</span><spanclass="comment">// Used in dual phase I to hold the price of each possible leaving choices.</span></div>
<divclass="line"><aid="l00725"name="l00725"></a><spanclass="lineno"> 725</span><spanclass="comment">// Temporary memory used by DualMinimize().</span></div>
<divclass="line"><aid="l00728"name="l00728"></a><spanclass="lineno"> 728</span><spanclass="comment">// Total number of iterations performed.</span></div>
<divclass="line"><aid="l00731"name="l00731"></a><spanclass="lineno"> 731</span><spanclass="comment">// Number of iterations performed during the first (feasibility) phase.</span></div>
<divclass="line"><aid="l00734"name="l00734"></a><spanclass="lineno"> 734</span><spanclass="comment">// Number of iterations performed during the second (optimization) phase.</span></div>
<divclass="line"><aid="l00737"name="l00737"></a><spanclass="lineno"> 737</span><spanclass="comment">// Number of iterations performed during the push/crossover phase.</span></div>
<divclass="line"><aid="l00740"name="l00740"></a><spanclass="lineno"> 740</span><spanclass="comment">// Deterministic time for DualPhaseIUpdatePriceOnReducedCostChange().</span></div>
<divclass="line"><aid="l00746"name="l00746"></a><spanclass="lineno"> 746</span><spanclass="comment">// Time spent in the first (feasibility) phase.</span></div>
<divclass="line"><aid="l00749"name="l00749"></a><spanclass="lineno"> 749</span><spanclass="comment">// Time spent in the second (optimization) phase.</span></div>
<divclass="line"><aid="l00752"name="l00752"></a><spanclass="lineno"> 752</span><spanclass="comment">// Time spent in the push/crossover phase.</span></div>
<divclass="line"><aid="l00755"name="l00755"></a><spanclass="lineno"> 755</span><spanclass="comment">// The internal deterministic time during the most recent call to</span></div>
<divclass="line"><aid="l00759"name="l00759"></a><spanclass="lineno"> 759</span><spanclass="comment">// Statistics about the iterations done by PrimalMinimize().</span></div>
<divclass="line"><aid="l00764"name="l00764"></a><spanclass="lineno"> 764</span><spanclass="comment">// Placeholder for all the function timing stats.</span></div>
<divclass="line"><aid="l00765"name="l00765"></a><spanclass="lineno"> 765</span><spanclass="comment">// Mutable because we time const functions like ChooseLeavingVariableRow().</span></div>
<divclass="line"><aid="l00768"name="l00768"></a><spanclass="lineno"> 768</span><spanclass="comment">// Proto holding all the parameters of this algorithm.</span></div>
<divclass="line"><aid="l00770"name="l00770"></a><spanclass="lineno"> 770</span><spanclass="comment">// Note that parameters_ may actually change during a solve as the solver may</span></div>
<divclass="line"><aid="l00771"name="l00771"></a><spanclass="lineno"> 771</span><spanclass="comment">// dynamically adapt some values. It is why we store the argument of the last</span></div>
<divclass="line"><aid="l00772"name="l00772"></a><spanclass="lineno"> 772</span><spanclass="comment">// SetParameters() call in initial_parameters_ so the next Solve() can reset</span></div>
<divclass="line"><aid="l00773"name="l00773"></a><spanclass="lineno"> 773</span><spanclass="comment">// it correctly.</span></div>
<divclass="line"><aid="l00777"name="l00777"></a><spanclass="lineno"> 777</span><spanclass="comment">// LuFactorization used to test if a pivot will cause the new basis to</span></div>
<divclass="line"><aid="l00778"name="l00778"></a><spanclass="lineno"> 778</span><spanclass="comment">// not be factorizable.</span></div>
<divclass="line"><aid="l00781"name="l00781"></a><spanclass="lineno"> 781</span><spanclass="comment">// Number of degenerate iterations made just before the current iteration.</span></div>
<divclass="line"><aid="l00784"name="l00784"></a><spanclass="lineno"> 784</span><spanclass="comment">// Indicate the current phase of the solve.</span></div>
<divclass="line"><aid="l00787"name="l00787"></a><spanclass="lineno"> 787</span><spanclass="comment">// Indicates whether simplex ended due to the objective limit being reached.</span></div>
<divclass="line"><aid="l00788"name="l00788"></a><spanclass="lineno"> 788</span><spanclass="comment">// Note that it's not enough to compare the final objective value with the</span></div>
<divclass="line"><aid="l00789"name="l00789"></a><spanclass="lineno"> 789</span><spanclass="comment">// limit due to numerical issues (i.e., the limit which is reached within</span></div>
<divclass="line"><aid="l00790"name="l00790"></a><spanclass="lineno"> 790</span><spanclass="comment">// given tolerance on the internal objective may no longer be reached when the</span></div>
<divclass="line"><aid="l00791"name="l00791"></a><spanclass="lineno"> 791</span><spanclass="comment">// objective scaling and offset are taken into account).</span></div>
<divclass="line"><aid="l00794"name="l00794"></a><spanclass="lineno"> 794</span><spanclass="comment">// Temporary SparseColumn used by ChooseLeavingVariableRow().</span></div>
<divclass="line"><aid="l00797"name="l00797"></a><spanclass="lineno"> 797</span><spanclass="comment">// Temporary vector used to hold the best leaving column candidates that are</span></div>
<divclass="line"><aid="l00798"name="l00798"></a><spanclass="lineno"> 798</span><spanclass="comment">// tied using the current choosing criteria. We actually only store the tied</span></div>
<divclass="line"><aid="l00799"name="l00799"></a><spanclass="lineno"> 799</span><spanclass="comment">// candidate #2, #3, ...; because the first tied candidate is remembered</span></div>
<divclass="line"><aid="l00809"name="l00809"></a><spanclass="lineno"> 809</span><spanclass="comment">// Hides the details of the dictionary matrix implementation. In the future,</span></div>
<divclass="line"><aid="l00810"name="l00810"></a><spanclass="lineno"> 810</span><spanclass="comment">// GLOP will support generating the dictionary one row at a time without having</span></div>
<divclass="line"><aid="l00811"name="l00811"></a><spanclass="lineno"> 811</span><spanclass="comment">// to store the whole matrix in memory.</span></div>
<divclass="line"><aid="l00816"name="l00816"></a><spanclass="lineno"> 816</span><spanclass="comment">// RevisedSimplex cannot be passed const because we have to call a non-const</span></div>
<divclass="line"><aid="l00818"name="l00818"></a><spanclass="lineno"> 818</span><spanclass="comment">// TODO(user): Overload this to take RevisedSimplex* alone when the</span></div>
<divclass="line"><aid="l00819"name="l00819"></a><spanclass="lineno"> 819</span><spanclass="comment">// caller would normally pass a nullptr for col_scales so this and</span></div>
<divclass="line"><aid="l00820"name="l00820"></a><spanclass="lineno"> 820</span><spanclass="comment">// ComputeDictionary can take a const& argument.</span></div>
<divclass="line"><aid="l00832"name="l00832"></a><spanclass="lineno"> 832</span><spanclass="comment">// TODO(user): This function is a better fit for the future custom iterator.</span></div>
<divclass="line"><aid="l00842"name="l00842"></a><spanclass="lineno"> 842</span><spanclass="comment">// TODO(user): When a row-by-row generation of the dictionary is supported,</span></div>
<divclass="line"><aid="l00843"name="l00843"></a><spanclass="lineno"> 843</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#l00105">time_limit.h:105</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#l00130">revised_simplex.h:130</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#l00604">revised_simplex.cc:604</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#l00562">revised_simplex.cc:562</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#l00595">revised_simplex.cc:595</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#l00599">revised_simplex.cc:599</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1glop_1_1_revised_simplex_html_a866a68af5afd0355fb348f7a59eeff9e"><divclass="ttname"><ahref="classoperations__research_1_1glop_1_1_revised_simplex.html#a866a68af5afd0355fb348f7a59eeff9e">operations_research::glop::RevisedSimplex::Solve</a></div><divclass="ttdeci">ABSL_MUST_USE_RESULT Status Solve(const LinearProgram &lp, TimeLimit *time_limit)</div><divclass="ttdef"><b>Definition:</b><ahref="revised__simplex_8cc_source.html#l00134">revised_simplex.cc:134</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#l00207">revised_simplex.h:207</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#l00611">revised_simplex.cc:611</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#l00574">revised_simplex.cc:574</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>