<ahref="linear__relaxation_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="l00037"name="l00037"></a><spanclass="lineno"> 37</span><spanclass="comment">// Looks at all the encoding literal (li <=> var == value_i) that have a</span></div>
<divclass="line"><aid="l00038"name="l00038"></a><spanclass="lineno"> 38</span><spanclass="comment">// view and add a linear relaxation of their relationship with var.</span></div>
<divclass="line"><aid="l00040"name="l00040"></a><spanclass="lineno"> 40</span><spanclass="comment">// If the encoding is full, we can just add:</span></div>
<divclass="line"><aid="l00041"name="l00041"></a><spanclass="lineno"> 41</span><spanclass="comment">// - Sum li == 1</span></div>
<divclass="line"><aid="l00042"name="l00042"></a><spanclass="lineno"> 42</span><spanclass="comment">// - var == min_value + Sum li * (value_i - min_value)</span></div>
<divclass="line"><aid="l00044"name="l00044"></a><spanclass="lineno"> 44</span><spanclass="comment">// When the set of such encoding literals do not cover the full domain of var,</span></div>
<divclass="line"><aid="l00045"name="l00045"></a><spanclass="lineno"> 45</span><spanclass="comment">// we do something a bit more involved. Let min_not_encoded/max_not_encoded the</span></div>
<divclass="line"><aid="l00046"name="l00046"></a><spanclass="lineno"> 46</span><spanclass="comment">// min and max value of the domain of var that is NOT part of the encoding.</span></div>
<divclass="line"><aid="l00047"name="l00047"></a><spanclass="lineno"> 47</span><spanclass="comment">// We add:</span></div>
<divclass="line"><aid="l00048"name="l00048"></a><spanclass="lineno"> 48</span><spanclass="comment">// - Sum li <= 1</span></div>
<divclass="line"><aid="l00049"name="l00049"></a><spanclass="lineno"> 49</span><spanclass="comment">// - var >= (Sum li * value_i) + (1 - Sum li) * min_not_encoded</span></div>
<divclass="line"><aid="l00050"name="l00050"></a><spanclass="lineno"> 50</span><spanclass="comment">// - var <= (Sum li * value_i) + (1 - Sum li) * max_not_encoded</span></div>
<divclass="line"><aid="l00052"name="l00052"></a><spanclass="lineno"> 52</span><spanclass="comment">// Note of the special case where min_not_encoded == max_not_encoded that kind</span></div>
<divclass="line"><aid="l00053"name="l00053"></a><spanclass="lineno"> 53</span><spanclass="comment">// of reduce to the full encoding, except with a different "rhs" value.</span></div>
<divclass="line"><aid="l00055"name="l00055"></a><spanclass="lineno"> 55</span><spanclass="comment">// We also increment the corresponding counter if we added something. We</span></div>
<divclass="line"><aid="l00056"name="l00056"></a><spanclass="lineno"> 56</span><spanclass="comment">// consider the relaxation "tight" if the encoding was full or if</span></div>
<divclass="line"><aid="l00063"name="l00063"></a><spanclass="lineno"> 63</span><spanclass="comment">// This is a different relaxation that use a partial set of literal li such that</span></div>
<divclass="line"><aid="l00064"name="l00064"></a><spanclass="lineno"> 64</span><spanclass="comment">// (li <=> var >= xi). In which case we use the following encoding:</span></div>
<divclass="line"><aid="l00065"name="l00065"></a><spanclass="lineno"> 65</span><spanclass="comment">// - li >= l_{i+1} for all possible i. Note that the xi need to be sorted.</span></div>
<divclass="line"><aid="l00066"name="l00066"></a><spanclass="lineno"> 66</span><spanclass="comment">// - var >= min + l0 * (x0 - min) + Sum_{i>0} li * (xi - x_{i-1})</span></div>
<divclass="line"><aid="l00067"name="l00067"></a><spanclass="lineno"> 67</span><spanclass="comment">// - and same as above for NegationOf(var) for the upper bound.</span></div>
<divclass="line"><aid="l00069"name="l00069"></a><spanclass="lineno"> 69</span><spanclass="comment">// Like for AppendRelaxationForEqualityEncoding() we skip any li that do not</span></div>
<divclass="line"><aid="l00070"name="l00070"></a><spanclass="lineno"> 70</span><spanclass="comment">// have an integer view.</span></div>
<divclass="line"><aid="l00075"name="l00075"></a><spanclass="lineno"> 75</span><spanclass="comment">// Returns a vector of new literals in exactly one relationship.</span></div>
<divclass="line"><aid="l00076"name="l00076"></a><spanclass="lineno"> 76</span><spanclass="comment">// In addition, this create an IntegerView for all these literals and also add</span></div>
<divclass="line"><aid="l00077"name="l00077"></a><spanclass="lineno"> 77</span><spanclass="comment">// the exactly one to the LinearRelaxation.</span></div>
<divclass="line"><aid="l00093"name="l00093"></a><spanclass="lineno"> 93</span><spanclass="comment">// Adds linearization of int max constraints. Returns a vector of z vars such</span></div>
<divclass="line"><aid="l00096"name="l00096"></a><spanclass="lineno"> 96</span><spanclass="comment">// Consider the Lin Max constraint with d expressions and n variables in the</span></div>
<divclass="line"><aid="l00097"name="l00097"></a><spanclass="lineno"> 97</span><spanclass="comment">// form: target = max {exprs[l] = Sum (wli * xi + bl)}. l in {1,..,d}.</span></div>
<divclass="line"><aid="l00098"name="l00098"></a><spanclass="lineno"> 98</span><spanclass="comment">// Li = lower bound of xi</span></div>
<divclass="line"><aid="l00099"name="l00099"></a><spanclass="lineno"> 99</span><spanclass="comment">// Ui = upper bound of xi.</span></div>
<divclass="line"><aid="l00100"name="l00100"></a><spanclass="lineno"> 100</span><spanclass="comment">// Let zl be in {0,1} for all l in {1,..,d}.</span></div>
<divclass="line"><aid="l00101"name="l00101"></a><spanclass="lineno"> 101</span><spanclass="comment">// The target = exprs[l] when zl = 1.</span></div>
<divclass="line"><aid="l00103"name="l00103"></a><spanclass="lineno"> 103</span><spanclass="comment">// The following is a valid linearization for Lin Max.</span></div>
<divclass="line"><aid="l00104"name="l00104"></a><spanclass="lineno"> 104</span><spanclass="comment">// target >= exprs[l], for all l in {1,..,d}</span></div>
<divclass="line"><aid="l00105"name="l00105"></a><spanclass="lineno"> 105</span><spanclass="comment">// target <= Sum_i(wki * xi) + Sum_l((Nkl + bl) * zl), for all k in {1,..,d}</span></div>
<divclass="line"><aid="l00106"name="l00106"></a><spanclass="lineno"> 106</span><spanclass="comment">// Where Nkl is a large number defined as:</span></div>
<divclass="line"><aid="l00108"name="l00108"></a><spanclass="lineno"> 108</span><spanclass="comment">// = Sum (max corner difference for variable i, target expr k, max expr l)</span></div>
<divclass="line"><aid="l00109"name="l00109"></a><spanclass="lineno"> 109</span><spanclass="comment">// Reference: "Strong mixed-integer programming formulations for trained neural</span></div>
<divclass="line"><aid="l00110"name="l00110"></a><spanclass="lineno"> 110</span><spanclass="comment">// networks" by Ross Anderson et. (https://arxiv.org/pdf/1811.01988.pdf).</span></div>
<divclass="line"><aid="l00111"name="l00111"></a><spanclass="lineno"> 111</span><spanclass="comment">// TODO(user): Support linear expression as target.</span></div>
<divclass="line"><aid="l00120"name="l00120"></a><spanclass="lineno"> 120</span><spanclass="comment">// Note: This only works if all affine expressions share the same variable.</span></div>
<divclass="line"><aid="l00124"name="l00124"></a><spanclass="lineno"> 124</span><spanclass="comment">// Appends linear constraints to the relaxation. This also handles the</span></div>
<divclass="line"><aid="l00125"name="l00125"></a><spanclass="lineno"> 125</span><spanclass="comment">// relaxation of linear constraints with enforcement literals.</span></div>
<divclass="line"><aid="l00126"name="l00126"></a><spanclass="lineno"> 126</span><spanclass="comment">// A linear constraint lb <= ax <= ub with enforcement literals {ei} is relaxed</span></div>
<divclass="line"><aid="l00127"name="l00127"></a><spanclass="lineno"> 127</span><spanclass="comment">// as following.</span></div>
<divclass="line"><aid="l00130"name="l00130"></a><spanclass="lineno"> 130</span><spanclass="comment">// Where implied_lb and implied_ub are trivial lower and upper bounds of the</span></div>
<divclass="line"><aid="l00143"name="l00143"></a><spanclass="lineno"> 143</span><spanclass="comment">// Adds linearization of no overlap constraints.</span></div>
<divclass="line"><aid="l00144"name="l00144"></a><spanclass="lineno"> 144</span><spanclass="comment">// It adds an energetic equation linking the duration of all potential tasks to</span></div>
<divclass="line"><aid="l00145"name="l00145"></a><spanclass="lineno"> 145</span><spanclass="comment">// the actual span of the no overlap constraint.</span></div>
<divclass="line"><aid="l00150"name="l00150"></a><spanclass="lineno"> 150</span><spanclass="comment">// Adds linearization of cumulative constraints.The second part adds an</span></div>
<divclass="line"><aid="l00151"name="l00151"></a><spanclass="lineno"> 151</span><spanclass="comment">// energetic equation linking the duration of all potential tasks to the actual</span></div>
<divclass="line"><aid="l00152"name="l00152"></a><spanclass="lineno"> 152</span><spanclass="comment">// max span * capacity of the cumulative constraint.</span></div>
<divclass="line"><aid="l00182"name="l00182"></a><spanclass="lineno"> 182</span><spanclass="comment">// Adds linearization of different types of constraints.</span></div>
<divclass="line"><aid="l00188"name="l00188"></a><spanclass="lineno"> 188</span><spanclass="comment">// Builds the linear relaxation of a CpModelProto.</span></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#l00042">sat/model.h:42</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a3bb33b0ea560d1818c283bacd4b3838e"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a3bb33b0ea560d1818c283bacd4b3838e">operations_research::sat::AddNoOverlapCutGenerator</a></div><divclass="ttdeci">void AddNoOverlapCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01310">linear_relaxation.cc:1310</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a53d4cc6dea5adf2353b4af43bc1bb2f0"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a53d4cc6dea5adf2353b4af43bc1bb2f0">operations_research::sat::AppendBoolAndRelaxation</a></div><divclass="ttdeci">void AppendBoolAndRelaxation(const ConstraintProto &ct, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00421">linear_relaxation.cc:421</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a5df2c2953d660d96c11967cd903a55fe"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a5df2c2953d660d96c11967cd903a55fe">operations_research::sat::AppendLinearConstraintRelaxation</a></div><divclass="ttdeci">void AppendLinearConstraintRelaxation(const ConstraintProto &ct, bool linearize_enforced_constraints, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00951">linear_relaxation.cc:951</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a6acf605cd9a3d72b8e33e8d145c07da5"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a6acf605cd9a3d72b8e33e8d145c07da5">operations_research::sat::AddNoOverlap2dCutGenerator</a></div><divclass="ttdeci">void AddNoOverlap2dCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01338">linear_relaxation.cc:1338</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a750b06e478ba967ec89e70fb3fa7394a"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a750b06e478ba967ec89e70fb3fa7394a">operations_research::sat::AddIntProdCutGenerator</a></div><divclass="ttdeci">void AddIntProdCutGenerator(const ConstraintProto &ct, int linearization_level, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01171">linear_relaxation.cc:1171</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a7545a11562b86718d401f1aeb5781c2a"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a7545a11562b86718d401f1aeb5781c2a">operations_research::sat::AddCircuitCutGenerator</a></div><divclass="ttdeci">void AddCircuitCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01131">linear_relaxation.cc:1131</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a87f6694cfc0f549668a974462118f99e"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a87f6694cfc0f549668a974462118f99e">operations_research::sat::AppendMaxAffineRelaxation</a></div><divclass="ttdeci">void AppendMaxAffineRelaxation(const ConstraintProto &ct, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00842">linear_relaxation.cc:842</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a8b2517dbe721a55849b77267941df8d1"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a8b2517dbe721a55849b77267941df8d1">operations_research::sat::AppendExactlyOneRelaxation</a></div><divclass="ttdeci">void AppendExactlyOneRelaxation(const ConstraintProto &ct, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00462">linear_relaxation.cc:462</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_a938790a385e658a61d53843b6bb5dfd6"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#a938790a385e658a61d53843b6bb5dfd6">operations_research::sat::CreateAlternativeLiteralsWithView</a></div><divclass="ttdeci">std::vector< Literal > CreateAlternativeLiteralsWithView(int num_literals, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00483">linear_relaxation.cc:483</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_aa4529cf0e90f927c1d7005c3cc4b70c5"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#aa4529cf0e90f927c1d7005c3cc4b70c5">operations_research::sat::AppendCircuitRelaxation</a></div><divclass="ttdeci">void AppendCircuitRelaxation(const ConstraintProto &ct, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00524">linear_relaxation.cc:524</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ab4a9f371c11b989199cb8e867d05d813"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ab4a9f371c11b989199cb8e867d05d813">operations_research::sat::AddAllDiffCutGenerator</a></div><divclass="ttdeci">void AddAllDiffCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01222">linear_relaxation.cc:1222</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ac17bc38e4e32fb15f01b0346eb6d0d70"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ac17bc38e4e32fb15f01b0346eb6d0d70">operations_research::sat::AddLinMaxCutGenerator</a></div><divclass="ttdeci">void AddLinMaxCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01383">linear_relaxation.cc:1383</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ac2091b9e5e6e887337a566d5ca547234"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ac2091b9e5e6e887337a566d5ca547234">operations_research::sat::AppendRoutesRelaxation</a></div><divclass="ttdeci">void AppendRoutesRelaxation(const ConstraintProto &ct, Model *model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00565">linear_relaxation.cc:565</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ad8ea8c0f170334873faaa68785e3c636"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ad8ea8c0f170334873faaa68785e3c636">operations_research::sat::AppendRelaxationForEqualityEncoding</a></div><divclass="ttdeci">void AppendRelaxationForEqualityEncoding(IntegerVariable var, const Model &model, LinearRelaxation *relaxation, int *num_tight, int *num_loose)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00171">linear_relaxation.cc:171</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_ae9204d7e95002b030bdc1cff7bb9bc83"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#ae9204d7e95002b030bdc1cff7bb9bc83">operations_research::sat::AddRoutesCutGenerator</a></div><divclass="ttdeci">void AddRoutesCutGenerator(const ConstraintProto &ct, Model *m, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01145">linear_relaxation.cc:1145</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_af68ee38b3d32ecb81072b0cc4d28226b"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#af68ee38b3d32ecb81072b0cc4d28226b">operations_research::sat::ComputeLinearRelaxation</a></div><divclass="ttdeci">LinearRelaxation ComputeLinearRelaxation(const CpModelProto &model_proto, Model *m)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l01481">linear_relaxation.cc:1481</a></div></div>
<divclass="ttc"id="anamespaceoperations__research_1_1sat_html_aff14a4092356fceea657393b7b234b7f"><divclass="ttname"><ahref="namespaceoperations__research_1_1sat.html#aff14a4092356fceea657393b7b234b7f">operations_research::sat::AppendPartialGreaterThanEncodingRelaxation</a></div><divclass="ttdeci">void AppendPartialGreaterThanEncodingRelaxation(IntegerVariable var, const Model &model, LinearRelaxation *relaxation)</div><divclass="ttdef"><b>Definition:</b><ahref="linear__relaxation_8cc_source.html#l00277">linear_relaxation.cc:277</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>