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"
77 IntegerValue multiplier,
78 const std::vector<std::pair<glop::ColIndex, IntegerValue>>& terms);
87 const std::vector<IntegerVariable>& integer_variables,
91 std::vector<std::pair<glop::ColIndex, IntegerValue>>
GetTerms();
95 return dense_vector_[
col];
102 bool is_sparse_ =
true;
103 std::vector<glop::ColIndex> non_zeros_;
127 class LinearProgrammingDispatcher;
171 return integer_variables_;
219 return total_num_simplex_iterations_;
225 bool BranchOnVar(IntegerVariable
var);
233 std::vector<IntegerLiteral>* integer_reason);
240 bool CreateLpFromConstraintManager();
250 bool AddCutFromConstraints(
251 const std::string&
name,
252 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
253 integer_multipliers);
256 bool PostprocessAndAddCut(
257 const std::string&
name,
const std::string& info,
258 IntegerVariable first_new_var, IntegerVariable first_slack,
259 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
266 void AddZeroHalfCuts();
269 void UpdateBoundsOfLpVariables();
274 bool ExactLpReasonning();
279 bool FillExactDualRayReason();
282 int64 CalculateDegeneracy();
290 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
291 bool take_objective_into_account,
293 int max_pow = 62)
const;
300 bool ComputeNewLinearConstraint(
301 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
304 IntegerValue* upper_bound)
const;
309 void AdjustNewLinearConstraint(
310 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
312 IntegerValue* upper_bound)
const;
315 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
319 void ConvertToLinearConstraint(
348 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
355 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
359 void UpdateAverageReducedCosts();
370 void UpdateSimplexIterationLimit(
const int64 min_iter,
const int64 max_iter);
375 static const double kCpEpsilon;
378 static const double kLpEpsilon;
386 struct LinearConstraintInternal {
391 LinearExpression integer_objective_;
392 IntegerValue integer_objective_offset_ = IntegerValue(0);
393 IntegerValue objective_infinity_norm_ = IntegerValue(0);
400 int64 next_simplex_iter_ = 500;
406 ZeroHalfCutHelper zero_half_cut_helper_;
407 CoverCutHelper cover_cut_helper_;
408 IntegerRoundingCutHelper integer_rounding_cut_helper_;
409 LinearConstraint cut_;
411 ScatteredIntegerVector tmp_scattered_vector_;
413 std::vector<double> tmp_lp_values_;
414 std::vector<IntegerValue> tmp_var_lbs_;
415 std::vector<IntegerValue> tmp_var_ubs_;
416 std::vector<glop::RowIndex> tmp_slack_rows_;
417 std::vector<IntegerValue> tmp_slack_bounds_;
426 std::vector<IntegerVariable> integer_variables_;
427 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
431 bool objective_is_defined_ =
false;
432 IntegerVariable objective_cp_;
435 const SatParameters& sat_parameters_;
438 IntegerTrail* integer_trail_;
440 IntegerEncoder* integer_encoder_;
441 ModelRandomGenerator* random_;
444 ImpliedBoundsProcessor implied_bounds_processor_;
448 LinearProgrammingDispatcher* dispatcher_;
450 std::vector<IntegerLiteral> integer_reason_;
451 std::vector<IntegerLiteral> deductions_;
452 std::vector<IntegerLiteral> deductions_reason_;
459 int rev_optimal_constraints_size_ = 0;
460 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
465 int lp_solution_level_ = 0;
466 bool lp_solution_is_set_ =
false;
467 bool lp_solution_is_integer_ =
false;
468 double lp_objective_;
469 std::vector<double> lp_solution_;
470 std::vector<double> lp_reduced_cost_;
475 std::vector<double> level_zero_lp_solution_;
479 bool lp_at_level_zero_is_final_ =
false;
482 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
485 bool lp_constraint_is_registered_ =
false;
487 std::vector<CutGenerator> cut_generators_;
490 bool compute_reduced_cost_averages_ =
false;
491 int num_calls_since_reduced_cost_averages_reset_ = 0;
492 std::vector<double> sum_cost_up_;
493 std::vector<double> sum_cost_down_;
494 std::vector<int> num_cost_up_;
495 std::vector<int> num_cost_down_;
496 std::vector<double> rc_scores_;
500 int rev_rc_start_ = 0;
502 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
505 IncrementalAverage average_degeneracy_;
506 bool is_degenerate_ =
false;
509 int branching_frequency_ = 1;
510 int64 count_since_last_branching_ = 0;
514 int64 total_num_simplex_iterations_ = 0;
517 std::vector<int64> num_solves_by_status_;
526 :
public absl::flat_hash_map<IntegerVariable,
527 LinearProgrammingConstraint*> {
534 :
public std::vector<LinearProgrammingConstraint*> {
547 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
548 const std::vector<Literal>& literals, Model*
model);
555 const std::vector<int>& tails,
556 const std::vector<int>& heads,
557 const std::vector<Literal>& literals,
558 const std::vector<int64>& demands,
563 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_