<!-- iframe showing the search results (closed by default) -->
<divid="MSearchResultsWindow">
<iframesrc="javascript:void(0)"frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<divclass="header">
<divclass="headertitle">
<divclass="title">presolve_context.h</div></div>
</div><!--header-->
<divclass="contents">
<ahref="presolve__context_8h.html">Go to the documentation of this file.</a><divclass="fragment"><divclass="line"><aname="l00001"></a><spanclass="lineno"> 1</span> <spanclass="comment">// Copyright 2010-2018 Google LLC</span></div>
<divclass="line"><aname="l00002"></a><spanclass="lineno"> 2</span> <spanclass="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div>
<divclass="line"><aname="l00003"></a><spanclass="lineno"> 3</span> <spanclass="comment">// you may not use this file except in compliance with the License.</span></div>
<divclass="line"><aname="l00004"></a><spanclass="lineno"> 4</span> <spanclass="comment">// You may obtain a copy of the License at</span></div>
<divclass="line"><aname="l00008"></a><spanclass="lineno"> 8</span> <spanclass="comment">// Unless required by applicable law or agreed to in writing, software</span></div>
<divclass="line"><aname="l00009"></a><spanclass="lineno"> 9</span> <spanclass="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div>
<divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> <spanclass="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div>
<divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span> <spanclass="comment">// See the License for the specific language governing permissions and</span></div>
<divclass="line"><aname="l00012"></a><spanclass="lineno"> 12</span> <spanclass="comment">// limitations under the License.</span></div>
<divclass="line"><aname="l00034"></a><spanclass="lineno"> 34</span> <spanclass="comment">// We use some special constraint index in our variable <-> constraint graph.</span></div>
<divclass="line"><aname="l00041"></a><spanclass="lineno"> 41</span> <spanclass="comment">// When storing a reference to a literal, it is important not to forget when</span></div>
<divclass="line"><aname="l00042"></a><spanclass="lineno"> 42</span> <spanclass="comment">// reading it back to take its representative. Otherwise, we might introduce</span></div>
<divclass="line"><aname="l00043"></a><spanclass="lineno"> 43</span> <spanclass="comment">// literal that have already been removed, which will break invariants in a</span></div>
<divclass="line"><aname="l00044"></a><spanclass="lineno"> 44</span> <spanclass="comment">// bunch of places.</span></div>
<divclass="line"><aname="l00066"></a><spanclass="lineno"> 66</span> <spanclass="comment">// Wrap the CpModelProto we are presolving with extra data structure like the</span></div>
<divclass="line"><aname="l00067"></a><spanclass="lineno"> 67</span> <spanclass="comment">// in-memory domain of each variables and the constraint variable graph.</span></div>
<divclass="line"><aname="l00079"></a><spanclass="lineno"> 79</span> <spanclass="comment">// Helpers to adds new variables to the presolved model.</span></div>
<divclass="line"><aname="l00090"></a><spanclass="lineno"> 90</span> <spanclass="comment">// Helpers to query the current domain of a variable.</span></div>
<divclass="line"><aname="l00101"></a><spanclass="lineno"> 101</span> <spanclass="comment">// Helpers to query the current domain of a linear expression.</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment">// This doesn't check for integer overflow, but our linear expression</span></div>
<divclass="line"><aname="l00103"></a><spanclass="lineno"> 103</span> <spanclass="comment">// should be such that this cannot happen (tested at validation).</span></div>
<divclass="line"><aname="l00107"></a><spanclass="lineno"> 107</span> <spanclass="comment">// This function takes a positive variable reference.</span></div>
<divclass="line"><aname="l00112"></a><spanclass="lineno"> 112</span> <spanclass="comment">// Returns true if this ref only appear in one constraint.</span></div>
<divclass="line"><aname="l00115"></a><spanclass="lineno"> 115</span> <spanclass="comment">// Returns true if this ref no longer appears in the model.</span></div>
<divclass="line"><aname="l00118"></a><spanclass="lineno"> 118</span> <spanclass="comment">// Functions to make sure that once we remove a variable, we no longer reuse</span></div>
<divclass="line"><aname="l00123"></a><spanclass="lineno"> 123</span> <spanclass="comment">// Same as VariableIsUniqueAndRemovable() except that in this case the</span></div>
<divclass="line"><aname="l00124"></a><spanclass="lineno"> 124</span> <spanclass="comment">// variable also appear in the objective in addition to a single constraint.</span></div>
<divclass="line"><aname="l00127"></a><spanclass="lineno"> 127</span> <spanclass="comment">// Returns true if an integer variable is only appearing in the rhs of</span></div>
<divclass="line"><aname="l00128"></a><spanclass="lineno"> 128</span> <spanclass="comment">// constraints of the form lit => var in domain. When this is the case, then</span></div>
<divclass="line"><aname="l00129"></a><spanclass="lineno"> 129</span> <spanclass="comment">// we can usually remove this variable and replace these constraints with</span></div>
<divclass="line"><aname="l00130"></a><spanclass="lineno"> 130</span> <spanclass="comment">// the proper constraints on the enforcement literals.</span></div>
<divclass="line"><aname="l00133"></a><spanclass="lineno"> 133</span> <spanclass="comment">// Returns false if the new domain is empty. Sets 'domain_modified' (if</span></div>
<divclass="line"><aname="l00134"></a><spanclass="lineno"> 134</span> <spanclass="comment">// provided) to true iff the domain is modified otherwise does not change it.</span></div>
<divclass="line"><aname="l00138"></a><spanclass="lineno"> 138</span> <spanclass="comment">// Returns false if the 'lit' doesn't have the desired value in the domain.</span></div>
<divclass="line"><aname="l00142"></a><spanclass="lineno"> 142</span> <spanclass="comment">// This function always return false. It is just a way to make a little bit</span></div>
<divclass="line"><aname="l00143"></a><spanclass="lineno"> 143</span> <spanclass="comment">// more sure that we abort right away when infeasibility is detected.</span></div>
<divclass="line"><aname="l00146"></a><spanclass="lineno"> 146</span> <spanclass="comment">// TODO(user): Report any explanation for the client in a nicer way?</span></div>
<divclass="line"><aname="l00154"></a><spanclass="lineno"> 154</span> <spanclass="comment">// Stores a description of a rule that was just applied to have a summary of</span></div>
<divclass="line"><aname="l00155"></a><spanclass="lineno"> 155</span> <spanclass="comment">// what the presolve did at the end.</span></div>
<divclass="line"><aname="l00158"></a><spanclass="lineno"> 158</span> <spanclass="comment">// Updates the constraints <-> variables graph. This needs to be called each</span></div>
<divclass="line"><aname="l00159"></a><spanclass="lineno"> 159</span> <spanclass="comment">// time a constraint is modified.</span></div>
<divclass="line"><aname="l00162"></a><spanclass="lineno"> 162</span> <spanclass="comment">// At the beginning of the presolve, we delay the costly creation of this</span></div>
<divclass="line"><aname="l00163"></a><spanclass="lineno"> 163</span> <spanclass="comment">// "graph" until we at least ran some basic presolve. This is because during</span></div>
<divclass="line"><aname="l00164"></a><spanclass="lineno"> 164</span> <spanclass="comment">// a LNS neighbhorhood, many constraints will be reduced significantly by</span></div>
<divclass="line"><aname="l00165"></a><spanclass="lineno"> 165</span> <spanclass="comment">// this "simple" presolve.</span></div>
<divclass="line"><aname="l00168"></a><spanclass="lineno"> 168</span> <spanclass="comment">// Calls UpdateConstraintVariableUsage() on all newly created constraints.</span></div>
<divclass="line"><aname="l00171"></a><spanclass="lineno"> 171</span> <spanclass="comment">// Returns true if our current constraints <-> variables graph is ok.</span></div>
<divclass="line"><aname="l00172"></a><spanclass="lineno"> 172</span> <spanclass="comment">// This is meant to be used in DEBUG mode only.</span></div>
<divclass="line"><aname="l00175"></a><spanclass="lineno"> 175</span> <spanclass="comment">// Regroups fixed variables with the same value.</span></div>
<divclass="line"><aname="l00176"></a><spanclass="lineno"> 176</span> <spanclass="comment">// TODO(user): Also regroup cte and -cte?</span></div>
<divclass="line"><aname="l00179"></a><spanclass="lineno"> 179</span> <spanclass="comment">// Adds the relation (ref_x = coeff * ref_y + offset) to the repository.</span></div>
<divclass="line"><aname="l00180"></a><spanclass="lineno"> 180</span> <spanclass="comment">// Once the relation is added, it doesn't need to be enforced by a constraint</span></div>
<divclass="line"><aname="l00181"></a><spanclass="lineno"> 181</span> <spanclass="comment">// in the model proto, since we will propagate such relation directly and add</span></div>
<divclass="line"><aname="l00182"></a><spanclass="lineno"> 182</span> <spanclass="comment">// them to the proto at the end of the presolve.</span></div>
<divclass="line"><aname="l00184"></a><spanclass="lineno"> 184</span> <spanclass="comment">// Returns true if the relation was added.</span></div>
<divclass="line"><aname="l00185"></a><spanclass="lineno"> 185</span> <spanclass="comment">// In some rare case, like if x = 3*z and y = 5*t are already added, we</span></div>
<divclass="line"><aname="l00186"></a><spanclass="lineno"> 186</span> <spanclass="comment">// currently cannot add x = 2 * y and we will return false in these case. So</span></div>
<divclass="line"><aname="l00187"></a><spanclass="lineno"> 187</span> <spanclass="comment">// when this returns false, the relation needs to be enforced by a separate</span></div>
<divclass="line"><aname="l00190"></a><spanclass="lineno"> 190</span> <spanclass="comment">// If the relation was added, both variables will be marked to appear in the</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment">// special kAffineRelationConstraint. This will allow to identify when a</span></div>
<divclass="line"><aname="l00192"></a><spanclass="lineno"> 192</span> <spanclass="comment">// variable is no longer needed (only appear there and is not a</span></div>
<divclass="line"><aname="l00196"></a><spanclass="lineno"> 196</span> <spanclass="comment">// Adds the fact that ref_a == ref_b using StoreAffineRelation() above.</span></div>
<divclass="line"><aname="l00197"></a><spanclass="lineno"> 197</span> <spanclass="comment">// This should never fail, so the relation will always be added.</span></div>
<divclass="line"><aname="l00200"></a><spanclass="lineno"> 200</span> <spanclass="comment">// Stores/Get the relation target_ref = abs(ref); The first function returns</span></div>
<divclass="line"><aname="l00201"></a><spanclass="lineno"> 201</span> <spanclass="comment">// false if it already exist and the second false if it is not present.</span></div>
<divclass="line"><aname="l00205"></a><spanclass="lineno"> 205</span> <spanclass="comment">// Returns the representative of a literal.</span></div>
<divclass="line"><aname="l00208"></a><spanclass="lineno"> 208</span> <spanclass="comment">// Returns another reference with exactly the same value.</span></div>
<divclass="line"><aname="l00215"></a><spanclass="lineno"> 215</span> <spanclass="comment">// This makes sure that the affine relation only uses one of the</span></div>
<divclass="line"><aname="l00216"></a><spanclass="lineno"> 216</span> <spanclass="comment">// representative from the var_equiv_relations.</span></div>
<divclass="line"><aname="l00223"></a><spanclass="lineno"> 223</span> <spanclass="comment">// Makes sure the domain of ref and of its representative are in sync.</span></div>
<divclass="line"><aname="l00224"></a><spanclass="lineno"> 224</span> <spanclass="comment">// Returns false on unsat.</span></div>
<divclass="line"><aname="l00227"></a><spanclass="lineno"> 227</span> <spanclass="comment">// Creates the internal structure for any new variables in working_model.</span></div>
<divclass="line"><aname="l00233"></a><spanclass="lineno"> 233</span> <spanclass="comment">// Inserts the given literal to encode ref == value.</span></div>
<divclass="line"><aname="l00234"></a><spanclass="lineno"> 234</span> <spanclass="comment">// If an encoding already exists, it adds the two implications between</span></div>
<divclass="line"><aname="l00235"></a><spanclass="lineno"> 235</span> <spanclass="comment">// the previous encoding and the new encoding.</span></div>
<divclass="line"><aname="l00237"></a><spanclass="lineno"> 237</span> <spanclass="comment">// Important: This does not update the constraint<->variable graph, so</span></div>
<divclass="line"><aname="l00238"></a><spanclass="lineno"> 238</span> <spanclass="comment">// ConstraintVariableGraphIsUpToDate() will be false until</span></div>
<divclass="line"><aname="l00239"></a><spanclass="lineno"> 239</span> <spanclass="comment">// UpdateNewConstraintsVariableUsage() is called.</span></div>
<divclass="line"><aname="l00242"></a><spanclass="lineno"> 242</span> <spanclass="comment">// Gets the associated literal if it is already created. Otherwise</span></div>
<divclass="line"><aname="l00243"></a><spanclass="lineno"> 243</span> <spanclass="comment">// create it, add the corresponding constraints and returns it.</span></div>
<divclass="line"><aname="l00245"></a><spanclass="lineno"> 245</span> <spanclass="comment">// Important: This does not update the constraint<->variable graph, so</span></div>
<divclass="line"><aname="l00246"></a><spanclass="lineno"> 246</span> <spanclass="comment">// ConstraintVariableGraphIsUpToDate() will be false until</span></div>
<divclass="line"><aname="l00247"></a><spanclass="lineno"> 247</span> <spanclass="comment">// UpdateNewConstraintsVariableUsage() is called.</span></div>
<divclass="line"><aname="l00250"></a><spanclass="lineno"> 250</span> <spanclass="comment">// If not already done, adds a Boolean to represent any integer variables that</span></div>
<divclass="line"><aname="l00251"></a><spanclass="lineno"> 251</span> <spanclass="comment">// take only two values. Make sure all the relevant affine and encoding</span></div>
<divclass="line"><aname="l00252"></a><spanclass="lineno"> 252</span> <spanclass="comment">// relations are updated.</span></div>
<divclass="line"><aname="l00254"></a><spanclass="lineno"> 254</span> <spanclass="comment">// Note that this might create a new Boolean variable.</span></div>
<divclass="line"><aname="l00257"></a><spanclass="lineno"> 257</span> <spanclass="comment">// Returns true if a literal attached to ref == var exists.</span></div>
<divclass="line"><aname="l00258"></a><spanclass="lineno"> 258</span> <spanclass="comment">// It assigns the corresponding to `literal` if non null.</span></div>
<divclass="line"><aname="l00261"></a><spanclass="lineno"> 261</span> <spanclass="comment">// Stores the fact that literal implies var == value.</span></div>
<divclass="line"><aname="l00262"></a><spanclass="lineno"> 262</span> <spanclass="comment">// It returns true if that information is new.</span></div>
<divclass="line"><aname="l00265"></a><spanclass="lineno"> 265</span> <spanclass="comment">// Stores the fact that literal implies var != value.</span></div>
<divclass="line"><aname="l00266"></a><spanclass="lineno"> 266</span> <spanclass="comment">// It returns true if that information is new.</span></div>
<divclass="line"><aname="l00269"></a><spanclass="lineno"> 269</span> <spanclass="comment">// Objective handling functions. We load it at the beginning so that during</span></div>
<divclass="line"><aname="l00270"></a><spanclass="lineno"> 270</span> <spanclass="comment">// presolve we can work on the more efficient hash_map representation.</span></div>
<divclass="line"><aname="l00272"></a><spanclass="lineno"> 272</span> <spanclass="comment">// Note that ReadObjectiveFromProto() makes sure that var_to_constraints of</span></div>
<divclass="line"><aname="l00273"></a><spanclass="lineno"> 273</span> <spanclass="comment">// all the variable that appear in the objective contains -1. This is later</span></div>
<divclass="line"><aname="l00274"></a><spanclass="lineno"> 274</span> <spanclass="comment">// enforced by all the functions modifying the objective.</span></div>
<divclass="line"><aname="l00276"></a><spanclass="lineno"> 276</span> <spanclass="comment">// Note(user): Because we process affine relation only on</span></div>
<divclass="line"><aname="l00277"></a><spanclass="lineno"> 277</span> <spanclass="comment">// CanonicalizeObjective(), it is possible that when processing a</span></div>
<divclass="line"><aname="l00278"></a><spanclass="lineno"> 278</span> <spanclass="comment">// canonicalized linear constraint, we don't detect that a variable in affine</span></div>
<divclass="line"><aname="l00279"></a><spanclass="lineno"> 279</span> <spanclass="comment">// relation is in the objective. For now this is fine, because when this is</span></div>
<divclass="line"><aname="l00280"></a><spanclass="lineno"> 280</span> <spanclass="comment">// the case, we also have an affine linear constraint, so we can't really do</span></div>
<divclass="line"><aname="l00281"></a><spanclass="lineno"> 281</span> <spanclass="comment">// anything with that variable since it appear in at least two constraints.</span></div>
<divclass="line"><aname="l00286"></a><spanclass="lineno"> 286</span> <spanclass="comment">// Given a variable defined by the given inequality that also appear in the</span></div>
<divclass="line"><aname="l00287"></a><spanclass="lineno"> 287</span> <spanclass="comment">// objective, remove it from the objective by transferring its cost to other</span></div>
<divclass="line"><aname="l00288"></a><spanclass="lineno"> 288</span> <spanclass="comment">// variables in the equality.</span></div>
<divclass="line"><aname="l00290"></a><spanclass="lineno"> 290</span> <spanclass="comment">// If new_vars_in_objective is not nullptr, it will be filled with "new"</span></div>
<divclass="line"><aname="l00291"></a><spanclass="lineno"> 291</span> <spanclass="comment">// variables that where not in the objective before and are after</span></div>
<divclass="line"><aname="l00294"></a><spanclass="lineno"> 294</span> <spanclass="comment">// Returns false, if the substitution cannot be done. This is the case if the</span></div>
<divclass="line"><aname="l00295"></a><spanclass="lineno"> 295</span> <spanclass="comment">// model become UNSAT or if doing it will result in an objective that do not</span></div>
<divclass="line"><aname="l00296"></a><spanclass="lineno"> 296</span> <spanclass="comment">// satisfy our overflow preconditions. Note that this can only happen if the</span></div>
<divclass="line"><aname="l00297"></a><spanclass="lineno"> 297</span> <spanclass="comment">// substitued variable is not implied free (i.e. if its domain is smaller than</span></div>
<divclass="line"><aname="l00298"></a><spanclass="lineno"> 298</span> <spanclass="comment">// the implied domain from the equality).</span></div>
<divclass="line"><aname="l00313"></a><spanclass="lineno"> 313</span> <spanclass="comment">// Advanced usage. This should be called when a variable can be removed from</span></div>
<divclass="line"><aname="l00314"></a><spanclass="lineno"> 314</span> <spanclass="comment">// the problem, so we don't count it as part of an affine relation anymore.</span></div>
<divclass="line"><aname="l00319"></a><spanclass="lineno"> 319</span> <spanclass="comment">// The vector list is sorted and contains unique elements.</span></div>
<divclass="line"><aname="l00321"></a><spanclass="lineno"> 321</span> <spanclass="comment">// Important: To properly handle the objective, var_to_constraints[objective]</span></div>
<divclass="line"><aname="l00322"></a><spanclass="lineno"> 322</span> <spanclass="comment">// contains -1 so that if the objective appear in only one constraint, the</span></div>
<divclass="line"><aname="l00323"></a><spanclass="lineno"> 323</span> <spanclass="comment">// constraint cannot be simplified.</span></div>
<divclass="line"><aname="l00337"></a><spanclass="lineno"> 337</span> <spanclass="comment">// Make sure we never delete an "assumption" literal by using a special</span></div>
<divclass="line"><aname="l00338"></a><spanclass="lineno"> 338</span> <spanclass="comment">// constraint for that.</span></div>
<divclass="line"><aname="l00345"></a><spanclass="lineno"> 345</span> <spanclass="comment">// The following helper adds the following constraint:</span></div>
<divclass="line"><aname="l00346"></a><spanclass="lineno"> 346</span> <spanclass="comment">// result <=> (time_i <= time_j && active_i is true && active_j is true)</span></div>
<divclass="line"><aname="l00347"></a><spanclass="lineno"> 347</span> <spanclass="comment">// and returns the (cached) literal result.</span></div>
<divclass="line"><aname="l00349"></a><spanclass="lineno"> 349</span> <spanclass="comment">// Note that this cache should just be used temporarily and then cleared</span></div>
<divclass="line"><aname="l00350"></a><spanclass="lineno"> 350</span> <spanclass="comment">// with ClearPrecedenceCache() because there is no mechanism to update the</span></div>
<divclass="line"><aname="l00351"></a><spanclass="lineno"> 351</span> <spanclass="comment">// cached literals when literal equivalence are detected.</span></div>
<divclass="line"><aname="l00363"></a><spanclass="lineno"> 363</span> <spanclass="comment">// For each variables, list the constraints that just enforce a lower bound</span></div>
<divclass="line"><aname="l00364"></a><spanclass="lineno"> 364</span> <spanclass="comment">// (resp. upper bound) on that variable. If all the constraints in which a</span></div>
<divclass="line"><aname="l00365"></a><spanclass="lineno"> 365</span> <spanclass="comment">// variable appear are in the same direction, then we can usually fix a</span></div>
<divclass="line"><aname="l00366"></a><spanclass="lineno"> 366</span> <spanclass="comment">// variable to one of its bound (modulo its cost).</span></div>
<divclass="line"><aname="l00368"></a><spanclass="lineno"> 368</span> <spanclass="comment">// TODO(user): Keeping these extra vector of hash_set seems inefficient. Come</span></div>
<divclass="line"><aname="l00369"></a><spanclass="lineno"> 369</span> <spanclass="comment">// up with a better way to detect if a variable is only constrainted in one</span></div>
<divclass="line"><aname="l00377"></a><spanclass="lineno"> 377</span> <spanclass="comment">// Indicate if we are allowed to remove irrelevant feasible solution from the</span></div>
<divclass="line"><aname="l00378"></a><spanclass="lineno"> 378</span> <spanclass="comment">// set of feasible solution. For example, if a variable is unused, can we fix</span></div>
<divclass="line"><aname="l00379"></a><spanclass="lineno"> 379</span> <spanclass="comment">// it to an arbitrary value (or its mimimum objective one)? This must be true</span></div>
<divclass="line"><aname="l00380"></a><spanclass="lineno"> 380</span> <spanclass="comment">// if the client wants to enumerate all solutions or wants correct tightened</span></div>
<divclass="line"><aname="l00381"></a><spanclass="lineno"> 381</span> <spanclass="comment">// bounds in the response.</span></div>
<divclass="line"><aname="l00384"></a><spanclass="lineno"> 384</span> <spanclass="comment">// If true, fills stats_by_rule_name, otherwise do not do that. This can take</span></div>
<divclass="line"><aname="l00385"></a><spanclass="lineno"> 385</span> <spanclass="comment">// a few percent of the run time with a lot of LNS threads.</span></div>
<divclass="line"><aname="l00388"></a><spanclass="lineno"> 388</span> <spanclass="comment">// Just used to display statistics on the presolve rules that were used.</span></div>
<divclass="line"><aname="l00391"></a><spanclass="lineno"> 391</span> <spanclass="comment">// Number of "rules" applied. This should be equal to the sum of all numbers</span></div>
<divclass="line"><aname="l00392"></a><spanclass="lineno"> 392</span> <spanclass="comment">// in stats_by_rule_name. This is used to decide if we should do one more pass</span></div>
<divclass="line"><aname="l00393"></a><spanclass="lineno"> 393</span> <spanclass="comment">// of the presolve or not. Note that depending on the presolve transformation,</span></div>
<divclass="line"><aname="l00394"></a><spanclass="lineno"> 394</span> <spanclass="comment">// a rule can correspond to a tiny change or a big change. Because of that,</span></div>
<divclass="line"><aname="l00395"></a><spanclass="lineno"> 395</span> <spanclass="comment">// this isn't a perfect proxy for the efficacy of the presolve.</span></div>
<divclass="line"><aname="l00404"></a><spanclass="lineno"> 404</span> <spanclass="comment">// Each time a domain is modified this is set to true.</span></div>
<divclass="line"><aname="l00407"></a><spanclass="lineno"> 407</span> <spanclass="comment">// Advanced presolve. See this class comment.</span></div>
<divclass="line"><aname="l00411"></a><spanclass="lineno"> 411</span> <spanclass="comment">// Helper to add an affine relation x = c.y + o to the given repository.</span></div>
<divclass="line"><aname="l00412"></a><spanclass="lineno"> 412</span> <spanclass="keywordtype">bool</span> AddRelation(<spanclass="keywordtype">int</span> x, <spanclass="keywordtype">int</span> y, <aclass="code"href="integral__types_8h.html#a7cde0074dfd288f2d70c0e035dacb28a">int64</a> c, <aclass="code"href="integral__types_8h.html#a7cde0074dfd288f2d70c0e035dacb28a">int64</a> o, <aclass="code"href="classoperations__research_1_1_affine_relation.html">AffineRelation</a>* repo);</div>
<divclass="line"><aname="l00417"></a><spanclass="lineno"> 417</span> <spanclass="comment">// Returns true iff the variable is not the representative of an equivalence</span></div>
<divclass="line"><aname="l00418"></a><spanclass="lineno"> 418</span> <spanclass="comment">// class of size at least 2.</span></div>
<divclass="line"><aname="l00421"></a><spanclass="lineno"> 421</span> <spanclass="comment">// Process encoding_remap_queue_ and updates the encoding maps. This could</span></div>
<divclass="line"><aname="l00422"></a><spanclass="lineno"> 422</span> <spanclass="comment">// lead to UNSAT being detected, in which case it will return false.</span></div>
<divclass="line"><aname="l00425"></a><spanclass="lineno"> 425</span> <spanclass="comment">// Makes sure we only insert encoding about the current representative.</span></div>
<divclass="line"><aname="l00427"></a><spanclass="lineno"> 427</span> <spanclass="comment">// Returns false if ref cannot take the given value (it might not have been</span></div>
<divclass="line"><aname="l00431"></a><spanclass="lineno"> 431</span> <spanclass="comment">// Inserts an half reified var value encoding (literal => var ==/!= value).</span></div>
<divclass="line"><aname="l00432"></a><spanclass="lineno"> 432</span> <spanclass="comment">// It returns true if the new state is different from the old state.</span></div>
<divclass="line"><aname="l00433"></a><spanclass="lineno"> 433</span> <spanclass="comment">// Not that if imply_eq is false, the literal will be stored in its negated</span></div>
<divclass="line"><aname="l00436"></a><spanclass="lineno"> 436</span> <spanclass="comment">// Thus, if you detect literal <=> var == value, then two calls must be made:</span></div>
<divclass="line"><aname="l00437"></a><spanclass="lineno"> 437</span> <spanclass="comment">// InsertHalfVarValueEncoding(literal, var, value, true);</span></div>
<divclass="line"><aname="l00438"></a><spanclass="lineno"> 438</span> <spanclass="comment">// InsertHalfVarValueEncoding(NegatedRef(literal), var, value, false);</span></div>
<divclass="line"><aname="l00451"></a><spanclass="lineno"> 451</span> <spanclass="comment">// Initially false, and set to true on the first inconsistency.</span></div>
<divclass="line"><aname="l00457"></a><spanclass="lineno"> 457</span> <spanclass="comment">// Internal representation of the objective. During presolve, we first load</span></div>
<divclass="line"><aname="l00458"></a><spanclass="lineno"> 458</span> <spanclass="comment">// the objective in this format in order to have more efficient substitution</span></div>
<divclass="line"><aname="l00459"></a><spanclass="lineno"> 459</span> <spanclass="comment">// on large problems (also because the objective is often dense). At the end</span></div>
<divclass="line"><aname="l00460"></a><spanclass="lineno"> 460</span> <spanclass="comment">// we re-convert it to its proto form.</span></div>
<divclass="line"><aname="l00473"></a><spanclass="lineno"> 473</span> <spanclass="comment">// Number of constraints of the form [lit =>] var in domain.</span></div>
<divclass="line"><aname="l00477"></a><spanclass="lineno"> 477</span> <spanclass="comment">// We maintain how many time each interval is used.</span></div>
<divclass="line"><aname="l00484"></a><spanclass="lineno"> 484</span> <spanclass="comment">// For each constant variable appearing in the model, we maintain a reference</span></div>
<divclass="line"><aname="l00485"></a><spanclass="lineno"> 485</span> <spanclass="comment">// variable with the same constant value. If two variables end up having the</span></div>
<divclass="line"><aname="l00486"></a><spanclass="lineno"> 486</span> <spanclass="comment">// same fixed value, then we can detect it using this and add a new</span></div>
<divclass="line"><aname="l00487"></a><spanclass="lineno"> 487</span> <spanclass="comment">// equivalence relation. See ExploitFixedDomain().</span></div>
<divclass="line"><aname="l00490"></a><spanclass="lineno"> 490</span> <spanclass="comment">// When a "representative" gets a new representative, it should be enqueued</span></div>
<divclass="line"><aname="l00491"></a><spanclass="lineno"> 491</span> <spanclass="comment">// here so that we can lazily update the *encoding_ maps below.</span></div>
<divclass="line"><aname="l00494"></a><spanclass="lineno"> 494</span> <spanclass="comment">// Contains variables with some encoded value: encoding_[i][v] points</span></div>
<divclass="line"><aname="l00495"></a><spanclass="lineno"> 495</span> <spanclass="comment">// to the literal attached to the value v of the variable i.</span></div>
<divclass="line"><aname="l00498"></a><spanclass="lineno"> 498</span> <spanclass="comment">// Contains the currently collected half value encodings:</span></div>
<divclass="line"><aname="l00499"></a><spanclass="lineno"> 499</span> <spanclass="comment">// i.e.: literal => var ==/!= value</span></div>
<divclass="line"><aname="l00500"></a><spanclass="lineno"> 500</span> <spanclass="comment">// The state is accumulated (adding x => var == value then !x => var != value)</span></div>
<divclass="line"><aname="l00501"></a><spanclass="lineno"> 501</span> <spanclass="comment">// will deduce that x equivalent to var == value.</span></div>
<divclass="line"><aname="l00507"></a><spanclass="lineno"> 507</span> <spanclass="comment">// This regroups all the affine relations between variables. Note that the</span></div>
<divclass="line"><aname="l00508"></a><spanclass="lineno"> 508</span> <spanclass="comment">// constraints used to detect such relations will not be removed from the</span></div>
<divclass="line"><aname="l00509"></a><spanclass="lineno"> 509</span> <spanclass="comment">// model at detection time (thus allowing proper domain propagation). However,</span></div>
<divclass="line"><aname="l00510"></a><spanclass="lineno"> 510</span> <spanclass="comment">// if the arity of a variable becomes one, then such constraint will be</span></div>
<divclass="line"><aname="l00517"></a><spanclass="lineno"> 517</span> <spanclass="comment">// Used by SetVariableAsRemoved() and VariableWasRemoved().</span></div>
<divclass="line"><aname="l00520"></a><spanclass="lineno"> 520</span> <spanclass="comment">// Cache for the reified precedence literals created during the expansion of</span></div>
<divclass="line"><aname="l00521"></a><spanclass="lineno"> 521</span> <spanclass="comment">// the reservoir constraint. This cache is only valid during the expansion</span></div>
<divclass="line"><aname="l00522"></a><spanclass="lineno"> 522</span> <spanclass="comment">// phase, and is cleared afterwards.</span></div>
<divclass="ttc"id="aclassoperations__research_1_1_domain_html"><divclass="ttname"><ahref="classoperations__research_1_1_domain.html">operations_research::Domain</a></div><divclass="ttdoc">We call domain any subset of Int64 = [kint64min, kint64max].</div><divclass="ttdef"><b>Definition:</b><ahref="sorted__interval__list_8h_source.html#l00081">sorted_interval_list.h:81</a></div></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_1sat_1_1_model_html"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_model.html">operations_research::sat::Model</a></div><divclass="ttdoc">Class that owns everything related to a particular optimization model.</div><divclass="ttdef"><b>Definition:</b><ahref="sat_2model_8h_source.html#l00038">sat/model.h:38</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a06f0856b91c0399720273b5da85ce280"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a06f0856b91c0399720273b5da85ce280">operations_research::sat::PresolveContext::StoreAbsRelation</a></div><divclass="ttdeci">bool StoreAbsRelation(int target_ref, int ref)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l00671">presolve_context.cc:671</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a1aadaad9b8af16ab5a208c682e2e1717"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a1aadaad9b8af16ab5a208c682e2e1717">operations_research::sat::PresolveContext::AddImplication</a></div><divclass="ttdeci">void AddImplication(int a, int b)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l00055">presolve_context.cc:55</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a23aa815e8a7a860998c4d35760fa087e"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a23aa815e8a7a860998c4d35760fa087e">operations_research::sat::PresolveContext::var_to_lb_only_constraints</a></div><divclass="ttdeci">std::vector< absl::flat_hash_set< int >> var_to_lb_only_constraints</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00372">presolve_context.h:372</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a31ade354475e7f6052e62f7befc21cf8"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a31ade354475e7f6052e62f7befc21cf8">operations_research::sat::PresolveContext::StoreLiteralImpliesVarNEqValue</a></div><divclass="ttdeci">bool StoreLiteralImpliesVarNEqValue(int literal, int var, int64 value)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l01056">presolve_context.cc:1056</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a31d9b7763fd739fe805438b464096c32"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a31d9b7763fd739fe805438b464096c32">operations_research::sat::PresolveContext::ObjectiveDomain</a></div><divclass="ttdeci">const Domain & ObjectiveDomain() const</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00305">presolve_context.h:305</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a3dc318518f2e4259ed03b5d1c95316ef"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a3dc318518f2e4259ed03b5d1c95316ef">operations_research::sat::PresolveContext::StoreLiteralImpliesVarEqValue</a></div><divclass="ttdeci">bool StoreLiteralImpliesVarEqValue(int literal, int var, int64 value)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l01048">presolve_context.cc:1048</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a436752c51b5f6010033151b7bd7966da"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a436752c51b5f6010033151b7bd7966da">operations_research::sat::PresolveContext::tmp_literals</a></div><divclass="ttdeci">std::vector< int > tmp_literals</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00399">presolve_context.h:399</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a47714f887512a3d7acebfcb4a348291a"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a47714f887512a3d7acebfcb4a348291a">operations_research::sat::PresolveContext::var_to_ub_only_constraints</a></div><divclass="ttdeci">std::vector< absl::flat_hash_set< int >> var_to_ub_only_constraints</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00371">presolve_context.h:371</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a4d724b2f4bd1d1cab7b11dafd3448d8b"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a4d724b2f4bd1d1cab7b11dafd3448d8b">operations_research::sat::PresolveContext::ConstraintToVars</a></div><divclass="ttdeci">const std::vector< int >& ConstraintToVars(int c) const</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00324">presolve_context.h:324</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a8abe16435f55971a49965eb6616c5783"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a8abe16435f55971a49965eb6616c5783">operations_research::sat::PresolveContext::stats_by_rule_name</a></div><divclass="ttdeci">absl::flat_hash_map< std::string, int > stats_by_rule_name</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00389">presolve_context.h:389</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a8fc1d49d1e1bf7261f15ccc6c23c4b10"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a8fc1d49d1e1bf7261f15ccc6c23c4b10">operations_research::sat::PresolveContext::StoreBooleanEqualityRelation</a></div><divclass="ttdeci">void StoreBooleanEqualityRelation(int ref_a, int ref_b)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l00645">presolve_context.cc:645</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_a90674fa816d7a066e251337852214e84"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#a90674fa816d7a066e251337852214e84">operations_research::sat::PresolveContext::IntervalUsage</a></div><divclass="ttdeci">int IntervalUsage(int c) const</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00332">presolve_context.h:332</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_aaabb604ccac4a6136be93bfe64e2290d"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#aaabb604ccac4a6136be93bfe64e2290d">operations_research::sat::PresolveContext::params</a></div><divclass="ttdeci">const SatParameters & params() const</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00359">presolve_context.h:359</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_adc37a02104d979e9943fadfd2e209686"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#adc37a02104d979e9943fadfd2e209686">operations_research::sat::PresolveContext::GetOrCreateReifiedPrecedenceLiteral</a></div><divclass="ttdeci">int GetOrCreateReifiedPrecedenceLiteral(int time_i, int time_j, int active_i, int active_j)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l01404">presolve_context.cc:1404</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_aeb77639debea43978becf1d990581537"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#aeb77639debea43978becf1d990581537">operations_research::sat::PresolveContext::tmp_literal_set</a></div><divclass="ttdeci">absl::flat_hash_set< int > tmp_literal_set</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00402">presolve_context.h:402</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_af97bdc26758ff0f27314cafb7c2d7044"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#af97bdc26758ff0f27314cafb7c2d7044">operations_research::sat::PresolveContext::GetAbsRelation</a></div><divclass="ttdeci">bool GetAbsRelation(int target_ref, int *ref)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l00686">presolve_context.cc:686</a></div></div>
<divclass="ttc"id="aclassoperations__research_1_1sat_1_1_presolve_context_html_afad3c5370d5ef3338d7a5455198e6364"><divclass="ttname"><ahref="classoperations__research_1_1sat_1_1_presolve_context.html#afad3c5370d5ef3338d7a5455198e6364">operations_research::sat::PresolveContext::StoreAffineRelation</a></div><divclass="ttdeci">bool StoreAffineRelation(int ref_x, int ref_y, int64 coeff, int64 offset)</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8cc_source.html#l00530">presolve_context.cc:530</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a55963ffe87280b37dce97b9a8cbd03ae"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a55963ffe87280b37dce97b9a8cbd03ae">operations_research::sat::kAffineRelationConstraint</a></div><divclass="ttdeci">constexpr int kAffineRelationConstraint</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00036">presolve_context.h:36</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_abe4ecb2ef8f498b18a55fbcbbf54e550"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#abe4ecb2ef8f498b18a55fbcbbf54e550">operations_research::sat::kAssumptionsConstraint</a></div><divclass="ttdeci">constexpr int kAssumptionsConstraint</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00037">presolve_context.h:37</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_aca25bc3ffa54b3f2668c6eeddffd8d1d"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#aca25bc3ffa54b3f2668c6eeddffd8d1d">operations_research::sat::kObjectiveConstraint</a></div><divclass="ttdeci">constexpr int kObjectiveConstraint</div><divclass="ttdef"><b>Definition:</b><ahref="presolve__context_8h_source.html#l00035">presolve_context.h:35</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_html"><divclass="ttname"><ahref="namespaceoperations__research.html">operations_research</a></div><divclass="ttdoc">The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...</div><divclass="ttdef"><b>Definition:</b><ahref="dense__doubly__linked__list_8h_source.html#l00021">dense_doubly_linked_list.h:21</a></div></div>