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];
103 bool is_sparse_ =
true;
104 std::vector<glop::ColIndex> non_zeros_;
128 class LinearProgrammingDispatcher;
172 return integer_variables_;
220 return total_num_simplex_iterations_;
226 bool BranchOnVar(IntegerVariable
var);
234 std::vector<IntegerLiteral>* integer_reason);
241 bool CreateLpFromConstraintManager();
251 bool AddCutFromConstraints(
252 const std::string&
name,
253 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
254 integer_multipliers);
257 bool PostprocessAndAddCut(
258 const std::string&
name,
const std::string& info,
259 IntegerVariable first_new_var, IntegerVariable first_slack,
260 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
267 void AddZeroHalfCuts();
270 void UpdateBoundsOfLpVariables();
275 bool ExactLpReasonning();
280 bool FillExactDualRayReason();
283 int64_t CalculateDegeneracy();
291 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
292 bool take_objective_into_account,
293 const std::vector<std::pair<glop::RowIndex, double>>& lp_multipliers,
301 bool ComputeNewLinearConstraint(
302 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
310 void AdjustNewLinearConstraint(
311 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
316 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
320 void ConvertToLinearConstraint(
349 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
356 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
360 void UpdateAverageReducedCosts();
371 void UpdateSimplexIterationLimit(
const int64_t min_iter,
372 const int64_t max_iter);
377 static constexpr
double kCpEpsilon = 1e-4;
380 static constexpr
double kLpEpsilon = 1e-6;
384 static constexpr
double kZeroTolerance = 1e-12;
392 struct LinearConstraintInternal {
397 LinearExpression integer_objective_;
398 IntegerValue integer_objective_offset_ = IntegerValue(0);
399 IntegerValue objective_infinity_norm_ = IntegerValue(0);
406 int64_t next_simplex_iter_ = 500;
412 ZeroHalfCutHelper zero_half_cut_helper_;
413 CoverCutHelper cover_cut_helper_;
414 IntegerRoundingCutHelper integer_rounding_cut_helper_;
415 LinearConstraint cut_;
417 ScatteredIntegerVector tmp_scattered_vector_;
419 std::vector<double> tmp_lp_values_;
420 std::vector<IntegerValue> tmp_var_lbs_;
421 std::vector<IntegerValue> tmp_var_ubs_;
422 std::vector<glop::RowIndex> tmp_slack_rows_;
423 std::vector<IntegerValue> tmp_slack_bounds_;
426 mutable std::vector<std::pair<glop::RowIndex, double>> tmp_cp_multipliers_;
435 std::vector<IntegerVariable> integer_variables_;
436 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
440 bool objective_is_defined_ =
false;
441 IntegerVariable objective_cp_;
444 const SatParameters& sat_parameters_;
447 IntegerTrail* integer_trail_;
449 IntegerEncoder* integer_encoder_;
450 ModelRandomGenerator* random_;
453 ImpliedBoundsProcessor implied_bounds_processor_;
457 LinearProgrammingDispatcher* dispatcher_;
459 std::vector<IntegerLiteral> integer_reason_;
460 std::vector<IntegerLiteral> deductions_;
461 std::vector<IntegerLiteral> deductions_reason_;
468 int rev_optimal_constraints_size_ = 0;
469 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
474 int lp_solution_level_ = 0;
475 bool lp_solution_is_set_ =
false;
476 bool lp_solution_is_integer_ =
false;
477 double lp_objective_;
478 std::vector<double> lp_solution_;
479 std::vector<double> lp_reduced_cost_;
484 std::vector<double> level_zero_lp_solution_;
488 bool lp_at_level_zero_is_final_ =
false;
491 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
494 bool lp_constraint_is_registered_ =
false;
496 std::vector<CutGenerator> cut_generators_;
499 bool compute_reduced_cost_averages_ =
false;
500 int num_calls_since_reduced_cost_averages_reset_ = 0;
501 std::vector<double> sum_cost_up_;
502 std::vector<double> sum_cost_down_;
503 std::vector<int> num_cost_up_;
504 std::vector<int> num_cost_down_;
505 std::vector<double> rc_scores_;
509 int rev_rc_start_ = 0;
511 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
514 IncrementalAverage average_degeneracy_;
515 bool is_degenerate_ =
false;
518 int branching_frequency_ = 1;
519 int64_t count_since_last_branching_ = 0;
523 int64_t total_num_simplex_iterations_ = 0;
526 std::vector<int64_t> num_solves_by_status_;
535 :
public absl::flat_hash_map<IntegerVariable,
536 LinearProgrammingConstraint*> {
543 :
public std::vector<LinearProgrammingConstraint*> {
556 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
557 const std::vector<Literal>& literals, Model*
model);
564 const std::vector<int>& tails,
565 const std::vector<int>& heads,
566 const std::vector<Literal>& literals,
567 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::function< IntegerLiteral()> HeuristicLpReducedCostBinary(Model *model)
~LinearProgrammingConstraint() override
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)
void ClearAndResize(int size)
IntegerValue operator[](glop::ColIndex col) const
std::vector< std::pair< glop::ColIndex, IntegerValue > > GetTerms()
bool AddLinearExpressionMultiple(IntegerValue multiplier, const std::vector< std::pair< glop::ColIndex, IntegerValue >> &terms)
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()