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_;
217 bool BranchOnVar(IntegerVariable
var);
225 std::vector<IntegerLiteral>* integer_reason);
232 bool CreateLpFromConstraintManager();
242 bool AddCutFromConstraints(
243 const std::string&
name,
244 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
245 integer_multipliers);
248 bool PostprocessAndAddCut(
249 const std::string&
name,
const std::string& info,
250 IntegerVariable first_new_var, IntegerVariable first_slack,
251 const std::vector<ImpliedBoundsProcessor::SlackInfo>& ib_slack_infos,
258 void AddZeroHalfCuts();
261 void UpdateBoundsOfLpVariables();
266 bool ExactLpReasonning();
271 bool FillExactDualRayReason();
274 int64 CalculateDegeneracy();
282 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
283 bool take_objective_into_account,
285 int max_pow = 62)
const;
292 bool ComputeNewLinearConstraint(
293 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
296 IntegerValue* upper_bound)
const;
301 void AdjustNewLinearConstraint(
302 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
304 IntegerValue* upper_bound)
const;
307 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
311 void ConvertToLinearConstraint(
340 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
347 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
351 void UpdateAverageReducedCosts();
354 LiteralIndex LPReducedCostAverageDecision();
362 void UpdateSimplexIterationLimit(
const int64 min_iter,
const int64 max_iter);
367 static const double kCpEpsilon;
370 static const double kLpEpsilon;
378 struct LinearConstraintInternal {
383 LinearExpression integer_objective_;
384 IntegerValue objective_infinity_norm_ = IntegerValue(0);
391 int64 next_simplex_iter_ = 500;
397 ZeroHalfCutHelper zero_half_cut_helper_;
398 CoverCutHelper cover_cut_helper_;
399 IntegerRoundingCutHelper integer_rounding_cut_helper_;
400 LinearConstraint cut_;
402 ScatteredIntegerVector tmp_scattered_vector_;
404 std::vector<double> tmp_lp_values_;
405 std::vector<IntegerValue> tmp_var_lbs_;
406 std::vector<IntegerValue> tmp_var_ubs_;
407 std::vector<glop::RowIndex> tmp_slack_rows_;
408 std::vector<IntegerValue> tmp_slack_bounds_;
416 std::vector<IntegerVariable> integer_variables_;
417 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
421 bool objective_is_defined_ =
false;
422 IntegerVariable objective_cp_;
425 const SatParameters& sat_parameters_;
428 IntegerTrail* integer_trail_;
430 SearchHeuristicsVector* model_heuristics_;
431 IntegerEncoder* integer_encoder_;
432 ModelRandomGenerator* random_;
435 ImpliedBoundsProcessor implied_bounds_processor_;
439 LinearProgrammingDispatcher* dispatcher_;
441 std::vector<IntegerLiteral> integer_reason_;
442 std::vector<IntegerLiteral> deductions_;
443 std::vector<IntegerLiteral> deductions_reason_;
450 int rev_optimal_constraints_size_ = 0;
451 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
456 int lp_solution_level_ = 0;
457 bool lp_solution_is_set_ =
false;
458 bool lp_solution_is_integer_ =
false;
459 double lp_objective_;
460 std::vector<double> lp_solution_;
461 std::vector<double> lp_reduced_cost_;
466 std::vector<double> level_zero_lp_solution_;
470 bool lp_at_level_zero_is_final_ =
false;
473 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
476 bool lp_constraint_is_registered_ =
false;
478 std::vector<CutGenerator> cut_generators_;
481 bool compute_reduced_cost_averages_ =
false;
482 int num_calls_since_reduced_cost_averages_reset_ = 0;
483 std::vector<double> sum_cost_up_;
484 std::vector<double> sum_cost_down_;
485 std::vector<int> num_cost_up_;
486 std::vector<int> num_cost_down_;
487 std::vector<double> rc_scores_;
491 int rev_rc_start_ = 0;
493 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
496 IncrementalAverage average_degeneracy_;
497 bool is_degenerate_ =
false;
500 int branching_frequency_ = 1;
501 int64 count_since_last_branching_ = 0;
505 int64 total_num_simplex_iterations_ = 0;
514 :
public absl::flat_hash_map<IntegerVariable,
515 LinearProgrammingConstraint*> {
522 :
public std::vector<LinearProgrammingConstraint*> {
535 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
536 const std::vector<Literal>& literals, Model*
model);
543 const std::vector<int>& tails,
544 const std::vector<int>& heads,
545 const std::vector<Literal>& literals,
546 const std::vector<int64>& demands,
551 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_