<!-- 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">cp_model_presolve.h</div></div>
</div><!--header-->
<divclass="contents">
<ahref="cp__model__presolve_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="l00032"></a><spanclass="lineno"> 32</span> <spanclass="comment">// Replaces all the instance of a variable i (and the literals referring to it)</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"> 33</span> <spanclass="comment">// by mapping[i]. The definition of variables i is also moved to its new index.</span></div>
<divclass="line"><aname="l00034"></a><spanclass="lineno"> 34</span> <spanclass="comment">// Variables with a negative mapping value are ignored and it is an error if</span></div>
<divclass="line"><aname="l00035"></a><spanclass="lineno"> 35</span> <spanclass="comment">// such variable is referenced anywhere (this is CHECKed).</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"> 37</span> <spanclass="comment">// The image of the mapping should be dense in [0, new_num_variables), this is</span></div>
<divclass="line"><aname="l00038"></a><spanclass="lineno"> 38</span> <spanclass="comment">// also CHECKed.</span></div>
<divclass="line"><aname="l00042"></a><spanclass="lineno"> 42</span> <spanclass="comment">// Presolves the initial content of presolved_model.</span></div>
<divclass="line"><aname="l00044"></a><spanclass="lineno"> 44</span> <spanclass="comment">// This also creates a mapping model that encode the correspondence between the</span></div>
<divclass="line"><aname="l00045"></a><spanclass="lineno"> 45</span> <spanclass="comment">// two problems. This works as follow:</span></div>
<divclass="line"><aname="l00046"></a><spanclass="lineno"> 46</span> <spanclass="comment">// - The first variables of mapping_model are in one to one correspondence with</span></div>
<divclass="line"><aname="l00047"></a><spanclass="lineno"> 47</span> <spanclass="comment">// the variables of the initial model.</span></div>
<divclass="line"><aname="l00048"></a><spanclass="lineno"> 48</span> <spanclass="comment">// - The presolved_model variables are in one to one correspondence with the</span></div>
<divclass="line"><aname="l00049"></a><spanclass="lineno"> 49</span> <spanclass="comment">// variable at the indices given by postsolve_mapping in the mapping model.</span></div>
<divclass="line"><aname="l00050"></a><spanclass="lineno"> 50</span> <spanclass="comment">// - Fixing one of the two sets of variables and solving the model will assign</span></div>
<divclass="line"><aname="l00051"></a><spanclass="lineno"> 51</span> <spanclass="comment">// the other set to a feasible solution of the other problem. Moreover, the</span></div>
<divclass="line"><aname="l00052"></a><spanclass="lineno"> 52</span> <spanclass="comment">// objective value of these solutions will be the same. Note that solving such</span></div>
<divclass="line"><aname="l00053"></a><spanclass="lineno"> 53</span> <spanclass="comment">// problems will take little time in practice because the propagation will</span></div>
<divclass="line"><aname="l00054"></a><spanclass="lineno"> 54</span> <spanclass="comment">// basically do all the work.</span></div>
<divclass="line"><aname="l00056"></a><spanclass="lineno"> 56</span> <spanclass="comment">// Note(user): an optimization model can be transformed into a decision problem,</span></div>
<divclass="line"><aname="l00057"></a><spanclass="lineno"> 57</span> <spanclass="comment">// if for instance the objective is fixed, or independent from the rest of the</span></div>
<divclass="line"><aname="l00060"></a><spanclass="lineno"> 60</span> <spanclass="comment">// TODO(user): Identify disconnected components and returns a vector of</span></div>
<divclass="line"><aname="l00061"></a><spanclass="lineno"> 61</span> <spanclass="comment">// presolved model? If we go this route, it may be nicer to store the indices</span></div>
<divclass="line"><aname="l00062"></a><spanclass="lineno"> 62</span> <spanclass="comment">// inside the model. We can add a IntegerVariableProto::initial_index;</span></div>
<divclass="line"><aname="l00068"></a><spanclass="lineno"> 68</span> <spanclass="comment">// Returns false if a non-recoverable error was encountered.</span></div>
<divclass="line"><aname="l00070"></a><spanclass="lineno"> 70</span> <spanclass="comment">// TODO(user): Make sure this can never run into this case provided that the</span></div>
<divclass="line"><aname="l00071"></a><spanclass="lineno"> 71</span> <spanclass="comment">// initial model is valid!</span></div>
<divclass="line"><aname="l00074"></a><spanclass="lineno"> 74</span> <spanclass="comment">// Executes presolve method for the given constraint. Public for testing only.</span></div>
<divclass="line"><aname="l00088"></a><spanclass="lineno"> 88</span> <spanclass="comment">// They should return false only if the constraint <-> variable graph didn't</span></div>
<divclass="line"><aname="l00089"></a><spanclass="lineno"> 89</span> <spanclass="comment">// change. This is just an optimization, returning true is always correct.</span></div>
<divclass="line"><aname="l00091"></a><spanclass="lineno"> 91</span> <spanclass="comment">// Invariant about UNSAT: All these functions should abort right away if</span></div>
<divclass="line"><aname="l00092"></a><spanclass="lineno"> 92</span> <spanclass="comment">// context_.IsUnsat() is true. And the only way to change the status to unsat</span></div>
<divclass="line"><aname="l00093"></a><spanclass="lineno"> 93</span> <spanclass="comment">// is through ABSL_MUST_USE_RESULT function that should also abort right away</span></div>
<divclass="line"><aname="l00094"></a><spanclass="lineno"> 94</span> <spanclass="comment">// the current code. This way we shouldn't keep doing computation on an</span></div>
<divclass="line"><aname="l00096"></a><spanclass="lineno"> 96</span> <spanclass="comment">// TODO(user,user): Make these public and unit test.</span></div>
<divclass="line"><aname="l00121"></a><spanclass="lineno"> 121</span> <spanclass="comment">// Regroups terms and substitute affine relations.</span></div>
<divclass="line"><aname="l00122"></a><spanclass="lineno"> 122</span> <spanclass="comment">// Returns true if the set of variables in the expression changed.</span></div>
<divclass="line"><aname="l00130"></a><spanclass="lineno"> 130</span> <spanclass="comment">// For the linear constraints, we have more than one function.</span></div>
<divclass="line"><aname="l00138"></a><spanclass="lineno"> 138</span> <spanclass="comment">// To simplify dealing with the two kind of intervals.</span></div>
<divclass="line"><aname="l00144"></a><spanclass="lineno"> 144</span> <spanclass="comment">// SetPPC is short for set packing, partitioning and covering constraints.</span></div>
<divclass="line"><aname="l00145"></a><spanclass="lineno"> 145</span> <spanclass="comment">// These are sum of booleans <=, = and >= 1 respectively.</span></div>
<divclass="line"><aname="l00148"></a><spanclass="lineno"> 148</span> <spanclass="comment">// Removes dominated constraints or fixes some variables for given pair of</span></div>
<divclass="line"><aname="l00149"></a><spanclass="lineno"> 149</span> <spanclass="comment">// setppc constraints. This assumes that literals in constraint c1 is subset</span></div>
<divclass="line"><aname="l00150"></a><spanclass="lineno"> 150</span> <spanclass="comment">// of literals in constraint c2.</span></div>
<divclass="line"><aname="l00157"></a><spanclass="lineno"> 157</span> <spanclass="comment">// Extracts AtMostOne constraint from Linear constraint.</span></div>
<divclass="line"><aname="l00165"></a><spanclass="lineno"> 165</span> <spanclass="comment">// Extracts cliques from bool_and and small at_most_one constraints and</span></div>
<divclass="line"><aname="l00166"></a><spanclass="lineno"> 166</span> <spanclass="comment">// transforms them into maximal cliques.</span></div>
<divclass="line"><aname="l00169"></a><spanclass="lineno"> 169</span> <spanclass="comment">// Converts bool_or and at_most_one of size 2 to bool_and.</span></div>
<divclass="line"><aname="l00178"></a><spanclass="lineno"> 178</span> <spanclass="comment">// Boths function are responsible for dealing with affine relations.</span></div>
<divclass="line"><aname="l00179"></a><spanclass="lineno"> 179</span> <spanclass="comment">// The second one returns false on UNSAT.</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment">// Used by CanonicalizeLinearExpressionInternal().</span></div>
<divclass="line"><aname="l00195"></a><spanclass="lineno"> 195</span> <spanclass="comment">// Convenient wrapper to call the full presolve.</span></div>
<divclass="line"><aname="l00199"></a><spanclass="lineno"> 199</span> <spanclass="comment">// Returns the index of exact duplicate constraints in the given proto. That</span></div>
<divclass="line"><aname="l00200"></a><spanclass="lineno"> 200</span> <spanclass="comment">// is, all returned constraints will have an identical constraint before it in</span></div>
<divclass="line"><aname="l00201"></a><spanclass="lineno"> 201</span> <spanclass="comment">// the model_proto.constraints() list. Empty constraints are ignored.</span></div>
<divclass="line"><aname="l00203"></a><spanclass="lineno"> 203</span> <spanclass="comment">// Visible here for testing. This is meant to be called at the end of the</span></div>
<divclass="line"><aname="l00204"></a><spanclass="lineno"> 204</span> <spanclass="comment">// presolve where constraints have been canonicalized.</span></div>
<divclass="line"><aname="l00206"></a><spanclass="lineno"> 206</span> <spanclass="comment">// TODO(user): Ignore names? canonicalize constraint further by sorting</span></div>
<divclass="line"><aname="l00207"></a><spanclass="lineno"> 207</span> <spanclass="comment">// enforcement literal list for instance...</span></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a5921e7fd881f9a30b1ccb2c90ed672c8"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a5921e7fd881f9a30b1ccb2c90ed672c8">operations_research::sat::PresolveCpModel</a></div><divclass="ttdeci">bool PresolveCpModel(PresolveContext *context, std::vector< int > *postsolve_mapping)</div><divclass="ttdef"><b>Definition:</b><ahref="cp__model__presolve_8cc_source.html#l05102">cp_model_presolve.cc:5102</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a90650dff7fc501dfe17041e0cb5388fd"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a90650dff7fc501dfe17041e0cb5388fd">operations_research::sat::FindDuplicateConstraints</a></div><divclass="ttdeci">std::vector< int > FindDuplicateConstraints(const CpModelProto &model_proto)</div><divclass="ttdef"><b>Definition:</b><ahref="cp__model__presolve_8cc_source.html#l05548">cp_model_presolve.cc:5548</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ae82ca1b371f76400eefb8e94246c5fe2"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ae82ca1b371f76400eefb8e94246c5fe2">operations_research::sat::ApplyVariableMapping</a></div><divclass="ttdeci">void ApplyVariableMapping(const std::vector< int >&mapping, const PresolveContext &context)</div><divclass="ttdef"><b>Definition:</b><ahref="cp__model__presolve_8cc_source.html#l05447">cp_model_presolve.cc:5447</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>