14 #ifndef OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_
15 #define OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_
21 #include "absl/container/flat_hash_map.h"
76 IntegerValue multiplier,
77 const std::vector<std::pair<glop::ColIndex, IntegerValue>>& terms);
86 const std::vector<IntegerVariable>& integer_variables,
90 std::vector<std::pair<glop::ColIndex, IntegerValue>>
GetTerms();
94 return dense_vector_[
col];
101 bool is_sparse_ =
true;
102 std::vector<glop::ColIndex> non_zeros_;
126 class LinearProgrammingDispatcher;
170 return integer_variables_;
218 return total_num_simplex_iterations_;
224 bool BranchOnVar(IntegerVariable
var);
232 std::vector<IntegerLiteral>* integer_reason);
239 bool CreateLpFromConstraintManager();
249 bool AddCutFromConstraints(
250 const std::string&
name,
251 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
252 integer_multipliers);
255 bool PostprocessAndAddCut(
256 const std::string&
name,
const std::string& info,
257 IntegerVariable first_new_var, IntegerVariable first_slack,
258 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
265 void AddZeroHalfCuts();
268 void UpdateBoundsOfLpVariables();
273 bool ExactLpReasonning();
278 bool FillExactDualRayReason();
281 int64 CalculateDegeneracy();
289 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
290 bool take_objective_into_account,
292 int max_pow = 62)
const;
299 bool ComputeNewLinearConstraint(
300 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
303 IntegerValue* upper_bound)
const;
308 void AdjustNewLinearConstraint(
309 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
311 IntegerValue* upper_bound)
const;
314 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
318 void ConvertToLinearConstraint(
347 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
354 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
358 void UpdateAverageReducedCosts();
369 void UpdateSimplexIterationLimit(
const int64 min_iter,
const int64 max_iter);
374 static const double kCpEpsilon;
377 static const double kLpEpsilon;
385 struct LinearConstraintInternal {
390 LinearExpression integer_objective_;
391 IntegerValue integer_objective_offset_ = IntegerValue(0);
392 IntegerValue objective_infinity_norm_ = IntegerValue(0);
399 int64 next_simplex_iter_ = 500;
405 ZeroHalfCutHelper zero_half_cut_helper_;
406 CoverCutHelper cover_cut_helper_;
407 IntegerRoundingCutHelper integer_rounding_cut_helper_;
408 LinearConstraint cut_;
410 ScatteredIntegerVector tmp_scattered_vector_;
412 std::vector<double> tmp_lp_values_;
413 std::vector<IntegerValue> tmp_var_lbs_;
414 std::vector<IntegerValue> tmp_var_ubs_;
415 std::vector<glop::RowIndex> tmp_slack_rows_;
416 std::vector<IntegerValue> tmp_slack_bounds_;
424 std::vector<IntegerVariable> integer_variables_;
425 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
429 bool objective_is_defined_ =
false;
430 IntegerVariable objective_cp_;
433 const SatParameters& sat_parameters_;
436 IntegerTrail* integer_trail_;
438 IntegerEncoder* integer_encoder_;
439 ModelRandomGenerator* random_;
442 ImpliedBoundsProcessor implied_bounds_processor_;
446 LinearProgrammingDispatcher* dispatcher_;
448 std::vector<IntegerLiteral> integer_reason_;
449 std::vector<IntegerLiteral> deductions_;
450 std::vector<IntegerLiteral> deductions_reason_;
457 int rev_optimal_constraints_size_ = 0;
458 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
463 int lp_solution_level_ = 0;
464 bool lp_solution_is_set_ =
false;
465 bool lp_solution_is_integer_ =
false;
466 double lp_objective_;
467 std::vector<double> lp_solution_;
468 std::vector<double> lp_reduced_cost_;
473 std::vector<double> level_zero_lp_solution_;
477 bool lp_at_level_zero_is_final_ =
false;
480 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
483 bool lp_constraint_is_registered_ =
false;
485 std::vector<CutGenerator> cut_generators_;
488 bool compute_reduced_cost_averages_ =
false;
489 int num_calls_since_reduced_cost_averages_reset_ = 0;
490 std::vector<double> sum_cost_up_;
491 std::vector<double> sum_cost_down_;
492 std::vector<int> num_cost_up_;
493 std::vector<int> num_cost_down_;
494 std::vector<double> rc_scores_;
498 int rev_rc_start_ = 0;
500 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
503 IncrementalAverage average_degeneracy_;
504 bool is_degenerate_ =
false;
507 int branching_frequency_ = 1;
508 int64 count_since_last_branching_ = 0;
512 int64 total_num_simplex_iterations_ = 0;
515 std::vector<int64> num_solves_by_status_;
524 :
public absl::flat_hash_map<IntegerVariable,
525 LinearProgrammingConstraint*> {
532 :
public std::vector<LinearProgrammingConstraint*> {
545 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
546 const std::vector<Literal>& literals, Model*
model);
553 const std::vector<int>& tails,
554 const std::vector<int>& heads,
555 const std::vector<Literal>& literals,
556 const std::vector<int64>& demands,
561 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_