91#ifndef OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
92#define OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
98#include "absl/random/bit_gen_ref.h"
244 total(
"total", this),
245 normal(
"normal", this),
246 bound_flip(
"bound_flip", this),
247 refactorize(
"refactorize", this),
248 degenerate(
"degenerate", this),
249 num_dual_flips(
"num_dual_flips", this),
250 degenerate_run_size(
"degenerate_run_size", this) {}
260 struct RatioTestStats :
public StatsGroup {
262 : StatsGroup(
"RatioTestStats"),
263 bound_shift(
"bound_shift", this),
264 abs_used_pivot(
"abs_used_pivot", this),
265 abs_tested_pivot(
"abs_tested_pivot", this),
266 abs_skipped_pivot(
"abs_skipped_pivot", this),
267 direction_density(
"direction_density", this),
268 leaving_choices(
"leaving_choices", this),
269 num_perfect_ties(
"num_perfect_ties", this) {}
270 DoubleDistribution bound_shift;
271 DoubleDistribution abs_used_pivot;
272 DoubleDistribution abs_tested_pivot;
273 DoubleDistribution abs_skipped_pivot;
274 RatioDistribution direction_density;
275 IntegerDistribution leaving_choices;
276 IntegerDistribution num_perfect_ties;
279 enum class Phase { FEASIBILITY, OPTIMIZATION, PUSH };
286 void PropagateParameters();
300 std::string GetPrettySolverStats()
const;
304 std::string SimpleVariableInfo(ColIndex
col)
const;
307 void DisplayIterationInfo(
bool primal);
310 void DisplayErrors();
313 void DisplayInfoOnVariables()
const;
316 void DisplayVariableBounds();
332 void DisplayRevisedSimplexDebugInfo();
335 void DisplayProblem()
const;
344 Fractional ComputeInitialProblemObjectiveValue()
const;
348 void SetVariableNames();
354 void SetNonBasicVariableStatusAndDeriveValue(ColIndex
col,
360 bool BasisIsConsistent()
const;
365 void UpdateBasis(ColIndex entering_col, RowIndex basis_row,
375 bool InitializeMatrixAndTestIfUnchanged(
const LinearProgram& lp,
376 bool lp_is_in_equation_form,
377 bool* only_change_is_new_rows,
378 bool* only_change_is_new_cols,
379 ColIndex* num_new_cols);
383 bool OldBoundsAreUnchangedAndNewVariablesHaveOneBoundAtZero(
384 const LinearProgram& lp,
bool lp_is_in_equation_form,
385 ColIndex num_new_cols);
388 bool InitializeObjectiveAndTestIfUnchanged(
const LinearProgram& lp);
391 void InitializeObjectiveLimit(
const LinearProgram& lp);
395 ABSL_MUST_USE_RESULT Status CreateInitialBasis();
399 ABSL_MUST_USE_RESULT Status
403 ABSL_MUST_USE_RESULT Status Initialize(
const LinearProgram& lp);
409 void DisplayBasicVariableStatistics();
418 RowIndex ComputeNumberOfEmptyRows();
422 ColIndex ComputeNumberOfEmptyColumns();
427 int ComputeNumberOfSuperBasicVariables()
const;
439 void CorrectErrorsOnVariableValues();
442 void ComputeVariableValuesError();
447 void ComputeDirection(ColIndex
col);
457 template <
bool is_entering_reduced_cost_positive>
465 template <
bool is_entering_reduced_cost_positive>
466 Fractional ComputeHarrisRatioAndLeavingCandidates(
467 Fractional bound_flip_ratio, SparseColumn* leaving_candidates)
const;
474 Status ChooseLeavingVariableRow(ColIndex entering_col,
476 RowIndex* leaving_row,
485 void PrimalPhaseIChooseLeavingVariableRow(ColIndex entering_col,
488 RowIndex* leaving_row,
500 ABSL_MUST_USE_RESULT Status DualChooseLeavingVariableRow(
501 RowIndex* leaving_row,
Fractional* cost_variation,
509 void DualPhaseIUpdatePrice(RowIndex leaving_row, ColIndex entering_col);
513 template <
bool use_dense_update = false>
514 void OnDualPriceChange(
const DenseColumn& squared_norms, RowIndex
row,
519 template <
typename Cols>
520 void DualPhaseIUpdatePriceOnReducedCostChange(
const Cols& cols);
529 ABSL_MUST_USE_RESULT Status DualPhaseIChooseLeavingVariableRow(
530 RowIndex* leaving_row,
Fractional* cost_variation,
541 template <
typename BoxedVariableCols>
542 void MakeBoxedVariableDualFeasible(
const BoxedVariableCols& cols,
543 bool update_basic_values);
547 Fractional ComputeStepToMoveBasicVariableToBound(RowIndex leaving_row,
551 bool TestPivot(ColIndex entering_col, RowIndex leaving_row);
562 ABSL_MUST_USE_RESULT Status UpdateAndPivot(ColIndex entering_col,
563 RowIndex leaving_row,
567 void DisplayAllStats();
576 Status RefactorizeBasisIfNeeded(
bool* refactorize);
579 ABSL_MUST_USE_RESULT Status PrimalMinimize(TimeLimit*
time_limit);
582 ABSL_MUST_USE_RESULT Status DualMinimize(
bool feasibility_phase,
590 ABSL_MUST_USE_RESULT Status PrimalPush(TimeLimit*
time_limit);
600 ABSL_MUST_USE_RESULT Status Polish(TimeLimit*
time_limit);
605 ColIndex SlackColIndex(RowIndex
row)
const;
612 void AdvanceDeterministicTime(TimeLimit*
time_limit);
618 RowIndex num_rows_ = RowIndex(0);
621 ColIndex num_cols_ = ColIndex(0);
626 ColIndex first_slack_col_ = ColIndex(0);
633 CompactSparseMatrix compact_matrix_;
636 CompactSparseMatrix transposed_matrix_;
661 DenseRow dual_infeasibility_improvement_direction_;
662 int num_dual_infeasible_positions_;
665 ScatteredColumn initially_all_zero_scratchpad_;
673 StrictITIVector<ColIndex, std::string> variable_name_;
681 DenseRow solution_dual_ray_row_combination_;
682 BasisState solution_state_;
683 bool solution_state_has_been_set_externally_;
690 bool notify_that_matrix_is_unchanged_ =
false;
696 ScatteredColumn direction_;
707 absl::BitGen absl_random_;
709 absl::BitGenRef random_;
712 SolverLogger default_logger_;
713 SolverLogger* logger_ = &default_logger_;
716 BasisFactorization basis_factorization_;
719 VariablesInfo variables_info_;
720 PrimalEdgeNorms primal_edge_norms_;
721 DualEdgeNorms dual_edge_norms_;
722 DynamicMaximum<RowIndex> dual_prices_;
723 VariableValues variable_values_;
724 UpdateRow update_row_;
725 ReducedCosts reduced_costs_;
726 EnteringVariable entering_variable_;
727 PrimalPrices primal_prices_;
733 std::vector<ColIndex> bound_flip_candidates_;
736 uint64_t num_iterations_ = 0;
739 uint64_t num_feasibility_iterations_ = 0;
742 uint64_t num_optimization_iterations_ = 0;
745 uint64_t num_push_iterations_ = 0;
748 int64_t num_update_price_operations_ = 0;
751 double total_time_ = 0.0;
754 double feasibility_time_ = 0.0;
757 double optimization_time_ = 0.0;
760 double push_time_ = 0.0;
764 double last_deterministic_time_update_ = 0.0;
767 IterationStats iteration_stats_;
769 mutable RatioTestStats ratio_test_stats_;
773 mutable StatsGroup function_stats_;
781 GlopParameters parameters_;
782 GlopParameters initial_parameters_;
786 LuFactorization test_lu_;
789 int num_consecutive_degenerate_iterations_;
792 Phase phase_ = Phase::FEASIBILITY;
799 bool objective_limit_reached_;
802 SparseColumn leaving_candidates_;
808 std::vector<RowIndex> equivalent_leaving_choices_;
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
ABSL_MUST_USE_RESULT Status Solve(const LinearProgram &lp, TimeLimit *time_limit)
void SetLogger(SolverLogger *logger)
ProblemStatus GetProblemStatus() const
const ScatteredRow & GetUnitRowLeftInverse(RowIndex row)
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 & ComputeAndGetUnitRowLeftInverse(RowIndex leaving_row)
ModelSharedTimeLimit * time_limit
StrictITIVector< ColIndex, Fractional > DenseRow
StrictITIVector< RowIndex, ColIndex > RowToColMapping
StrictITIVector< RowIndex, Fractional > DenseColumn
Collection of objects used to extend the Constraint Solver library.
std::mt19937 random_engine_t
std::vector< double > lower_bounds
std::vector< double > upper_bounds