OR-Tools  8.0
cuts.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_SAT_CUTS_H_
15 #define OR_TOOLS_SAT_CUTS_H_
16 
17 #include <utility>
18 #include <vector>
19 
20 #include "ortools/base/int_type.h"
22 #include "ortools/sat/integer.h"
23 #include "ortools/sat/intervals.h"
26 #include "ortools/sat/model.h"
28 
29 namespace operations_research {
30 namespace sat {
31 
32 // A "cut" generator on a set of IntegerVariable.
33 //
34 // The generate_cuts() function will usually be called with the current LP
35 // optimal solution (but should work for any lp_values). Note that a
36 // CutGenerator should:
37 // - Only look at the lp_values positions that corresponds to its 'vars' or
38 // their negation.
39 // - Only add cuts in term of the same variables or their negation.
40 struct CutGenerator {
41  std::vector<IntegerVariable> vars;
42  std::function<void(const gtl::ITIVector<IntegerVariable, double>& lp_values,
43  LinearConstraintManager* manager)>
45 };
46 
47 // Given an upper-bounded linear relation (sum terms <= ub), this algorithm
48 // inspects the integer variable appearing in the sum and try to replace each of
49 // them by a tight lower bound (>= coeff * binary + lb) using the implied bound
50 // repository. By tight, we mean that it will take the same value under the
51 // current LP solution.
52 //
53 // We use a class to reuse memory of the tmp terms.
55  public:
56  // We will only replace IntegerVariable appearing in lp_vars_.
57  ImpliedBoundsProcessor(absl::Span<const IntegerVariable> lp_vars_,
58  IntegerTrail* integer_trail,
59  ImpliedBounds* implied_bounds)
60  : lp_vars_(lp_vars_.begin(), lp_vars_.end()),
61  integer_trail_(integer_trail),
62  implied_bounds_(implied_bounds) {}
63 
64  // Processes and updates the given cut.
67  LinearConstraint* cut);
68 
69  // Same as ProcessUpperBoundedConstraint() but instead of just using
70  // var >= coeff * binary + lb we use var == slack + coeff * binary + lb where
71  // slack is a new temporary variable that we create.
72  //
73  // The new slack will be such that slack_infos[(slack - first_slack) / 2]
74  // contains its definition so that we can properly handle it in the cut
75  // generation and substitute it back later.
76  struct SlackInfo {
77  // This slack is equal to sum of terms + offset.
78  std::vector<std::pair<IntegerVariable, IntegerValue>> terms;
79  IntegerValue offset;
80 
81  // The slack bounds and current lp_value.
82  IntegerValue lb = IntegerValue(0);
83  IntegerValue ub = IntegerValue(0);
84  double lp_value = 0.0;
85  };
87  bool substitute_only_inner_variables, IntegerVariable first_slack,
89  LinearConstraint* cut, std::vector<SlackInfo>* slack_infos);
90 
91  // See if some of the implied bounds equation are violated and add them to
92  // the IB cut pool if it is the case.
95 
96  // Only used for debugging.
97  //
98  // Substituting back the slack created by the function above should give
99  // exactly the same cut as the original one.
100  bool DebugSlack(IntegerVariable first_slack,
101  const LinearConstraint& initial_cut,
102  const LinearConstraint& cut,
103  const std::vector<SlackInfo>& info);
104 
105  // Add a new variable that could be used in the new cuts.
106  void AddLpVariable(IntegerVariable var) { lp_vars_.insert(var); }
107 
108  // Must be called before we process any constraints with a different
109  // lp_values or level zero bounds.
110  void ClearCache() const { cache_.clear(); }
111 
113  double bool_lp_value = 0.0;
114  double slack_lp_value = std::numeric_limits<double>::infinity();
116  IntegerValue bound_diff;
117  IntegerVariable bool_var = kNoIntegerVariable;
118  };
120 
121  // As we compute the best implied bounds for each variable, we add violated
122  // cuts here.
123  TopNCuts& IbCutPool() { return ib_cut_pool_; }
124 
125  private:
126  BestImpliedBoundInfo ComputeBestImpliedBound(
127  IntegerVariable var,
128  const gtl::ITIVector<IntegerVariable, double>& lp_values);
129 
130  absl::flat_hash_set<IntegerVariable> lp_vars_;
131  mutable absl::flat_hash_map<IntegerVariable, BestImpliedBoundInfo> cache_;
132 
133  TopNCuts ib_cut_pool_ = TopNCuts(50);
134 
135  // Data from the constructor.
136  IntegerTrail* integer_trail_;
137  ImpliedBounds* implied_bounds_;
138 
139  // Temporary memory used by ProcessUpperBoundedConstraint().
140  mutable std::vector<std::pair<IntegerVariable, IntegerValue>> tmp_terms_;
141 };
142 
143 // Visible for testing. Returns a function f on integers such that:
144 // - f is non-decreasing.
145 // - f is super-additive: f(a) + f(b) <= f(a + b)
146 // - 1 <= f(divisor) <= max_scaling
147 // - For all x, f(x * divisor) = x * f(divisor)
148 // - For all x, f(x * divisor + remainder) = x * f(divisor)
149 //
150 // Preconditions:
151 // - 0 <= remainder < divisor.
152 // - 1 <= max_scaling.
153 //
154 // This is used in IntegerRoundingCut() and is responsible for "strengthening"
155 // the cut. Just taking f(x) = x / divisor result in the non-strengthened cut
156 // and using any function that stricly dominate this one is better.
157 //
158 // Algorithm:
159 // - We first scale by a factor t so that rhs_remainder >= divisor / 2.
160 // - Then, if max_scaling == 2, we use the function described
161 // in "Strenghtening Chvatal-Gomory cuts and Gomory fractional cuts", Adam N.
162 // Letchfrod, Andrea Lodi.
163 // - Otherwise, we use a generalization of this which is a discretized version
164 // of the classical MIR rounding function that only take the value of the
165 // form "an_integer / max_scaling". As max_scaling goes to infinity, this
166 // converge to the real-valued MIR function.
167 //
168 // Note that for each value of max_scaling we will get a different function.
169 // And that there is no dominance relation between any of these functions. So
170 // it could be nice to try to generate a cut using different values of
171 // max_scaling.
172 IntegerValue GetFactorT(IntegerValue rhs_remainder, IntegerValue divisor,
173  IntegerValue max_t);
174 std::function<IntegerValue(IntegerValue)> GetSuperAdditiveRoundingFunction(
175  IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue t,
176  IntegerValue max_scaling);
177 
178 // Given an upper bounded linear constraint, this function tries to transform it
179 // to a valid cut that violate the given LP solution using integer rounding.
180 // Note that the returned cut might not always violate the LP solution, in which
181 // case it can be discarded.
182 //
183 // What this does is basically take the integer division of the constraint by an
184 // integer. If the coefficients where doubles, this would be the same as scaling
185 // the constraint and then rounding. We choose the coefficient of the most
186 // fractional variable (rescaled by its coefficient) as the divisor, but there
187 // are other possible alternatives.
188 //
189 // Note that if the constraint is tight under the given lp solution, and if
190 // there is a unique variable not at one of its bounds and fractional, then we
191 // are guaranteed to generate a cut that violate the current LP solution. This
192 // should be the case for Chvatal-Gomory base constraints modulo our loss of
193 // precision while doing exact integer computations.
194 //
195 // Precondition:
196 // - We assumes that the given initial constraint is tight using the given lp
197 // values. This could be relaxed, but for now it should always be the case, so
198 // we log a message and abort if not, to ease debugging.
199 // - The IntegerVariable of the cuts are not used here. We assumes that the
200 // first three vectors are in one to one correspondence with the initial order
201 // of the variable in the cut.
202 //
203 // TODO(user): There is a bunch of heuristic involved here, and we could spend
204 // more effort tunning them. In particular, one can try many heuristics and keep
205 // the best looking cut (or more than one). This is not on the critical code
206 // path, so we can spend more effort in finding good cuts.
208  IntegerValue max_scaling = IntegerValue(60);
209 };
211  public:
212  void ComputeCut(RoundingOptions options, const std::vector<double>& lp_values,
213  const std::vector<IntegerValue>& lower_bounds,
214  const std::vector<IntegerValue>& upper_bounds,
215  ImpliedBoundsProcessor* ib_processor, LinearConstraint* cut);
216 
217  // Returns the number of implied bound lifted Booleans in the last
218  // ComputeCut() call. Useful for investigation.
219  int NumLiftedBooleans() const { return num_lifted_booleans_; }
220 
221  private:
222  // The helper is just here to reuse the memory for these vectors.
223  std::vector<int> relevant_indices_;
224  std::vector<double> relevant_lp_values_;
225  std::vector<IntegerValue> relevant_coeffs_;
226  std::vector<IntegerValue> relevant_bound_diffs_;
227  std::vector<IntegerValue> divisors_;
228  std::vector<std::pair<int, IntegerValue>> adjusted_coeffs_;
229  std::vector<IntegerValue> remainders_;
230  std::vector<bool> change_sign_at_postprocessing_;
231  std::vector<IntegerValue> rs_;
232  std::vector<IntegerValue> best_rs_;
233 
234  int num_lifted_booleans_ = 0;
235  std::vector<std::pair<IntegerVariable, IntegerValue>> tmp_terms_;
236 };
237 
238 // Helper to find knapsack or flow cover cuts (not yet implemented).
240  public:
241  // Try to find a cut with a knapsack heuristic.
242  // If this returns true, you can get the cut via cut().
243  bool TrySimpleKnapsack(const LinearConstraint base_ct,
244  const std::vector<double>& lp_values,
245  const std::vector<IntegerValue>& lower_bounds,
246  const std::vector<IntegerValue>& upper_bounds);
247 
248  // If successful, info about the last generated cut.
249  LinearConstraint* mutable_cut() { return &cut_; }
250  const LinearConstraint& cut() const { return cut_; }
251 
252  // Single line of text that we append to the cut log line.
253  const std::string Info() { return absl::StrCat("lift=", num_lifting_); }
254 
255  private:
256  struct Term {
257  int index;
258  double dist_to_max_value;
259  IntegerValue positive_coeff; // abs(coeff in original constraint).
260  IntegerValue diff;
261  };
262  std::vector<Term> terms_;
263  std::vector<bool> in_cut_;
264 
265  LinearConstraint cut_;
266  int num_lifting_;
267 };
268 
269 // If a variable is away from its upper bound by more than value 1.0, then it
270 // cannot be part of a cover that will violate the lp solution. This method
271 // returns a reduced constraint by removing such variables from the given
272 // constraint.
273 LinearConstraint GetPreprocessedLinearConstraint(
274  const LinearConstraint& constraint,
276  const IntegerTrail& integer_trail);
277 
278 // Returns true if sum of all the variables in the given constraint is less than
279 // or equal to constraint upper bound. This method assumes that all the
280 // coefficients are non negative.
281 bool ConstraintIsTriviallyTrue(const LinearConstraint& constraint,
282  const IntegerTrail& integer_trail);
283 
284 // If the left variables in lp solution satisfies following inequality, we prove
285 // that there does not exist any knapsack cut which is violated by the solution.
286 // Let |Cmin| = smallest possible cover size.
287 // Let S = smallest (var_ub - lp_values[var]) first |Cmin| variables.
288 // Let cut lower bound = sum_(var in S)(var_ub - lp_values[var])
289 // For any cover,
290 // If cut lower bound >= 1
291 // ==> sum_(var in S)(var_ub - lp_values[var]) >= 1
292 // ==> sum_(var in cover)(var_ub - lp_values[var]) >= 1
293 // ==> The solution already satisfies cover. Since this is true for all covers,
294 // this method returns false in such cases.
295 // This method assumes that the constraint is preprocessed and has only non
296 // negative coefficients.
298  const LinearConstraint& preprocessed_constraint,
300  const IntegerTrail& integer_trail);
301 
302 // Struct to help compute upper bound for knapsack instance.
303 struct KnapsackItem {
304  double profit;
305  double weight;
306  bool operator>(const KnapsackItem& other) const {
307  return profit * other.weight > other.profit * weight;
308  }
309 };
310 
311 // Gets upper bound on profit for knapsack instance by solving the linear
312 // relaxation.
313 double GetKnapsackUpperBound(std::vector<KnapsackItem> items, double capacity);
314 
315 // Returns true if the linear relaxation upper bound for the knapsack instance
316 // shows that this constraint cannot be used to form a cut. This method assumes
317 // that all the coefficients are non negative.
319  const LinearConstraint& constraint,
321  const IntegerTrail& integer_trail);
322 
323 // Returns true if the given constraint passes all the filters described above.
324 // This method assumes that the constraint is preprocessed and has only non
325 // negative coefficients.
327  const LinearConstraint& preprocessed_constraint,
329  const IntegerTrail& integer_trail);
330 
331 // Converts the given constraint into canonical knapsack form (described
332 // below) and adds it to 'knapsack_constraints'.
333 // Canonical knapsack form:
334 // - Constraint has finite upper bound.
335 // - All coefficients are positive.
336 // For constraint with finite lower bound, this method also adds the negation of
337 // the given constraint after converting it to canonical knapsack form.
338 void ConvertToKnapsackForm(const LinearConstraint& constraint,
339  std::vector<LinearConstraint>* knapsack_constraints,
340  IntegerTrail* integer_trail);
341 
342 // Returns true if the cut is lifted. Lifting procedure is described below.
343 //
344 // First we decide a lifting sequence for the binary variables which are not
345 // already in cut. We lift the cut for each lifting candidate one by one.
346 //
347 // Given the original constraint where the lifting candidate is fixed to one, we
348 // compute the maximum value the cut can take and still be feasible using a
349 // knapsack problem. We can then lift the variable in the cut using the
350 // difference between the cut upper bound and this maximum value.
351 bool LiftKnapsackCut(
352  const LinearConstraint& constraint,
354  const std::vector<IntegerValue>& cut_vars_original_coefficients,
355  const IntegerTrail& integer_trail, TimeLimit* time_limit,
356  LinearConstraint* cut);
357 
358 // A cut generator that creates knpasack cover cuts.
359 //
360 // For a constraint of type
361 // \sum_{i=1..n}(a_i * x_i) <= b
362 // where x_i are integer variables with upper bound u_i, a cover of size k is a
363 // subset C of {1 , .. , n} such that \sum_{c \in C}(a_c * u_c) > b.
364 //
365 // A knapsack cover cut is a constraint of the form
366 // \sum_{c \in C}(u_c - x_c) >= 1
367 // which is equivalent to \sum_{c \in C}(x_c) <= \sum_{c \in C}(u_c) - 1.
368 // In other words, in a feasible solution, at least some of the variables do
369 // not take their maximum value.
370 //
371 // If all x_i are binary variables then the cover cut becomes
372 // \sum_{c \in C}(x_c) <= |C| - 1.
373 //
374 // The major difficulty for generating Knapsack cover cuts is finding a minimal
375 // cover set C that cut a given floating point solution. There are many ways to
376 // heuristically generate the cover but the following method that uses a
377 // solution of the LP relaxation of the constraint works the best.
378 //
379 // Look at a given linear relaxation solution for the integer problem x'
380 // and try to solve the following knapsack problem:
381 // Minimize \sum_{i=1..n}(z_i * (u_i - x_i')),
382 // such that \sum_{i=1..n}(a_i * u_i * z_i) > b,
383 // where z_i is a binary decision variable and x_i' are values of the variables
384 // in the given relaxation solution x'. If the objective of the optimal solution
385 // of this problem is less than 1, this algorithm does not generate any cuts.
386 // Otherwise, it adds a knapsack cover cut in the form
387 // \sum_{i=1..n}(z_i' * x_i) <= cb,
388 // where z_i' is the value of z_i in the optimal solution of the above
389 // problem and cb is the upper bound for the cut constraint. Note that the above
390 // problem can be converted into a standard kanpsack form by replacing z_i by 1
391 // - y_i. In that case the problem becomes
392 // Maximize \sum_{i=1..n}((u_i - x_i') * (y_i - 1)),
393 // such that
394 // \sum_{i=1..n}(a_i * u_i * y_i) <= \sum_{i=1..n}(a_i * u_i) - b - 1.
395 //
396 // Solving this knapsack instance would help us find the smallest cover with
397 // maximum LP violation.
398 //
399 // Cut strengthning:
400 // Let lambda = \sum_{c \in C}(a_c * u_c) - b and max_coeff = \max_{c
401 // \in C}(a_c), then cut can be strengthened as
402 // \sum_{c \in C}(u_c - x_c) >= ceil(lambda / max_coeff)
403 //
404 // For further information about knapsack cover cuts see
405 // A. Atamtürk, Cover and Pack Inequalities for (Mixed) Integer Programming
406 // Annals of Operations Research Volume 139, Issue 1 , pp 21-38, 2005.
407 // TODO(user): Implement cut lifting.
409  const std::vector<LinearConstraint>& base_constraints,
410  const std::vector<IntegerVariable>& vars, Model* model);
411 
412 // A cut generator for z = x * y (x and y >= 0).
413 CutGenerator CreatePositiveMultiplicationCutGenerator(IntegerVariable z,
414  IntegerVariable x,
415  IntegerVariable y,
416  Model* model);
417 
418 // A cut generator for y = x ^ 2 (x >= 0).
419 // It will dynamically add a linear inequality to push y closer to the parabola.
420 CutGenerator CreateSquareCutGenerator(IntegerVariable y, IntegerVariable x,
421  Model* model);
422 
423 // A cut generator for all_diff(xi). Let the united domain of all xi be D. Sum
424 // of any k-sized subset of xi need to be greater or equal to the sum of
425 // smallest k values in D and lesser or equal to the sum of largest k values in
426 // D. The cut generator first sorts the variables based on LP values and adds
427 // cuts of the form described above if they are violated by lp solution. Note
428 // that all the fixed variables are ignored while generating cuts.
429 CutGenerator CreateAllDifferentCutGenerator(
430  const std::vector<IntegerVariable>& vars, Model* model);
431 
432 // Consider the Lin Max constraint with d expressions and n variables in the
433 // form: target = max {exprs[k] = Sum (wki * xi + bk)}. k in {1,..,d}.
434 // Li = lower bound of xi
435 // Ui = upper bound of xi.
436 // Let zk be in {0,1} for all k in {1,..,d}.
437 // The target = exprs[k] when zk = 1.
438 //
439 // The following is a valid linearization for Lin Max.
440 // target >= exprs[k], for all k in {1,..,d}
441 // target <= Sum (wli * xi) + Sum((Nlk + bk) * zk), for all l in {1,..,d}
442 // Where Nlk is a large number defined as:
443 // Nlk = Sum (max((wki - wli)*Li, (wki - wli)*Ui))
444 // = Sum (max corner difference for variable i, target expr l, max expr k)
445 //
446 // Consider a partition of variables xi into set {1,..,d} as I.
447 // i.e. I(i) = j means xi is mapped to jth index.
448 // The following inequality is valid and sharp cut for the lin max constraint
449 // described above.
450 //
451 // target <= Sum(i=1..n)(wI(i)i * xi + Sum(k=1..d)(MPlusCoefficient_ki * zk))
452 // + Sum(k=1..d)(bk * zk) ,
453 // Where MPlusCoefficient_ki = max((wki - wI(i)i) * Li,
454 // (wki - wI(i)i) * Ui)
455 // = max corner difference for variable i,
456 // target expr I(i), max expr k.
457 //
458 // For detailed proof of validity, refer
459 // Reference: "Strong mixed-integer programming formulations for trained neural
460 // networks" by Ross Anderson et. (https://arxiv.org/pdf/1811.01988.pdf).
461 //
462 // In the cut generator, we compute the most violated partition I by computing
463 // the rhs value (wI(i)i * lp_value(xi) + Sum(k=1..d)(MPlusCoefficient_ki * zk))
464 // for each variable for each partition index. We choose the partition index
465 // that gives lowest rhs value for a given variable.
466 //
467 // Note: This cut generator requires all expressions to contain only positive
468 // vars.
469 CutGenerator CreateLinMaxCutGenerator(
470  const IntegerVariable target, const std::vector<LinearExpression>& exprs,
471  const std::vector<IntegerVariable>& z_vars, Model* model);
472 
473 // For a given set of intervals and demands, we compute the maximum energy of
474 // each task and make sure it is less than the span of the intervals * its
475 // capacity.
476 //
477 // If an interval is optional, it contributes
478 // min_demand * min_size * presence_literal
479 // amount of total energy.
480 //
481 // If an interval is performed, it contributes either min_demand * size or
482 // demand * min_size. We choose the most violated formulation.
483 //
484 // The maximum energy is capacity * span of intervals at level 0.
485 CutGenerator CreateCumulativeCutGenerator(
486  const std::vector<IntervalVariable>& intervals,
487  const IntegerVariable capacity, const std::vector<IntegerVariable>& demands,
488  Model* model);
489 
490 // For a given set of intervals and demands, we first compute the mandatory part
491 // of the interval as [start_max , end_min]. We use this to calculate mandatory
492 // demands for each start_max time points for eligible intervals.
493 // Since the sum of these mandatory demands must be smaller or equal to the
494 // capacity, we create a cut representing that.
495 //
496 // If an interval is optional, it contributes min_demand * presence_literal
497 // amount of demand to the mandatory demands sum. So the final cut is generated
498 // as follows:
499 // sum(demands of always present intervals)
500 // + sum(presence_literal * min_of_demand) <= capacity.
502  const std::vector<IntervalVariable>& intervals,
503  const IntegerVariable capacity, const std::vector<IntegerVariable>& demands,
504  Model* model);
505 
506 // For a given set of intervals, we first compute the min and max of all
507 // intervals. Then we create a cut that indicates that all intervals must fit
508 // in that span.
509 //
510 // If an interval is optional, it contributes min_size * presence_literal
511 // amount of demand to the mandatory demands sum. So the final cut is generated
512 // as follows:
513 // sum(sizes of always present intervals)
514 // + sum(presence_literal * min_of_size) <= span of all intervals.
515 CutGenerator CreateNoOverlapCutGenerator(
516  const std::vector<IntervalVariable>& intervals, Model* model);
517 
518 // For a given set of intervals in a no_overlap constraint, we detect violated
519 // mandatory precedences and create a cut for these.
521  const std::vector<IntervalVariable>& intervals, Model* model);
522 
523 // Extracts the variables that have a Literal view from base variables and
524 // create a generator that will returns constraint of the form "at_most_one"
525 // between such literals.
526 CutGenerator CreateCliqueCutGenerator(
527  const std::vector<IntegerVariable>& base_variables, Model* model);
528 
529 } // namespace sat
530 } // namespace operations_research
531 
532 #endif // OR_TOOLS_SAT_CUTS_H_
var
IntVar * var
Definition: expr_array.cc:1858
operations_research::sat::ImpliedBoundsProcessor::SlackInfo::terms
std::vector< std::pair< IntegerVariable, IntegerValue > > terms
Definition: cuts.h:78
operations_research::sat::ImpliedBoundsProcessor::ProcessUpperBoundedConstraintWithSlackCreation
void ProcessUpperBoundedConstraintWithSlackCreation(bool substitute_only_inner_variables, IntegerVariable first_slack, const gtl::ITIVector< IntegerVariable, double > &lp_values, LinearConstraint *cut, std::vector< SlackInfo > *slack_infos)
Definition: cuts.cc:1581
operations_research::sat::IntegerTrail
Definition: integer.h:523
operations_research::sat::kNoIntegerVariable
const IntegerVariable kNoIntegerVariable(-1)
operations_research::sat::CreateAllDifferentCutGenerator
CutGenerator CreateAllDifferentCutGenerator(const std::vector< IntegerVariable > &vars, Model *model)
Definition: cuts.cc:1815
operations_research::sat::CanBeFilteredUsingCutLowerBound
bool CanBeFilteredUsingCutLowerBound(const LinearConstraint &preprocessed_constraint, const gtl::ITIVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
Definition: cuts.cc:288
time_limit.h
operations_research::sat::GetFactorT
IntegerValue GetFactorT(IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue max_t)
Definition: cuts.cc:614
operations_research::sat::KnapsackItem::profit
double profit
Definition: cuts.h:304
operations_research::sat::CutGenerator
Definition: cuts.h:40
operations_research::sat::CreateCliqueCutGenerator
CutGenerator CreateCliqueCutGenerator(const std::vector< IntegerVariable > &base_variables, Model *model)
Definition: cuts.cc:2406
operations_research::sat::CoverCutHelper::mutable_cut
LinearConstraint * mutable_cut()
Definition: cuts.h:249
linear_constraint.h
gtl::ITIVector< IntegerVariable, double >
operations_research::sat::ImpliedBoundsProcessor::SlackInfo::ub
IntegerValue ub
Definition: cuts.h:83
operations_research::sat::CoverCutHelper::TrySimpleKnapsack
bool TrySimpleKnapsack(const LinearConstraint base_ct, const std::vector< double > &lp_values, const std::vector< IntegerValue > &lower_bounds, const std::vector< IntegerValue > &upper_bounds)
Definition: cuts.cc:1153
model.h
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::sat::CreateNoOverlapPrecedenceCutGenerator
CutGenerator CreateNoOverlapPrecedenceCutGenerator(const std::vector< IntervalVariable > &intervals, Model *model)
Definition: cuts.cc:2343
operations_research::sat::ImpliedBoundsProcessor::SlackInfo::lp_value
double lp_value
Definition: cuts.h:84
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo
Definition: cuts.h:112
operations_research::sat::ImpliedBoundsProcessor::ImpliedBoundsProcessor
ImpliedBoundsProcessor(absl::Span< const IntegerVariable > lp_vars_, IntegerTrail *integer_trail, ImpliedBounds *implied_bounds)
Definition: cuts.h:57
operations_research::sat::ConvertToKnapsackForm
void ConvertToKnapsackForm(const LinearConstraint &constraint, std::vector< LinearConstraint > *knapsack_constraints, IntegerTrail *integer_trail)
Definition: cuts.cc:386
operations_research::sat::ImpliedBoundsProcessor::ProcessUpperBoundedConstraint
void ProcessUpperBoundedConstraint(const gtl::ITIVector< IntegerVariable, double > &lp_values, LinearConstraint *cut)
Definition: cuts.cc:1488
operations_research::TimeLimit
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Definition: time_limit.h:105
operations_research::sat::LiftKnapsackCut
bool LiftKnapsackCut(const LinearConstraint &constraint, const gtl::ITIVector< IntegerVariable, double > &lp_values, const std::vector< IntegerValue > &cut_vars_original_coefficients, const IntegerTrail &integer_trail, TimeLimit *time_limit, LinearConstraint *cut)
Definition: cuts.cc:170
index
int index
Definition: pack.cc:508
operations_research::sat::ImpliedBoundsProcessor
Definition: cuts.h:54
operations_research::sat::CreateSquareCutGenerator
CutGenerator CreateSquareCutGenerator(IntegerVariable y, IntegerVariable x, Model *model)
Definition: cuts.cc:1421
operations_research::sat::LinearConstraintManager
Definition: linear_constraint_manager.h:40
operations_research::sat::LinearConstraint
Definition: linear_constraint.h:39
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo::slack_lp_value
double slack_lp_value
Definition: cuts.h:114
operations_research::sat::CreateOverlappingCumulativeCutGenerator
CutGenerator CreateOverlappingCumulativeCutGenerator(const std::vector< IntervalVariable > &intervals, const IntegerVariable capacity, const std::vector< IntegerVariable > &demands, Model *model)
Definition: cuts.cc:2212
operations_research::sat::GetPreprocessedLinearConstraint
LinearConstraint GetPreprocessedLinearConstraint(const LinearConstraint &constraint, const gtl::ITIVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
Definition: cuts.cc:248
time_limit
SharedTimeLimit * time_limit
Definition: cp_model_solver.cc:2063
operations_research::sat::RoundingOptions
Definition: cuts.h:207
int_type.h
intervals.h
operations_research::sat::ImpliedBoundsProcessor::IbCutPool
TopNCuts & IbCutPool()
Definition: cuts.h:123
operations_research::sat::CreateLinMaxCutGenerator
CutGenerator CreateLinMaxCutGenerator(const IntegerVariable target, const std::vector< LinearExpression > &exprs, const std::vector< IntegerVariable > &z_vars, Model *model)
Definition: cuts.cc:1912
operations_research::sat::RoundingOptions::max_scaling
IntegerValue max_scaling
Definition: cuts.h:208
operations_research::sat::CreateNoOverlapCutGenerator
CutGenerator CreateNoOverlapCutGenerator(const std::vector< IntervalVariable > &intervals, Model *model)
Definition: cuts.cc:2326
operations_research::sat::IntegerRoundingCutHelper
Definition: cuts.h:210
operations_research::sat::TopNCuts
Definition: linear_constraint_manager.h:280
operations_research::sat::ImpliedBounds
Definition: implied_bounds.h:77
operations_research::sat::CanBeFilteredUsingKnapsackUpperBound
bool CanBeFilteredUsingKnapsackUpperBound(const LinearConstraint &constraint, const gtl::ITIVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
Definition: cuts.cc:334
operations_research::sat::CreatePositiveMultiplicationCutGenerator
CutGenerator CreatePositiveMultiplicationCutGenerator(IntegerVariable z, IntegerVariable x, IntegerVariable y, Model *model)
Definition: cuts.cc:1325
implied_bounds.h
operations_research::sat::ImpliedBoundsProcessor::SeparateSomeImpliedBoundCuts
void SeparateSomeImpliedBoundCuts(const gtl::ITIVector< IntegerVariable, double > &lp_values)
Definition: cuts.cc:1572
operations_research::sat::ImpliedBoundsProcessor::GetCachedImpliedBoundInfo
BestImpliedBoundInfo GetCachedImpliedBoundInfo(IntegerVariable var)
Definition: cuts.cc:1497
model
GRBmodel * model
Definition: gurobi_interface.cc:195
operations_research::sat::CanFormValidKnapsackCover
bool CanFormValidKnapsackCover(const LinearConstraint &preprocessed_constraint, const gtl::ITIVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
Definition: cuts.cc:368
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo::bool_lp_value
double bool_lp_value
Definition: cuts.h:113
operations_research::sat::GetSuperAdditiveRoundingFunction
std::function< IntegerValue(IntegerValue)> GetSuperAdditiveRoundingFunction(IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue t, IntegerValue max_scaling)
Definition: cuts.cc:622
operations_research::sat::ImpliedBoundsProcessor::AddLpVariable
void AddLpVariable(IntegerVariable var)
Definition: cuts.h:106
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo::bound_diff
IntegerValue bound_diff
Definition: cuts.h:116
linear_constraint_manager.h
operations_research::sat::CoverCutHelper::cut
const LinearConstraint & cut() const
Definition: cuts.h:250
operations_research::sat::KnapsackItem::weight
double weight
Definition: cuts.h:305
lower_bounds
std::vector< double > lower_bounds
Definition: sat/lp_utils.cc:443
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo::bool_var
IntegerVariable bool_var
Definition: cuts.h:117
operations_research::sat::ImpliedBoundsProcessor::SlackInfo
Definition: cuts.h:76
operations_research::sat::CutGenerator::generate_cuts
std::function< void(const gtl::ITIVector< IntegerVariable, double > &lp_values, LinearConstraintManager *manager)> generate_cuts
Definition: cuts.h:44
operations_research::sat::ImpliedBoundsProcessor::ClearCache
void ClearCache() const
Definition: cuts.h:110
operations_research::sat::IntegerRoundingCutHelper::ComputeCut
void ComputeCut(RoundingOptions options, const std::vector< double > &lp_values, const std::vector< IntegerValue > &lower_bounds, const std::vector< IntegerValue > &upper_bounds, ImpliedBoundsProcessor *ib_processor, LinearConstraint *cut)
Definition: cuts.cc:705
operations_research::sat::ImpliedBoundsProcessor::DebugSlack
bool DebugSlack(IntegerVariable first_slack, const LinearConstraint &initial_cut, const LinearConstraint &cut, const std::vector< SlackInfo > &info)
Definition: cuts.cc:1722
operations_research::sat::GetKnapsackUpperBound
double GetKnapsackUpperBound(std::vector< KnapsackItem > items, const double capacity)
Definition: cuts.cc:316
operations_research::sat::CutGenerator::vars
std::vector< IntegerVariable > vars
Definition: cuts.h:41
operations_research::sat::CreateCumulativeCutGenerator
CutGenerator CreateCumulativeCutGenerator(const std::vector< IntervalVariable > &intervals, const IntegerVariable capacity, const std::vector< IntegerVariable > &demands, Model *model)
Definition: cuts.cc:2193
capacity
int64 capacity
Definition: routing_flow.cc:129
operations_research::sat::CoverCutHelper::Info
const std::string Info()
Definition: cuts.h:253
operations_research::sat::CoverCutHelper
Definition: cuts.h:239
operations_research::sat::ImpliedBoundsProcessor::BestImpliedBoundInfo::is_positive
bool is_positive
Definition: cuts.h:115
operations_research::sat::KnapsackItem
Definition: cuts.h:303
operations_research::sat::ImpliedBoundsProcessor::SlackInfo::offset
IntegerValue offset
Definition: cuts.h:79
operations_research::sat::IntegerRoundingCutHelper::NumLiftedBooleans
int NumLiftedBooleans() const
Definition: cuts.h:219
upper_bounds
std::vector< double > upper_bounds
Definition: sat/lp_utils.cc:444
operations_research::sat::CreateKnapsackCoverCutGenerator
CutGenerator CreateKnapsackCoverCutGenerator(const std::vector< LinearConstraint > &base_constraints, const std::vector< IntegerVariable > &vars, Model *model)
Definition: cuts.cc:435
operations_research::sat::KnapsackItem::operator>
bool operator>(const KnapsackItem &other) const
Definition: cuts.h:306
operations_research::sat::ImpliedBoundsProcessor::SlackInfo::lb
IntegerValue lb
Definition: cuts.h:82
operations_research::sat::ConstraintIsTriviallyTrue
bool ConstraintIsTriviallyTrue(const LinearConstraint &constraint, const IntegerTrail &integer_trail)
Definition: cuts.cc:272
integer.h