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_;
425 std::vector<IntegerVariable> integer_variables_;
426 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
430 bool objective_is_defined_ =
false;
431 IntegerVariable objective_cp_;
434 const SatParameters& sat_parameters_;
437 IntegerTrail* integer_trail_;
439 IntegerEncoder* integer_encoder_;
440 ModelRandomGenerator* random_;
443 ImpliedBoundsProcessor implied_bounds_processor_;
447 LinearProgrammingDispatcher* dispatcher_;
449 std::vector<IntegerLiteral> integer_reason_;
450 std::vector<IntegerLiteral> deductions_;
451 std::vector<IntegerLiteral> deductions_reason_;
458 int rev_optimal_constraints_size_ = 0;
459 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
464 int lp_solution_level_ = 0;
465 bool lp_solution_is_set_ =
false;
466 bool lp_solution_is_integer_ =
false;
467 double lp_objective_;
468 std::vector<double> lp_solution_;
469 std::vector<double> lp_reduced_cost_;
474 std::vector<double> level_zero_lp_solution_;
478 bool lp_at_level_zero_is_final_ =
false;
481 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
484 bool lp_constraint_is_registered_ =
false;
486 std::vector<CutGenerator> cut_generators_;
489 bool compute_reduced_cost_averages_ =
false;
490 int num_calls_since_reduced_cost_averages_reset_ = 0;
491 std::vector<double> sum_cost_up_;
492 std::vector<double> sum_cost_down_;
493 std::vector<int> num_cost_up_;
494 std::vector<int> num_cost_down_;
495 std::vector<double> rc_scores_;
499 int rev_rc_start_ = 0;
501 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
504 IncrementalAverage average_degeneracy_;
505 bool is_degenerate_ =
false;
508 int branching_frequency_ = 1;
509 int64 count_since_last_branching_ = 0;
513 int64 total_num_simplex_iterations_ = 0;
516 std::vector<int64> num_solves_by_status_;
525 :
public absl::flat_hash_map<IntegerVariable,
526 LinearProgrammingConstraint*> {
533 :
public std::vector<LinearProgrammingConstraint*> {
546 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
547 const std::vector<Literal>& literals, Model*
model);
554 const std::vector<int>& tails,
555 const std::vector<int>& heads,
556 const std::vector<Literal>& literals,
557 const std::vector<int64>& demands,
562 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_