91 #ifndef OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
92 #define OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
98 #include "absl/random/bit_gen_ref.h"
104 #include "ortools/glop/parameters.pb.h"
245 total(
"total", this),
246 normal(
"normal", this),
247 bound_flip(
"bound_flip", this),
248 refactorize(
"refactorize", this),
249 degenerate(
"degenerate", this),
250 num_dual_flips(
"num_dual_flips", this),
251 degenerate_run_size(
"degenerate_run_size", this) {}
261 struct RatioTestStats :
public StatsGroup {
263 : StatsGroup(
"RatioTestStats"),
264 bound_shift(
"bound_shift", this),
265 abs_used_pivot(
"abs_used_pivot", this),
266 abs_tested_pivot(
"abs_tested_pivot", this),
267 abs_skipped_pivot(
"abs_skipped_pivot", this),
268 direction_density(
"direction_density", this),
269 leaving_choices(
"leaving_choices", this),
270 num_perfect_ties(
"num_perfect_ties", this) {}
271 DoubleDistribution bound_shift;
272 DoubleDistribution abs_used_pivot;
273 DoubleDistribution abs_tested_pivot;
274 DoubleDistribution abs_skipped_pivot;
275 RatioDistribution direction_density;
276 IntegerDistribution leaving_choices;
277 IntegerDistribution num_perfect_ties;
280 enum class Phase { FEASIBILITY, OPTIMIZATION, PUSH };
282 enum class RefactorizationReason {
297 void PropagateParameters();
311 std::string GetPrettySolverStats()
const;
315 std::string SimpleVariableInfo(ColIndex
col)
const;
318 void DisplayIterationInfo(
bool primal, RefactorizationReason reason =
319 RefactorizationReason::DEFAULT);
322 void DisplayErrors();
325 void DisplayInfoOnVariables()
const;
328 void DisplayVariableBounds();
344 void DisplayRevisedSimplexDebugInfo();
347 void DisplayProblem()
const;
356 Fractional ComputeInitialProblemObjectiveValue()
const;
360 void SetVariableNames();
366 void SetNonBasicVariableStatusAndDeriveValue(ColIndex
col,
372 bool BasisIsConsistent()
const;
377 void UpdateBasis(ColIndex entering_col, RowIndex basis_row,
387 bool InitializeMatrixAndTestIfUnchanged(
const LinearProgram& lp,
388 bool lp_is_in_equation_form,
389 bool* only_change_is_new_rows,
390 bool* only_change_is_new_cols,
391 ColIndex* num_new_cols);
395 bool OldBoundsAreUnchangedAndNewVariablesHaveOneBoundAtZero(
396 const LinearProgram& lp,
bool lp_is_in_equation_form,
397 ColIndex num_new_cols);
400 bool InitializeObjectiveAndTestIfUnchanged(
const LinearProgram& lp);
403 void InitializeObjectiveLimit(
const LinearProgram& lp);
407 ABSL_MUST_USE_RESULT Status CreateInitialBasis();
411 ABSL_MUST_USE_RESULT Status
415 ABSL_MUST_USE_RESULT Status Initialize(
const LinearProgram& lp);
421 void DisplayBasicVariableStatistics();
430 RowIndex ComputeNumberOfEmptyRows();
434 ColIndex ComputeNumberOfEmptyColumns();
439 int ComputeNumberOfSuperBasicVariables()
const;
451 void CorrectErrorsOnVariableValues();
454 void ComputeVariableValuesError();
459 void ComputeDirection(ColIndex
col);
469 template <
bool is_entering_reduced_cost_positive>
477 template <
bool is_entering_reduced_cost_positive>
478 Fractional ComputeHarrisRatioAndLeavingCandidates(
479 Fractional bound_flip_ratio, SparseColumn* leaving_candidates)
const;
486 Status ChooseLeavingVariableRow(ColIndex entering_col,
488 RowIndex* leaving_row,
497 void PrimalPhaseIChooseLeavingVariableRow(ColIndex entering_col,
500 RowIndex* leaving_row,
512 ABSL_MUST_USE_RESULT Status DualChooseLeavingVariableRow(
513 RowIndex* leaving_row,
Fractional* cost_variation,
521 void DualPhaseIUpdatePrice(RowIndex leaving_row, ColIndex entering_col);
525 template <
bool use_dense_update = false>
526 void OnDualPriceChange(
const DenseColumn& squared_norms, RowIndex
row,
531 template <
typename Cols>
532 void DualPhaseIUpdatePriceOnReducedCostChange(
const Cols& cols);
541 ABSL_MUST_USE_RESULT Status DualPhaseIChooseLeavingVariableRow(
542 RowIndex* leaving_row,
Fractional* cost_variation,
553 template <
typename BoxedVariableCols>
554 void MakeBoxedVariableDualFeasible(
const BoxedVariableCols& cols,
555 bool update_basic_values);
559 Fractional ComputeStepToMoveBasicVariableToBound(RowIndex leaving_row,
563 bool TestPivot(ColIndex entering_col, RowIndex leaving_row);
574 ABSL_MUST_USE_RESULT Status UpdateAndPivot(ColIndex entering_col,
575 RowIndex leaving_row,
579 void DisplayAllStats();
588 Status RefactorizeBasisIfNeeded(
bool* refactorize);
591 ABSL_MUST_USE_RESULT Status PrimalMinimize(TimeLimit*
time_limit);
594 ABSL_MUST_USE_RESULT Status DualMinimize(
bool feasibility_phase,
602 ABSL_MUST_USE_RESULT Status PrimalPush(TimeLimit*
time_limit);
612 ABSL_MUST_USE_RESULT Status Polish(TimeLimit*
time_limit);
617 ColIndex SlackColIndex(RowIndex
row)
const;
624 void AdvanceDeterministicTime(TimeLimit*
time_limit);
630 RowIndex num_rows_ = RowIndex(0);
633 ColIndex num_cols_ = ColIndex(0);
638 ColIndex first_slack_col_ = ColIndex(0);
645 CompactSparseMatrix compact_matrix_;
648 CompactSparseMatrix transposed_matrix_;
673 DenseRow dual_infeasibility_improvement_direction_;
674 int num_dual_infeasible_positions_;
677 ScatteredColumn initially_all_zero_scratchpad_;
686 StrictITIVector<ColIndex, std::string> variable_name_;
689 RefactorizationReason last_refactorization_reason_;
697 DenseRow solution_dual_ray_row_combination_;
698 BasisState solution_state_;
699 bool solution_state_has_been_set_externally_;
706 bool notify_that_matrix_is_unchanged_ =
false;
712 ScatteredColumn direction_;
723 absl::BitGen absl_random_;
725 absl::BitGenRef random_;
728 SolverLogger default_logger_;
729 SolverLogger* logger_ = &default_logger_;
732 BasisFactorization basis_factorization_;
735 VariablesInfo variables_info_;
736 PrimalEdgeNorms primal_edge_norms_;
737 DualEdgeNorms dual_edge_norms_;
738 DynamicMaximum<RowIndex> dual_prices_;
739 VariableValues variable_values_;
740 UpdateRow update_row_;
742 EnteringVariable entering_variable_;
743 PrimalPrices primal_prices_;
750 std::vector<ColIndex> bound_flip_candidates_;
753 uint64_t num_iterations_ = 0;
756 uint64_t num_feasibility_iterations_ = 0;
759 uint64_t num_optimization_iterations_ = 0;
762 uint64_t num_push_iterations_ = 0;
765 int64_t num_update_price_operations_ = 0;
768 double total_time_ = 0.0;
771 double feasibility_time_ = 0.0;
774 double optimization_time_ = 0.0;
777 double push_time_ = 0.0;
781 double last_deterministic_time_update_ = 0.0;
784 IterationStats iteration_stats_;
786 mutable RatioTestStats ratio_test_stats_;
790 mutable StatsGroup function_stats_;
798 GlopParameters parameters_;
799 GlopParameters initial_parameters_;
803 LuFactorization test_lu_;
806 int num_consecutive_degenerate_iterations_;
809 Phase phase_ = Phase::FEASIBILITY;
816 bool objective_limit_reached_;
819 SparseColumn leaving_candidates_;
825 std::vector<RowIndex> equivalent_leaving_choices_;
848 ABSL_DIE_IF_NULL(revised_simplex)->ComputeDictionary(col_scales)),
849 basis_vars_(ABSL_DIE_IF_NULL(revised_simplex)->GetBasisVector()) {}
ParentType::const_iterator const_iterator
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
RevisedSimplexDictionary(const DenseRow *col_scales, RevisedSimplex *revised_simplex)
ConstIterator end() const
ColIndex GetBasicColumnForRow(RowIndex r) const
RowMajorSparseMatrix::const_iterator ConstIterator
ConstIterator begin() const
SparseRow GetRow(RowIndex r) const
const GlopParameters & GetParameters() const
const DenseRow & GetDualRayRowCombination() const
Fractional GetVariableValue(ColIndex col) const
void SetIntegralityScale(ColIndex col, Fractional scale)
const DenseRow & GetReducedCosts() const
const DenseRow & GetPrimalRay() const
RowToColMapping GetBasisVector() const
bool objective_limit_reached() const
Fractional GetConstraintActivity(RowIndex row) const
VariableStatus GetVariableStatus(ColIndex col) const
Fractional GetReducedCost(ColIndex col) const
const DenseColumn & GetDualRay() const
void NotifyThatMatrixIsChangedForNextSolve()
ABSL_MUST_USE_RESULT Status Solve(const LinearProgram &lp, TimeLimit *time_limit)
void SetLogger(SolverLogger *logger)
ProblemStatus GetProblemStatus() const
Fractional GetObjectiveValue() const
RowMajorSparseMatrix ComputeDictionary(const DenseRow *column_scales)
Fractional GetDualValue(RowIndex row) const
void ClearIntegralityScales()
void NotifyThatMatrixIsUnchangedForNextSolve()
void SetStartingVariableValuesForNextSolve(const DenseRow &values)
ConstraintStatus GetConstraintStatus(RowIndex row) const
void ComputeBasicVariablesForState(const LinearProgram &linear_program, const BasisState &state)
ColIndex GetProblemNumCols() const
void LoadStateForNextSolve(const BasisState &state)
RowIndex GetProblemNumRows() const
void ClearStateForNextSolve()
const BasisFactorization & GetBasisFactorization() const
int64_t GetNumberOfIterations() const
const BasisState & GetState() const
ColIndex GetBasis(RowIndex row) const
void SetParameters(const GlopParameters ¶meters)
double DeterministicTime() const
const ScatteredRow & GetUnitRowLeftInverse(RowIndex row)
const ScatteredRow & ComputeAndGetUnitRowLeftInverse(RowIndex leaving_row)
ModelSharedTimeLimit * time_limit
StrictITIVector< ColIndex, Fractional > DenseRow
StrictITIVector< RowIndex, ColIndex > RowToColMapping
StrictITIVector< RowIndex, Fractional > DenseColumn
VectorXd ReducedCosts(const PrimalDualHybridGradientParams ¶ms, const ShardedQuadraticProgram &sharded_qp, const VectorXd &primal_solution, const VectorXd &dual_solution, bool use_zero_primal_objective)
Collection of objects used to extend the Constraint Solver library.
std::mt19937_64 random_engine_t
std::vector< double > lower_bounds
std::vector< double > upper_bounds