14 #ifndef OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_ 15 #define OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_ 22 #include "absl/container/flat_hash_map.h" 78 IntegerValue multiplier,
79 const std::vector<std::pair<glop::ColIndex, IntegerValue>>& terms);
88 const std::vector<IntegerVariable>& integer_variables,
92 std::vector<std::pair<glop::ColIndex, IntegerValue>>
GetTerms();
96 return dense_vector_[
col];
99 const bool IsSparse()
const {
return is_sparse_; }
105 bool is_sparse_ =
true;
106 std::vector<glop::ColIndex> non_zeros_;
130 class LinearProgrammingDispatcher;
174 return integer_variables_;
222 return total_num_simplex_iterations_;
230 if (optimal_constraints_.empty())
return nullptr;
231 return optimal_constraints_.back().get();
235 return optimal_constraints_;
241 bool BranchOnVar(IntegerVariable
var);
249 std::vector<IntegerLiteral>* integer_reason);
256 bool CreateLpFromConstraintManager();
266 bool AddCutFromConstraints(
267 const std::string&
name,
268 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
269 integer_multipliers);
272 bool PostprocessAndAddCut(
273 const std::string&
name,
const std::string& info,
274 IntegerVariable first_new_var, IntegerVariable first_slack,
275 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
280 void AddObjectiveCut();
283 void AddZeroHalfCuts();
286 void UpdateBoundsOfLpVariables();
291 bool ExactLpReasonning();
296 bool FillExactDualRayReason();
299 int64_t CalculateDegeneracy();
307 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
308 bool take_objective_into_account,
309 const std::vector<std::pair<glop::RowIndex, double>>& lp_multipliers,
317 bool ComputeNewLinearConstraint(
318 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
326 void AdjustNewLinearConstraint(
327 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
332 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
336 void ConvertToLinearConstraint(
365 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
372 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
376 void UpdateAverageReducedCosts();
387 void UpdateSimplexIterationLimit(
const int64_t min_iter,
388 const int64_t max_iter);
393 static constexpr
double kCpEpsilon = 1e-4;
396 static constexpr
double kLpEpsilon = 1e-6;
400 static constexpr
double kZeroTolerance = 1e-12;
408 struct LinearConstraintInternal {
413 LinearExpression integer_objective_;
414 IntegerValue integer_objective_offset_ = IntegerValue(0);
415 IntegerValue objective_infinity_norm_ = IntegerValue(0);
422 int64_t next_simplex_iter_ = 500;
428 ZeroHalfCutHelper zero_half_cut_helper_;
429 CoverCutHelper cover_cut_helper_;
430 IntegerRoundingCutHelper integer_rounding_cut_helper_;
431 LinearConstraint cut_;
433 ScatteredIntegerVector tmp_scattered_vector_;
435 std::vector<double> tmp_lp_values_;
436 std::vector<IntegerValue> tmp_var_lbs_;
437 std::vector<IntegerValue> tmp_var_ubs_;
438 std::vector<glop::RowIndex> tmp_slack_rows_;
439 std::vector<IntegerValue> tmp_slack_bounds_;
442 mutable std::vector<std::pair<glop::RowIndex, double>> tmp_cp_multipliers_;
451 std::vector<IntegerVariable> integer_variables_;
452 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
456 bool objective_is_defined_ =
false;
457 IntegerVariable objective_cp_;
460 const SatParameters& parameters_;
463 IntegerTrail* integer_trail_;
465 IntegerEncoder* integer_encoder_;
466 ModelRandomGenerator* random_;
469 ImpliedBoundsProcessor implied_bounds_processor_;
473 LinearProgrammingDispatcher* dispatcher_;
475 std::vector<IntegerLiteral> integer_reason_;
476 std::vector<IntegerLiteral> deductions_;
477 std::vector<IntegerLiteral> deductions_reason_;
484 int rev_optimal_constraints_size_ = 0;
485 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
490 int lp_solution_level_ = 0;
491 bool lp_solution_is_set_ =
false;
492 bool lp_solution_is_integer_ =
false;
493 double lp_objective_;
494 std::vector<double> lp_solution_;
495 std::vector<double> lp_reduced_cost_;
500 std::vector<double> level_zero_lp_solution_;
504 bool lp_at_level_zero_is_final_ =
false;
507 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
510 bool lp_constraint_is_registered_ =
false;
512 std::vector<CutGenerator> cut_generators_;
515 bool compute_reduced_cost_averages_ =
false;
516 int num_calls_since_reduced_cost_averages_reset_ = 0;
517 std::vector<double> sum_cost_up_;
518 std::vector<double> sum_cost_down_;
519 std::vector<int> num_cost_up_;
520 std::vector<int> num_cost_down_;
521 std::vector<double> rc_scores_;
525 int rev_rc_start_ = 0;
527 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
530 IncrementalAverage average_degeneracy_;
531 bool is_degenerate_ =
false;
534 int branching_frequency_ = 1;
535 int64_t count_since_last_branching_ = 0;
539 int64_t total_num_simplex_iterations_ = 0;
542 int64_t num_solves_ = 0;
543 std::vector<int64_t> num_solves_by_status_;
552 :
public absl::flat_hash_map<IntegerVariable,
553 LinearProgrammingConstraint*> {
560 :
public std::vector<LinearProgrammingConstraint*> {
573 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
574 const std::vector<Literal>& literals, Model*
model);
581 const std::vector<int>& tails,
582 const std::vector<int>& heads,
583 const std::vector<Literal>& literals,
584 const std::vector<int64_t>& demands,
589 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_ std::string DimensionString() const
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
LinearProgrammingConstraintLpSolution()
Class that owns everything related to a particular optimization model.
const std::vector< IntegerVariable > & integer_variables() const
int64_t total_num_simplex_iterations() const
bool SolutionIsInteger() const
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue)
bool Propagate() override
std::function< IntegerLiteral()> HeuristicLpMostInfeasibleBinary(Model *model)
IntegerSumLE * LatestOptimalConstraintOrNull() const
void RegisterWith(Model *model)
CutGenerator CreateCVRPCutGenerator(int num_nodes, const std::vector< int > &tails, const std::vector< int > &heads, const std::vector< Literal > &literals, const std::vector< int64_t > &demands, int64_t capacity, Model *model)
LinearProgrammingConstraintCollection()
const std::vector< std::unique_ptr< IntegerSumLE > > & OptimalConstraints() const
std::vector< std::pair< glop::ColIndex, IntegerValue > > GetTerms()
void ClearAndResize(int size)
std::string GetDimensionString() const
IntegerVariable ObjectiveVariable() const
double GetSolutionReducedCost(IntegerVariable variable) const
double SolutionObjectiveValue() const
std::string Statistics() const
CutGenerator CreateStronglyConnectedGraphCutGenerator(int num_nodes, const std::vector< int > &tails, const std::vector< int > &heads, const std::vector< Literal > &literals, Model *model)
std::function< IntegerLiteral()> HeuristicLpReducedCostAverageBranching()
std::function< IntegerLiteral()> HeuristicLpReducedCostBinary(Model *model)
IntegerValue new_obj_bound
const bool IsSparse() const
bool IncrementalPropagate(const std::vector< int > &watch_indices) override
void SetObjectiveCoefficient(IntegerVariable ivar, IntegerValue coeff)
IntegerValue operator[](glop::ColIndex col) const
void SetMainObjectiveVariable(IntegerVariable ivar)
glop::RowIndex ConstraintIndex
void AddLinearConstraint(const LinearConstraint &ct)
Collection of objects used to extend the Constraint Solver library.
void SetLevel(int level) override
bool Add(glop::ColIndex col, IntegerValue value)
double CurrentAverage() const
LinearProgrammingConstraint(Model *model)
void ConvertToLinearConstraint(const std::vector< IntegerVariable > &integer_variables, IntegerValue upper_bound, LinearConstraint *result)
double average_degeneracy() const
bool AddLinearExpressionMultiple(IntegerValue multiplier, const std::vector< std::pair< glop::ColIndex, IntegerValue >> &terms)
void AddCutGenerator(CutGenerator generator)
double GetSolutionValue(IntegerVariable variable) const
LinearProgrammingDispatcher(Model *model)
glop::ProblemStatus status