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_;
130class 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_;
432 LinearConstraint tmp_constraint_;
434 ScatteredIntegerVector tmp_scattered_vector_;
436 std::vector<double> tmp_lp_values_;
437 std::vector<IntegerValue> tmp_var_lbs_;
438 std::vector<IntegerValue> tmp_var_ubs_;
439 std::vector<glop::RowIndex> tmp_slack_rows_;
440 std::vector<IntegerValue> tmp_slack_bounds_;
441 std::vector<ImpliedBoundsProcessor::SlackInfo> tmp_ib_slack_infos_;
442 std::vector<std::pair<glop::ColIndex, IntegerValue>> tmp_terms_;
445 std::vector<std::pair<glop::RowIndex, double>> tmp_lp_multipliers_;
446 std::vector<std::pair<glop::RowIndex, IntegerValue>> tmp_integer_multipliers_;
449 mutable std::vector<std::pair<glop::RowIndex, double>> tmp_cp_multipliers_;
458 std::vector<IntegerVariable> integer_variables_;
459 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
463 bool objective_is_defined_ =
false;
464 IntegerVariable objective_cp_;
467 const SatParameters& parameters_;
470 IntegerTrail* integer_trail_;
472 IntegerEncoder* integer_encoder_;
473 ModelRandomGenerator* random_;
476 ImpliedBoundsProcessor implied_bounds_processor_;
480 LinearProgrammingDispatcher* dispatcher_;
482 std::vector<IntegerLiteral> integer_reason_;
483 std::vector<IntegerLiteral> deductions_;
484 std::vector<IntegerLiteral> deductions_reason_;
491 int rev_optimal_constraints_size_ = 0;
492 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
497 int lp_solution_level_ = 0;
498 bool lp_solution_is_set_ =
false;
499 bool lp_solution_is_integer_ =
false;
500 double lp_objective_;
501 std::vector<double> lp_solution_;
502 std::vector<double> lp_reduced_cost_;
507 std::vector<double> level_zero_lp_solution_;
511 bool lp_at_level_zero_is_final_ =
false;
514 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
517 bool lp_constraint_is_registered_ =
false;
519 std::vector<CutGenerator> cut_generators_;
522 bool compute_reduced_cost_averages_ =
false;
523 int num_calls_since_reduced_cost_averages_reset_ = 0;
524 std::vector<double> sum_cost_up_;
525 std::vector<double> sum_cost_down_;
526 std::vector<int> num_cost_up_;
527 std::vector<int> num_cost_down_;
528 std::vector<double> rc_scores_;
532 int rev_rc_start_ = 0;
534 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
537 IncrementalAverage average_degeneracy_;
538 bool is_degenerate_ =
false;
541 int branching_frequency_ = 1;
542 int64_t count_since_last_branching_ = 0;
546 int64_t total_num_simplex_iterations_ = 0;
549 int64_t num_solves_ = 0;
550 std::vector<int64_t> num_solves_by_status_;
559 :
public absl::flat_hash_map<IntegerVariable,
560 LinearProgrammingConstraint*> {
567 :
public std::vector<LinearProgrammingConstraint*> {
580 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
581 const std::vector<Literal>& literals, Model*
model);
588 const std::vector<int>& tails,
589 const std::vector<int>& heads,
590 const std::vector<Literal>& literals,
591 const std::vector<int64_t>& demands,
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
std::string GetDimensionString() const
double CurrentAverage() const
LinearProgrammingConstraintCollection()
bool Propagate() override
double average_degeneracy() const
std::string DimensionString() const
double SolutionObjectiveValue() const
IntegerSumLE * LatestOptimalConstraintOrNull() const
double GetSolutionValue(IntegerVariable variable) const
void RegisterWith(Model *model)
int64_t total_num_simplex_iterations() const
glop::RowIndex ConstraintIndex
std::function< IntegerLiteral()> HeuristicLpReducedCostAverageBranching()
bool SolutionIsInteger() const
LinearProgrammingConstraint(Model *model)
std::string Statistics() const
std::function< IntegerLiteral()> HeuristicLpReducedCostBinary(Model *model)
IntegerVariable ObjectiveVariable() const
void AddLinearConstraint(const LinearConstraint &ct)
bool IncrementalPropagate(const std::vector< int > &watch_indices) override
void SetLevel(int level) override
std::function< IntegerLiteral()> HeuristicLpMostInfeasibleBinary(Model *model)
const std::vector< std::unique_ptr< IntegerSumLE > > & OptimalConstraints() const
const std::vector< IntegerVariable > & integer_variables() const
void SetMainObjectiveVariable(IntegerVariable ivar)
void SetObjectiveCoefficient(IntegerVariable ivar, IntegerValue coeff)
double GetSolutionReducedCost(IntegerVariable variable) const
void AddCutGenerator(CutGenerator generator)
LinearProgrammingDispatcher(Model *model)
Class that owns everything related to a particular optimization model.
void ConvertToLinearConstraint(const std::vector< IntegerVariable > &integer_variables, IntegerValue upper_bound, LinearConstraint *result)
bool Add(glop::ColIndex col, IntegerValue value)
bool AddLinearExpressionMultiple(IntegerValue multiplier, const std::vector< std::pair< glop::ColIndex, IntegerValue > > &terms)
const bool IsSparse() const
void ClearAndResize(int size)
IntegerValue operator[](glop::ColIndex col) const
std::vector< std::pair< glop::ColIndex, IntegerValue > > GetTerms()
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)
constexpr IntegerValue kMinIntegerValue(-kMaxIntegerValue)
CutGenerator CreateStronglyConnectedGraphCutGenerator(int num_nodes, const std::vector< int > &tails, const std::vector< int > &heads, const std::vector< Literal > &literals, Model *model)
Collection of objects used to extend the Constraint Solver library.
glop::ProblemStatus status
IntegerValue new_obj_bound
LinearProgrammingConstraintLpSolution()