remove mem allocs

This commit is contained in:
Laurent Perron
2023-01-27 16:08:26 +01:00
parent 9ffba8a0f5
commit c4d3e7ba0b
5 changed files with 16 additions and 3 deletions

View File

@@ -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,

View File

@@ -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_;

View File

@@ -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.

View File

@@ -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<ColIndex> bound_flip_candidates_;

View File

@@ -119,6 +119,14 @@ void ApplyColumnPermutationToRowIndexedVector(
ApplyPermutation(col_perm, temp_v, v);
}
template <typename RowIndexedVector>
void ApplyColumnPermutationToRowIndexedVector(
const Permutation<ColIndex>& col_perm, RowIndexedVector* v,
RowIndexedVector* tmp) {
ApplyPermutation(col_perm, *v, tmp);
std::swap(*tmp, *v);
}
// --------------------------------------------------------
// Implementation
// --------------------------------------------------------