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"
122 return integer_variables_;
169 bool BranchOnVar(IntegerVariable
var);
177 std::vector<IntegerLiteral>* integer_reason);
184 bool CreateLpFromConstraintManager();
194 bool AddCutFromConstraints(
195 const std::string&
name,
196 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
197 integer_multipliers);
208 void UpdateBoundsOfLpVariables();
213 bool ExactLpReasonning();
218 bool FillExactDualRayReason();
221 int64 CalculateDegeneracy();
229 std::vector<std::pair<glop::RowIndex, IntegerValue>> ScaleLpMultiplier(
230 bool take_objective_into_account,
232 int max_pow = 62)
const;
239 bool ComputeNewLinearConstraint(
240 const std::vector<std::pair<glop::RowIndex, IntegerValue>>&
243 IntegerValue* upper_bound)
const;
248 void AdjustNewLinearConstraint(
249 std::vector<std::pair<glop::RowIndex, IntegerValue>>* integer_multipliers,
251 IntegerValue* upper_bound)
const;
254 using LinearExpression = std::vector<std::pair<glop::ColIndex, IntegerValue>>;
258 void ConvertToLinearConstraint(
287 void ReducedCostStrengtheningDeductions(
double cp_objective_delta);
294 glop::ColIndex GetOrCreateMirrorVariable(IntegerVariable positive_variable);
298 void UpdateAverageReducedCosts();
301 LiteralIndex LPReducedCostAverageDecision();
309 void UpdateSimplexIterationLimit(
const int64 min_iter,
const int64 max_iter);
314 static const double kCpEpsilon;
317 static const double kLpEpsilon;
325 struct LinearConstraintInternal {
330 LinearExpression integer_objective_;
331 IntegerValue objective_infinity_norm_ = IntegerValue(0);
338 int64 next_simplex_iter_ = 500;
344 IntegerRoundingCutHelper integer_rounding_cut_helper_;
345 LinearConstraint cut_;
347 std::vector<double> tmp_lp_values_;
348 std::vector<IntegerValue> tmp_var_lbs_;
349 std::vector<IntegerValue> tmp_var_ubs_;
350 std::vector<glop::RowIndex> tmp_slack_rows_;
351 std::vector<IntegerValue> tmp_slack_bounds_;
357 std::vector<IntegerVariable> integer_variables_;
358 absl::flat_hash_map<IntegerVariable, glop::ColIndex> mirror_lp_variable_;
362 bool objective_is_defined_ =
false;
363 IntegerVariable objective_cp_;
366 const SatParameters& sat_parameters_;
369 IntegerTrail* integer_trail_;
371 SearchHeuristicsVector* model_heuristics_;
372 IntegerEncoder* integer_encoder_;
373 ModelRandomGenerator* random_;
376 ImpliedBoundsProcessor implied_bounds_processor_;
380 LinearProgrammingDispatcher* dispatcher_;
382 std::vector<IntegerLiteral> integer_reason_;
383 std::vector<IntegerLiteral> deductions_;
384 std::vector<IntegerLiteral> deductions_reason_;
391 int rev_optimal_constraints_size_ = 0;
392 std::vector<std::unique_ptr<IntegerSumLE>> optimal_constraints_;
397 int lp_solution_level_ = 0;
398 bool lp_solution_is_set_ =
false;
399 bool lp_solution_is_integer_ =
false;
400 double lp_objective_;
401 std::vector<double> lp_solution_;
402 std::vector<double> lp_reduced_cost_;
407 std::vector<double> level_zero_lp_solution_;
411 bool lp_at_level_zero_is_final_ =
false;
414 LinearProgrammingConstraintLpSolution& expanded_lp_solution_;
417 bool lp_constraint_is_registered_ =
false;
419 std::vector<CutGenerator> cut_generators_;
422 bool compute_reduced_cost_averages_ =
false;
423 int num_calls_since_reduced_cost_averages_reset_ = 0;
424 std::vector<double> sum_cost_up_;
425 std::vector<double> sum_cost_down_;
426 std::vector<int> num_cost_up_;
427 std::vector<int> num_cost_down_;
428 std::vector<double> rc_scores_;
432 int rev_rc_start_ = 0;
434 std::vector<std::pair<double, int>> positions_by_decreasing_rc_score_;
437 IncrementalAverage average_degeneracy_;
438 bool is_degenerate_ =
false;
441 int branching_frequency_ = 1;
442 int64 count_since_last_branching_ = 0;
446 int64 total_num_simplex_iterations_ = 0;
455 :
public absl::flat_hash_map<IntegerVariable,
456 LinearProgrammingConstraint*> {
463 :
public std::vector<LinearProgrammingConstraint*> {
476 int num_nodes,
const std::vector<int>& tails,
const std::vector<int>& heads,
477 const std::vector<Literal>& literals, Model*
model);
484 const std::vector<int>& tails,
485 const std::vector<int>& heads,
486 const std::vector<Literal>& literals,
487 const std::vector<int64>& demands,
492 #endif // OR_TOOLS_SAT_LINEAR_PROGRAMMING_CONSTRAINT_H_