diff --git a/ortools/glop/dual_edge_norms.cc b/ortools/glop/dual_edge_norms.cc index 96af1711ce..48e3b67c22 100644 --- a/ortools/glop/dual_edge_norms.cc +++ b/ortools/glop/dual_edge_norms.cc @@ -40,7 +40,8 @@ const DenseColumn& DualEdgeNorms::GetEdgeSquaredNorms() { void DualEdgeNorms::UpdateDataOnBasisPermutation( const ColumnPermutation& col_perm) { if (recompute_edge_squared_norms_) return; - ApplyColumnPermutationToRowIndexedVector(col_perm, &edge_squared_norms_); + ApplyColumnPermutationToRowIndexedVector(col_perm, &edge_squared_norms_, + &tmp_edge_squared_norms_); } bool DualEdgeNorms::TestPrecision(RowIndex leaving_row, diff --git a/ortools/glop/dual_edge_norms.h b/ortools/glop/dual_edge_norms.h index 8f381d3c15..03c56ea7b7 100644 --- a/ortools/glop/dual_edge_norms.h +++ b/ortools/glop/dual_edge_norms.h @@ -132,6 +132,7 @@ class DualEdgeNorms { // The dual edge norms. DenseColumn edge_squared_norms_; + DenseColumn tmp_edge_squared_norms_; // Whether we should recompute the norm from scratch. bool recompute_edge_squared_norms_; diff --git a/ortools/glop/revised_simplex.cc b/ortools/glop/revised_simplex.cc index db0d6606e9..c633e3a2ab 100644 --- a/ortools/glop/revised_simplex.cc +++ b/ortools/glop/revised_simplex.cc @@ -2477,13 +2477,14 @@ void RevisedSimplex::PermuteBasis() { if (col_perm.empty()) return; // Permute basis_. - ApplyColumnPermutationToRowIndexedVector(col_perm, &basis_); + ApplyColumnPermutationToRowIndexedVector(col_perm, &basis_, &tmp_basis_); // Permute dual_pricing_vector_ if needed. if (!dual_pricing_vector_.empty()) { // TODO(user): We need to permute dual_prices_ too now, we recompute // everything one each basis factorization, so this don't matter. - ApplyColumnPermutationToRowIndexedVector(col_perm, &dual_pricing_vector_); + ApplyColumnPermutationToRowIndexedVector(col_perm, &dual_pricing_vector_, + &tmp_dual_pricing_vector_); } // Notify the other classes. diff --git a/ortools/glop/revised_simplex.h b/ortools/glop/revised_simplex.h index 33ed6e21df..29da7c1763 100644 --- a/ortools/glop/revised_simplex.h +++ b/ortools/glop/revised_simplex.h @@ -678,6 +678,7 @@ class RevisedSimplex { // Array of column index, giving the column number corresponding // to a given basis row. RowToColMapping basis_; + RowToColMapping tmp_basis_; // Vector of strings containing the names of variables. // Indexed by column number. @@ -742,6 +743,7 @@ class RevisedSimplex { // Used in dual phase I to hold the price of each possible leaving choices. DenseColumn dual_pricing_vector_; + DenseColumn tmp_dual_pricing_vector_; // Temporary memory used by DualMinimize(). std::vector bound_flip_candidates_; diff --git a/ortools/lp_data/permutation.h b/ortools/lp_data/permutation.h index 8b26fe5fd3..af7d9453fe 100644 --- a/ortools/lp_data/permutation.h +++ b/ortools/lp_data/permutation.h @@ -119,6 +119,14 @@ void ApplyColumnPermutationToRowIndexedVector( ApplyPermutation(col_perm, temp_v, v); } +template +void ApplyColumnPermutationToRowIndexedVector( + const Permutation& col_perm, RowIndexedVector* v, + RowIndexedVector* tmp) { + ApplyPermutation(col_perm, *v, tmp); + std::swap(*tmp, *v); +} + // -------------------------------------------------------- // Implementation // --------------------------------------------------------