14#ifndef OR_TOOLS_SAT_CUTS_H_
15#define OR_TOOLS_SAT_CUTS_H_
23#include "absl/container/flat_hash_map.h"
24#include "absl/container/flat_hash_set.h"
25#include "absl/strings/str_cat.h"
26#include "absl/types/span.h"
48 std::vector<IntegerVariable>
vars;
68 : lp_vars_(lp_vars_.begin(), lp_vars_.
end()),
69 integer_trail_(integer_trail),
70 implied_bounds_(implied_bounds) {}
94 std::vector<std::pair<IntegerVariable, IntegerValue>>
terms;
98 IntegerValue
lb = IntegerValue(0);
99 IntegerValue
ub = IntegerValue(0);
103 bool substitute_only_inner_variables, IntegerVariable first_slack,
114 const std::vector<SlackInfo>& info);
136 BestImpliedBoundInfo ComputeBestImpliedBound(
140 absl::flat_hash_set<IntegerVariable> lp_vars_;
141 mutable absl::flat_hash_map<IntegerVariable, BestImpliedBoundInfo> cache_;
150 mutable std::vector<std::pair<IntegerVariable, IntegerValue>> tmp_terms_;
182IntegerValue
GetFactorT(IntegerValue rhs_remainder, IntegerValue divisor,
185 IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue t,
186 IntegerValue max_scaling);
233 std::vector<int> relevant_indices_;
234 std::vector<double> relevant_lp_values_;
235 std::vector<IntegerValue> relevant_coeffs_;
236 std::vector<IntegerValue> relevant_bound_diffs_;
237 std::vector<IntegerValue> divisors_;
238 std::vector<std::pair<int, IntegerValue>> adjusted_coeffs_;
239 std::vector<IntegerValue> remainders_;
240 std::vector<bool> change_sign_at_postprocessing_;
241 std::vector<IntegerValue> rs_;
242 std::vector<IntegerValue> best_rs_;
244 int num_lifted_booleans_ = 0;
245 std::vector<std::pair<IntegerVariable, IntegerValue>> tmp_terms_;
254 const std::vector<double>& lp_values,
263 const std::string
Info() {
return absl::StrCat(
"lift=", num_lifting_); }
268 double dist_to_max_value;
269 IntegerValue positive_coeff;
272 std::vector<Term> terms_;
273 std::vector<bool> in_cut_;
275 LinearConstraint cut_;
284 const LinearConstraint& constraint,
286 const IntegerTrail& integer_trail);
292 const IntegerTrail& integer_trail);
308 const LinearConstraint& preprocessed_constraint,
310 const IntegerTrail& integer_trail);
329 const LinearConstraint& constraint,
331 const IntegerTrail& integer_trail);
337 const LinearConstraint& preprocessed_constraint,
339 const IntegerTrail& integer_trail);
349 std::vector<LinearConstraint>* knapsack_constraints,
350 IntegerTrail* integer_trail);
362 const LinearConstraint& constraint,
364 const std::vector<IntegerValue>& cut_vars_original_coefficients,
366 LinearConstraint* cut);
419 const std::vector<LinearConstraint>& base_constraints,
420 const std::vector<IntegerVariable>& vars, Model*
model);
426 int linearization_level,
432 int linearization_level, Model*
model);
441 const std::vector<AffineExpression>& exprs, Model*
model);
481 const IntegerVariable target,
const std::vector<LinearExpression>& exprs,
482 const std::vector<IntegerVariable>& z_vars, Model*
model);
486 const LinearExpression& target, IntegerVariable
var,
487 const std::vector<std::pair<IntegerValue, IntegerValue>>& affines,
495 LinearExpression target, IntegerVariable
var,
496 std::vector<std::pair<IntegerValue, IntegerValue>> affines,
497 const std::string cut_name, Model*
model);
503 const std::vector<IntegerVariable>& base_variables, Model*
model);
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
const LinearConstraint & cut() const
LinearConstraint * mutable_cut()
bool TrySimpleKnapsack(const LinearConstraint base_ct, const std::vector< double > &lp_values, const std::vector< IntegerValue > &lower_bounds, const std::vector< IntegerValue > &upper_bounds)
void AddLpVariable(IntegerVariable var)
void ProcessUpperBoundedConstraintWithSlackCreation(bool substitute_only_inner_variables, IntegerVariable first_slack, const absl::StrongVector< IntegerVariable, double > &lp_values, LinearConstraint *cut, std::vector< SlackInfo > *slack_infos)
void ProcessUpperBoundedConstraint(const absl::StrongVector< IntegerVariable, double > &lp_values, LinearConstraint *cut)
bool DebugSlack(IntegerVariable first_slack, const LinearConstraint &initial_cut, const LinearConstraint &cut, const std::vector< SlackInfo > &info)
void RecomputeCacheAndSeparateSomeImpliedBoundCuts(const absl::StrongVector< IntegerVariable, double > &lp_values)
BestImpliedBoundInfo GetCachedImpliedBoundInfo(IntegerVariable var)
ImpliedBoundsProcessor(absl::Span< const IntegerVariable > lp_vars_, IntegerTrail *integer_trail, ImpliedBounds *implied_bounds)
int NumLiftedBooleans() const
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)
ModelSharedTimeLimit * time_limit
void ConvertToKnapsackForm(const LinearConstraint &constraint, std::vector< LinearConstraint > *knapsack_constraints, IntegerTrail *integer_trail)
LinearConstraint GetPreprocessedLinearConstraint(const LinearConstraint &constraint, const absl::StrongVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
CutGenerator CreateAllDifferentCutGenerator(const std::vector< AffineExpression > &exprs, Model *model)
bool CanFormValidKnapsackCover(const LinearConstraint &preprocessed_constraint, const absl::StrongVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
IntegerValue GetFactorT(IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue max_t)
double GetKnapsackUpperBound(std::vector< KnapsackItem > items, const double capacity)
bool CanBeFilteredUsingCutLowerBound(const LinearConstraint &preprocessed_constraint, const absl::StrongVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
const IntegerVariable kNoIntegerVariable(-1)
CutGenerator CreateLinMaxCutGenerator(const IntegerVariable target, const std::vector< LinearExpression > &exprs, const std::vector< IntegerVariable > &z_vars, Model *model)
CutGenerator CreatePositiveMultiplicationCutGenerator(AffineExpression z, AffineExpression x, AffineExpression y, int linearization_level, Model *model)
LinearConstraint BuildMaxAffineUpConstraint(const LinearExpression &target, IntegerVariable var, const std::vector< std::pair< IntegerValue, IntegerValue > > &affines, Model *model)
bool CanBeFilteredUsingKnapsackUpperBound(const LinearConstraint &constraint, const absl::StrongVector< IntegerVariable, double > &lp_values, const IntegerTrail &integer_trail)
std::function< IntegerValue(IntegerValue)> GetSuperAdditiveRoundingFunction(IntegerValue rhs_remainder, IntegerValue divisor, IntegerValue t, IntegerValue max_scaling)
CutGenerator CreateSquareCutGenerator(AffineExpression y, AffineExpression x, int linearization_level, Model *model)
CutGenerator CreateMaxAffineCutGenerator(LinearExpression target, IntegerVariable var, std::vector< std::pair< IntegerValue, IntegerValue > > affines, const std::string cut_name, Model *model)
CutGenerator CreateKnapsackCoverCutGenerator(const std::vector< LinearConstraint > &base_constraints, const std::vector< IntegerVariable > &vars, Model *model)
bool ConstraintIsTriviallyTrue(const LinearConstraint &constraint, const IntegerTrail &integer_trail)
bool LiftKnapsackCut(const LinearConstraint &constraint, const absl::StrongVector< IntegerVariable, double > &lp_values, const std::vector< IntegerValue > &cut_vars_original_coefficients, const IntegerTrail &integer_trail, TimeLimit *time_limit, LinearConstraint *cut)
CutGenerator CreateCliqueCutGenerator(const std::vector< IntegerVariable > &base_variables, Model *model)
Collection of objects used to extend the Constraint Solver library.
std::vector< double > lower_bounds
std::vector< double > upper_bounds
std::optional< int64_t > end
std::vector< IntegerVariable > vars
std::function< bool(const absl::StrongVector< IntegerVariable, double > &lp_values, LinearConstraintManager *manager)> generate_cuts
std::vector< std::pair< IntegerVariable, IntegerValue > > terms
bool operator>(const KnapsackItem &other) const