diff --git a/ortools/glop/reduced_costs.cc b/ortools/glop/reduced_costs.cc index 4093ae4c23..d715f6802c 100644 --- a/ortools/glop/reduced_costs.cc +++ b/ortools/glop/reduced_costs.cc @@ -237,7 +237,6 @@ void ReducedCosts::PerturbCosts() { SCOPED_TIME_STAT(&stats_); VLOG(1) << "Perturbing the costs ... "; - // Note(user): The max_cost_magnitude should be 1.0 when cost scaling is on. Fractional max_cost_magnitude = 0.0; const ColIndex structural_size = matrix_.num_cols() - RowToColIndex(matrix_.num_rows()); diff --git a/ortools/glop/revised_simplex.cc b/ortools/glop/revised_simplex.cc index 8eeb347f8a..5dda82f475 100644 --- a/ortools/glop/revised_simplex.cc +++ b/ortools/glop/revised_simplex.cc @@ -2909,12 +2909,17 @@ void RevisedSimplex::DisplayVariableBounds() { } } -ITIVector RevisedSimplex::ComputeDictionary() { +ITIVector RevisedSimplex::ComputeDictionary( + const SparseMatrixScaler* scaler) { ITIVector dictionary(num_rows_.value()); for (ColIndex col(0); col < num_cols_; ++col) { ComputeDirection(col); for (const RowIndex row : direction_non_zero_) { - dictionary[row].SetCoefficient(col, direction_[row]); + const Fractional scale_coefficient = + scaler == nullptr + ? 1.0 + : scaler->col_scale(col) / scaler->col_scale(GetBasis(row)); + dictionary[row].SetCoefficient(col, direction_[row] * scale_coefficient); } } return dictionary; @@ -2933,7 +2938,7 @@ void RevisedSimplex::DisplayRevisedSimplexDebugInfo() { } VLOG(3) << output << ";"; - const RevisedSimplexDictionary dictionary(this); + const RevisedSimplexDictionary dictionary(nullptr, this); RowIndex r(0); for (const SparseRow& row : dictionary) { output.clear(); diff --git a/ortools/glop/revised_simplex.h b/ortools/glop/revised_simplex.h index 48ee551162..d33168b3fe 100644 --- a/ortools/glop/revised_simplex.h +++ b/ortools/glop/revised_simplex.h @@ -228,7 +228,7 @@ class RevisedSimplex { // Computes the dictionary B^-1*N on-the-fly row by row. Returns the resulting // matrix as a vector of sparse rows so that it is easy to use it on the left // side in the matrix multiplication. Runs in O(num_non_zeros_in_matrix). - RowMajorSparseMatrix ComputeDictionary(); + RowMajorSparseMatrix ComputeDictionary(const SparseMatrixScaler* scaler); private: // Propagates parameters_ to all the other classes that need it. @@ -799,8 +799,9 @@ class RevisedSimplexDictionary { // RevisedSimplex cannot be passed const because we have to call a non-const // method ComputeDictionary. - explicit RevisedSimplexDictionary(RevisedSimplex* revised_simplex) - : dictionary_(CHECK_NOTNULL(revised_simplex)->ComputeDictionary()), + RevisedSimplexDictionary(const SparseMatrixScaler* scaler, + RevisedSimplex* revised_simplex) + : dictionary_(CHECK_NOTNULL(revised_simplex)->ComputeDictionary(scaler)), basis_vars_(CHECK_NOTNULL(revised_simplex)->GetBasisVector()) {} ConstIterator begin() const { return dictionary_.begin(); }