From e3c0ae5b9b52120cfcf58f09a74b62827e2df2e1 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Thu, 22 Aug 2019 13:15:29 +0200 Subject: [PATCH] improve glop internals --- ortools/glop/basis_representation.cc | 3 +-- ortools/glop/lu_factorization.cc | 11 ++++++++--- ortools/glop/lu_factorization.h | 3 ++- ortools/glop/revised_simplex.cc | 4 ++++ ortools/glop/revised_simplex.h | 1 + 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ortools/glop/basis_representation.cc b/ortools/glop/basis_representation.cc index bb2401e793..eb06b31510 100644 --- a/ortools/glop/basis_representation.cc +++ b/ortools/glop/basis_representation.cc @@ -344,8 +344,7 @@ const DenseColumn& BasisFactorization::RightSolveForTau( // Once used, the intermediate result is overwritten, so // RightSolveForTau() can no longer use the optimized algorithm. tau_computation_can_be_optimized_ = false; - lu_factorization_.RightSolveLWithPermutedInput(a.values, &tau_.values); - tau_.non_zeros.clear(); + lu_factorization_.RightSolveLWithPermutedInput(a.values, &tau_); } else { ClearAndResizeVectorWithNonZeros(compact_matrix_.num_rows(), &tau_); lu_factorization_.RightSolveLForScatteredColumn(a, &tau_); diff --git a/ortools/glop/lu_factorization.cc b/ortools/glop/lu_factorization.cc index 341206bff4..80bb4779ac 100644 --- a/ortools/glop/lu_factorization.cc +++ b/ortools/glop/lu_factorization.cc @@ -182,11 +182,16 @@ bool AreEqualWithPermutation(const DenseColumn& a, const DenseColumn& b, } // namespace void LuFactorization::RightSolveLWithPermutedInput(const DenseColumn& a, - DenseColumn* x) const { + ScatteredColumn* x) const { SCOPED_TIME_STAT(&stats_); if (!is_identity_factorization_) { - DCHECK(AreEqualWithPermutation(a, *x, row_perm_)); - lower_.LowerSolve(x); + DCHECK(AreEqualWithPermutation(a, x->values, row_perm_)); + lower_.ComputeRowsToConsiderInSortedOrder(&x->non_zeros); + if (x->non_zeros.empty()) { + lower_.LowerSolve(&x->values); + } else { + lower_.HyperSparseSolve(&x->values, &x->non_zeros); + } } } diff --git a/ortools/glop/lu_factorization.h b/ortools/glop/lu_factorization.h index d1365f3a9a..b91465854f 100644 --- a/ortools/glop/lu_factorization.h +++ b/ortools/glop/lu_factorization.h @@ -115,7 +115,8 @@ class LuFactorization { // Specialized version of RightSolveLWithNonZeros() where x is originaly equal // to 'a' permuted by row_perm_. Note that 'a' is only used for DCHECK. - void RightSolveLWithPermutedInput(const DenseColumn& a, DenseColumn* x) const; + void RightSolveLWithPermutedInput(const DenseColumn& a, + ScatteredColumn* x) const; // Specialized version of LeftSolveU() for an unit right-hand side. // non_zeros will either be cleared or set to the non zeros of the results. diff --git a/ortools/glop/revised_simplex.cc b/ortools/glop/revised_simplex.cc index 9df4b86919..9b3ef44e67 100644 --- a/ortools/glop/revised_simplex.cc +++ b/ortools/glop/revised_simplex.cc @@ -394,6 +394,10 @@ Fractional RevisedSimplex::GetReducedCost(ColIndex col) const { return solution_reduced_costs_[col]; } +const DenseRow& RevisedSimplex::GetReducedCosts() const { + return solution_reduced_costs_; +} + Fractional RevisedSimplex::GetDualValue(RowIndex row) const { return solution_dual_values_[row]; } diff --git a/ortools/glop/revised_simplex.h b/ortools/glop/revised_simplex.h index 3afc2cb664..d7cfb0f197 100644 --- a/ortools/glop/revised_simplex.h +++ b/ortools/glop/revised_simplex.h @@ -190,6 +190,7 @@ class RevisedSimplex { int64 GetNumberOfIterations() const; Fractional GetVariableValue(ColIndex col) const; Fractional GetReducedCost(ColIndex col) const; + const DenseRow& GetReducedCosts() const; Fractional GetDualValue(RowIndex row) const; Fractional GetConstraintActivity(RowIndex row) const; VariableStatus GetVariableStatus(ColIndex col) const;