91#ifndef OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
92#define OR_TOOLS_GLOP_REVISED_SIMPLEX_H_
98#include "absl/random/bit_gen_ref.h"
241 total(
"total", this),
242 normal(
"normal", this),
243 bound_flip(
"bound_flip", this),
244 refactorize(
"refactorize", this),
245 degenerate(
"degenerate", this),
246 num_dual_flips(
"num_dual_flips", this),
247 degenerate_run_size(
"degenerate_run_size", this) {}
257 struct RatioTestStats :
public StatsGroup {
259 : StatsGroup(
"RatioTestStats"),
260 bound_shift(
"bound_shift", this),
261 abs_used_pivot(
"abs_used_pivot", this),
262 abs_tested_pivot(
"abs_tested_pivot", this),
263 abs_skipped_pivot(
"abs_skipped_pivot", this),
264 direction_density(
"direction_density", this),
265 leaving_choices(
"leaving_choices", this),
266 num_perfect_ties(
"num_perfect_ties", this) {}
267 DoubleDistribution bound_shift;
268 DoubleDistribution abs_used_pivot;
269 DoubleDistribution abs_tested_pivot;
270 DoubleDistribution abs_skipped_pivot;
271 RatioDistribution direction_density;
272 IntegerDistribution leaving_choices;
273 IntegerDistribution num_perfect_ties;
276 enum class Phase { FEASIBILITY, OPTIMIZATION, PUSH };
283 void PropagateParameters();
297 std::string GetPrettySolverStats()
const;
301 std::string SimpleVariableInfo(ColIndex
col)
const;
304 void DisplayIterationInfo();
307 void DisplayErrors();
310 void DisplayInfoOnVariables()
const;
313 void DisplayVariableBounds();
329 void DisplayRevisedSimplexDebugInfo();
332 void DisplayProblem()
const;
341 Fractional ComputeInitialProblemObjectiveValue()
const;
345 void SetVariableNames();
351 void SetNonBasicVariableStatusAndDeriveValue(ColIndex
col,
357 bool BasisIsConsistent()
const;
362 void UpdateBasis(ColIndex entering_col, RowIndex basis_row,
372 bool InitializeMatrixAndTestIfUnchanged(
const LinearProgram& lp,
373 bool lp_is_in_equation_form,
374 bool* only_change_is_new_rows,
375 bool* only_change_is_new_cols,
376 ColIndex* num_new_cols);
380 bool OldBoundsAreUnchangedAndNewVariablesHaveOneBoundAtZero(
381 const LinearProgram& lp,
bool lp_is_in_equation_form,
382 ColIndex num_new_cols);
385 bool InitializeObjectiveAndTestIfUnchanged(
const LinearProgram& lp);
388 void InitializeObjectiveLimit(
const LinearProgram& lp);
392 ABSL_MUST_USE_RESULT Status CreateInitialBasis();
396 ABSL_MUST_USE_RESULT Status
400 ABSL_MUST_USE_RESULT Status Initialize(
const LinearProgram& lp);
406 void DisplayBasicVariableStatistics();
415 RowIndex ComputeNumberOfEmptyRows();
419 ColIndex ComputeNumberOfEmptyColumns();
424 int ComputeNumberOfSuperBasicVariables()
const;
436 void CorrectErrorsOnVariableValues();
439 void ComputeVariableValuesError();
444 void ComputeDirection(ColIndex
col);
454 template <
bool is_entering_reduced_cost_positive>
462 template <
bool is_entering_reduced_cost_positive>
463 Fractional ComputeHarrisRatioAndLeavingCandidates(
464 Fractional bound_flip_ratio, SparseColumn* leaving_candidates)
const;
471 Status ChooseLeavingVariableRow(ColIndex entering_col,
473 RowIndex* leaving_row,
482 void PrimalPhaseIChooseLeavingVariableRow(ColIndex entering_col,
485 RowIndex* leaving_row,
497 ABSL_MUST_USE_RESULT Status DualChooseLeavingVariableRow(
498 RowIndex* leaving_row,
Fractional* cost_variation,
506 void DualPhaseIUpdatePrice(RowIndex leaving_row, ColIndex entering_col);
510 template <
bool use_dense_update = false>
511 void OnDualPriceChange(
const DenseColumn& squared_norms, RowIndex
row,
516 template <
typename Cols>
517 void DualPhaseIUpdatePriceOnReducedCostChange(
const Cols& cols);
526 ABSL_MUST_USE_RESULT Status DualPhaseIChooseLeavingVariableRow(
527 RowIndex* leaving_row,
Fractional* cost_variation,
538 template <
typename BoxedVariableCols>
539 void MakeBoxedVariableDualFeasible(
const BoxedVariableCols& cols,
540 bool update_basic_values);
544 Fractional ComputeStepToMoveBasicVariableToBound(RowIndex leaving_row,
548 bool TestPivot(ColIndex entering_col, RowIndex leaving_row);
559 ABSL_MUST_USE_RESULT Status UpdateAndPivot(ColIndex entering_col,
560 RowIndex leaving_row,
564 void DisplayAllStats();
573 Status RefactorizeBasisIfNeeded(
bool* refactorize);
576 ABSL_MUST_USE_RESULT Status PrimalMinimize(TimeLimit*
time_limit);
579 ABSL_MUST_USE_RESULT Status DualMinimize(
bool feasibility_phase,
587 ABSL_MUST_USE_RESULT Status PrimalPush(TimeLimit*
time_limit);
597 ABSL_MUST_USE_RESULT Status Polish(TimeLimit*
time_limit);
602 ColIndex SlackColIndex(RowIndex
row)
const;
609 void AdvanceDeterministicTime(TimeLimit*
time_limit);
615 RowIndex num_rows_ = RowIndex(0);
618 ColIndex num_cols_ = ColIndex(0);
623 ColIndex first_slack_col_ = ColIndex(0);
630 CompactSparseMatrix compact_matrix_;
633 CompactSparseMatrix transposed_matrix_;
658 DenseRow dual_infeasibility_improvement_direction_;
659 int num_dual_infeasible_positions_;
662 ScatteredColumn initially_all_zero_scratchpad_;
670 StrictITIVector<ColIndex, std::string> variable_name_;
678 DenseRow solution_dual_ray_row_combination_;
679 BasisState solution_state_;
680 bool solution_state_has_been_set_externally_;
687 bool notify_that_matrix_is_unchanged_ =
false;
693 ScatteredColumn direction_;
704 absl::BitGen absl_random_;
706 absl::BitGenRef random_;
709 BasisFactorization basis_factorization_;
712 VariablesInfo variables_info_;
713 PrimalEdgeNorms primal_edge_norms_;
714 DualEdgeNorms dual_edge_norms_;
715 DynamicMaximum<RowIndex> dual_prices_;
716 VariableValues variable_values_;
717 UpdateRow update_row_;
718 ReducedCosts reduced_costs_;
719 EnteringVariable entering_variable_;
720 PrimalPrices primal_prices_;
726 std::vector<ColIndex> bound_flip_candidates_;
729 uint64_t num_iterations_ = 0;
732 uint64_t num_feasibility_iterations_ = 0;
735 uint64_t num_optimization_iterations_ = 0;
738 uint64_t num_push_iterations_ = 0;
741 int64_t num_update_price_operations_ = 0;
744 double total_time_ = 0.0;
747 double feasibility_time_ = 0.0;
750 double optimization_time_ = 0.0;
753 double push_time_ = 0.0;
757 double last_deterministic_time_update_ = 0.0;
760 IterationStats iteration_stats_;
762 mutable RatioTestStats ratio_test_stats_;
766 mutable StatsGroup function_stats_;
774 GlopParameters parameters_;
775 GlopParameters initial_parameters_;
779 LuFactorization test_lu_;
782 int num_consecutive_degenerate_iterations_;
785 Phase phase_ = Phase::FEASIBILITY;
792 bool objective_limit_reached_;
795 SparseColumn leaving_candidates_;
801 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)
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