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;
173 return integer_variables_;
221 return total_num_simplex_iterations_;
230 bool BranchOnVar(IntegerVariable
var);
238 std::vector<IntegerLiteral>* integer_reason);
245 bool CreateLpFromConstraintManager();
255 bool AddCutFromConstraints(
256 const std::string&
name,
257 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
258 integer_multipliers);
261 bool PostprocessAndAddCut(
262 const std::string&
name,
const std::string& info,
263 IntegerVariable first_new_var, IntegerVariable first_slack,
264 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
271 void AddZeroHalfCuts();
274 void UpdateBoundsOfLpVariables();
279 bool ExactLpReasonning();
284 bool FillExactDualRayReason();
287 int64_t CalculateDegeneracy();
295 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
296 bool take_objective_into_account,
297 const std::vector<std::pair<glop::RowIndex, double>>& lp_multipliers,
305 bool ComputeNewLinearConstraint(
306 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
314 void AdjustNewLinearConstraint(
315 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
320 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
324 void ConvertToLinearConstraint(
353 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
360 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
364 void UpdateAverageReducedCosts();
375 void UpdateSimplexIterationLimit(
const int64_t min_iter,
376 const int64_t max_iter);
381 static constexpr double kCpEpsilon = 1e-4;
384 static constexpr double kLpEpsilon = 1e-6;
388 static constexpr double kZeroTolerance = 1e-12;
396 struct LinearConstraintInternal {
401 LinearExpression integer_objective_;
402 IntegerValue integer_objective_offset_ = IntegerValue(0);
403 IntegerValue objective_infinity_norm_ = IntegerValue(0);
410 int64_t next_simplex_iter_ = 500;
416 ZeroHalfCutHelper zero_half_cut_helper_;
417 CoverCutHelper cover_cut_helper_;
418 IntegerRoundingCutHelper integer_rounding_cut_helper_;
419 LinearConstraint cut_;
421 ScatteredIntegerVector tmp_scattered_vector_;
423 std::vector<double> tmp_lp_values_;
424 std::vector<IntegerValue> tmp_var_lbs_;
425 std::vector<IntegerValue> tmp_var_ubs_;
426 std::vector<glop::RowIndex> tmp_slack_rows_;
427 std::vector<IntegerValue> tmp_slack_bounds_;
430 mutable std::vector<std::pair<glop::RowIndex, double>> tmp_cp_multipliers_;
439 std::vector<IntegerVariable> integer_variables_;
440 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
444 bool objective_is_defined_ =
false;
445 IntegerVariable objective_cp_;
448 const SatParameters& sat_parameters_;
451 IntegerTrail* integer_trail_;
453 IntegerEncoder* integer_encoder_;
454 ModelRandomGenerator* random_;
457 ImpliedBoundsProcessor implied_bounds_processor_;
461 LinearProgrammingDispatcher* dispatcher_;
463 std::vector<IntegerLiteral> integer_reason_;
464 std::vector<IntegerLiteral> deductions_;
465 std::vector<IntegerLiteral> deductions_reason_;
472 int rev_optimal_constraints_size_ = 0;
473 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
478 int lp_solution_level_ = 0;
479 bool lp_solution_is_set_ =
false;
480 bool lp_solution_is_integer_ =
false;
481 double lp_objective_;
482 std::vector<double> lp_solution_;
483 std::vector<double> lp_reduced_cost_;
488 std::vector<double> level_zero_lp_solution_;
492 bool lp_at_level_zero_is_final_ =
false;
495 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
498 bool lp_constraint_is_registered_ =
false;
500 std::vector<CutGenerator> cut_generators_;
503 bool compute_reduced_cost_averages_ =
false;
504 int num_calls_since_reduced_cost_averages_reset_ = 0;
505 std::vector<double> sum_cost_up_;
506 std::vector<double> sum_cost_down_;
507 std::vector<int> num_cost_up_;
508 std::vector<int> num_cost_down_;
509 std::vector<double> rc_scores_;
513 int rev_rc_start_ = 0;
515 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
518 IncrementalAverage average_degeneracy_;
519 bool is_degenerate_ =
false;
522 int branching_frequency_ = 1;
523 int64_t count_since_last_branching_ = 0;
527 int64_t total_num_simplex_iterations_ = 0;
530 int64_t num_solves_ = 0;
531 std::vector<int64_t> num_solves_by_status_;
540 :
public absl::flat_hash_map<IntegerVariable,
541 LinearProgrammingConstraint*> {
548 :
public std::vector<LinearProgrammingConstraint*> {
561 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
562 const std::vector<Literal>& literals, Model*
model);
569 const std::vector<int>& tails,
570 const std::vector<int>& heads,
571 const std::vector<Literal>& literals,
572 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
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)
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< 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()