From 4007aa885f87e25e3db558db1fc388fb6772b9ad Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Wed, 25 Jul 2018 10:21:35 -0700 Subject: [PATCH] simplify glop code --- ortools/glop/entering_variable.cc | 11 ++++------- ortools/glop/entering_variable.h | 6 ++---- ortools/glop/revised_simplex.cc | 6 +++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ortools/glop/entering_variable.cc b/ortools/glop/entering_variable.cc index 84359dc905..bf1f6f31b5 100644 --- a/ortools/glop/entering_variable.cc +++ b/ortools/glop/entering_variable.cc @@ -89,9 +89,9 @@ Status EnteringVariable::PrimalChooseEnteringColumn(ColIndex* entering_col) { Status EnteringVariable::DualChooseEnteringColumn( const UpdateRow& update_row, Fractional cost_variation, std::vector* bound_flip_candidates, ColIndex* entering_col, - Fractional* pivot, Fractional* step) { + Fractional* step) { GLOP_RETURN_ERROR_IF_NULL(entering_col); - GLOP_RETURN_ERROR_IF_NULL(pivot); + GLOP_RETURN_ERROR_IF_NULL(step); const DenseRow& update_coefficient = update_row.GetCoefficients(); const DenseRow& reduced_costs = reduced_costs_->GetReducedCosts(); SCOPED_TIME_STAT(&stats_); @@ -241,7 +241,6 @@ Status EnteringVariable::DualChooseEnteringColumn( } if (*entering_col == kInvalidCol) return Status::OK(); - *pivot = update_coefficient[*entering_col]; // If the step is 0.0, we make sure the reduced cost is 0.0 so // UpdateReducedCosts() will not take a step that goes in the wrong way (a few @@ -266,9 +265,9 @@ Status EnteringVariable::DualChooseEnteringColumn( Status EnteringVariable::DualPhaseIChooseEnteringColumn( const UpdateRow& update_row, Fractional cost_variation, - ColIndex* entering_col, Fractional* pivot, Fractional* step) { + ColIndex* entering_col, Fractional* step) { GLOP_RETURN_ERROR_IF_NULL(entering_col); - GLOP_RETURN_ERROR_IF_NULL(pivot); + GLOP_RETURN_ERROR_IF_NULL(step); const DenseRow& update_coefficient = update_row.GetCoefficients(); const DenseRow& reduced_costs = reduced_costs_->GetReducedCosts(); SCOPED_TIME_STAT(&stats_); @@ -365,8 +364,6 @@ Status EnteringVariable::DualPhaseIChooseEnteringColumn( std::pop_heap(breakpoints_.begin(), breakpoints_.end()); breakpoints_.pop_back(); } - *pivot = - (*entering_col == kInvalidCol) ? 0.0 : update_coefficient[*entering_col]; return Status::OK(); } diff --git a/ortools/glop/entering_variable.h b/ortools/glop/entering_variable.h index 3872981b72..9bbc3829dc 100644 --- a/ortools/glop/entering_variable.h +++ b/ortools/glop/entering_variable.h @@ -67,12 +67,11 @@ class EnteringVariable { // Returns the index of the entering column given that we want to move along // the "update" row vector in the direction given by the sign of // cost_variation. Computes the smallest step that keeps the dual feasibility - // for all the columns. The pivot is the coefficient of the "update" vector at - // the entering column index. + // for all the columns. Status DualChooseEnteringColumn(const UpdateRow& update_row, Fractional cost_variation, std::vector* bound_flip_candidates, - ColIndex* entering_col, Fractional* pivot, + ColIndex* entering_col, Fractional* step) MUST_USE_RESULT; // Dual feasibility phase (i.e. phase I) ratio test. @@ -82,7 +81,6 @@ class EnteringVariable { Status DualPhaseIChooseEnteringColumn(const UpdateRow& update_row, Fractional cost_variation, ColIndex* entering_col, - Fractional* pivot, Fractional* step) MUST_USE_RESULT; // Sets the pricing parameters. This does not change the pricing rule. diff --git a/ortools/glop/revised_simplex.cc b/ortools/glop/revised_simplex.cc index f1a9df7014..57210ba12b 100644 --- a/ortools/glop/revised_simplex.cc +++ b/ortools/glop/revised_simplex.cc @@ -2553,7 +2553,6 @@ Status RevisedSimplex::DualMinimize(TimeLimit* time_limit) { // Entering variable. ColIndex entering_col; - Fractional entering_coeff; Fractional ratio; while (true) { @@ -2670,11 +2669,11 @@ Status RevisedSimplex::DualMinimize(TimeLimit* time_limit) { update_row_.ComputeUpdateRow(leaving_row); if (feasibility_phase_) { GLOP_RETURN_IF_ERROR(entering_variable_.DualPhaseIChooseEnteringColumn( - update_row_, cost_variation, &entering_col, &entering_coeff, &ratio)); + update_row_, cost_variation, &entering_col, &ratio)); } else { GLOP_RETURN_IF_ERROR(entering_variable_.DualChooseEnteringColumn( update_row_, cost_variation, &bound_flip_candidates, &entering_col, - &entering_coeff, &ratio)); + &ratio)); } // No entering_col: Unbounded problem / Infeasible problem. @@ -2708,6 +2707,7 @@ Status RevisedSimplex::DualMinimize(TimeLimit* time_limit) { } // If the coefficient is too small, we recompute the reduced costs. + const Fractional entering_coeff = update_row_.GetCoefficient(entering_col); if (std::abs(entering_coeff) < parameters_.dual_small_pivot_threshold() && !reduced_costs_.AreReducedCostsPrecise()) { VLOG(1) << "Trying not to pivot by " << entering_coeff;