24 : basis_factorization_(basis_factorization),
25 recompute_edge_squared_norms_(true) {}
28 return recompute_edge_squared_norms_;
34 edge_squared_norms_.
resize(new_size, 1.0);
38 if (recompute_edge_squared_norms_) ComputeEdgeSquaredNorms();
44 if (recompute_edge_squared_norms_)
return;
46 &tmp_edge_squared_norms_);
52 if (recompute_edge_squared_norms_)
return true;
59 const Fractional old_squared_norm = edge_squared_norms_[leaving_row];
60 const Fractional estimated_edge_norms_accuracy =
61 (sqrt(leaving_squared_norm) - sqrt(old_squared_norm)) /
62 sqrt(leaving_squared_norm);
63 stats_.edge_norms_accuracy.
Add(estimated_edge_norms_accuracy);
65 if (std::abs(estimated_edge_norms_accuracy) >
66 parameters_.recompute_edges_norm_threshold()) {
67 VLOG(1) <<
"Recomputing edge norms: " << sqrt(leaving_squared_norm)
68 <<
" vs " << sqrt(old_squared_norm);
69 recompute_edge_squared_norms_ =
true;
73 edge_squared_norms_[leaving_row] = leaving_squared_norm;
74 const bool result = old_squared_norm > 0.25 * leaving_squared_norm;
76 VLOG(1) <<
"Recomputing leaving row. Norm was " << sqrt(old_squared_norm)
77 <<
" vs precise version " << sqrt(leaving_squared_norm);
83 ColIndex entering_col, RowIndex leaving_row,
87 if (recompute_edge_squared_norms_)
return;
91 const Fractional pivot = direction[leaving_row];
93 edge_squared_norms_[leaving_row] /
Square(pivot);
96 int stat_lower_bounded_norms = 0;
97 auto output = edge_squared_norms_.
view();
98 for (
const auto e : direction) {
102 e.coefficient() * (e.coefficient() * new_leaving_squared_norm -
103 2.0 / pivot * tau[e.row()]);
110 if (output[e.row()] < kLowerBound) {
111 if (e.row() == leaving_row)
continue;
112 output[e.row()] = kLowerBound;
113 ++stat_lower_bounded_norms;
116 output[leaving_row] = new_leaving_squared_norm;
120void DualEdgeNorms::ComputeEdgeSquaredNorms() {
127 edge_squared_norms_.
resize(num_rows, 0.0);
128 for (RowIndex
row(0);
row < num_rows; ++
row) {
131 recompute_edge_squared_norms_ =
false;
135 const ScatteredColumn& unit_row_left_inverse) {
const DenseColumn & RightSolveForTau(const ScatteredColumn &a) const
bool IsRefactorized() const
Returns true if the factorization was just recomputed.
RowIndex GetNumberOfRows() const
Return the number of rows in the basis.
Fractional DualEdgeSquaredNorm(RowIndex row) const
DenseColumn::ConstView GetEdgeSquaredNorms()
void ResizeOnNewRows(RowIndex new_size)
DualEdgeNorms(const BasisFactorization &basis_factorization)
Takes references to the linear program data we need.
void UpdateDataOnBasisPermutation(const ColumnPermutation &col_perm)
Updates the norms if the columns of the basis where permuted.
bool NeedsBasisRefactorization() const
void UpdateBeforeBasisPivot(ColIndex entering_col, RowIndex leaving_row, const ScatteredColumn &direction, const ScatteredRow &unit_row_left_inverse)
bool TestPrecision(RowIndex leaving_row, const ScatteredRow &unit_row_left_inverse)
ConstView const_view() const
void resize(IntType size)
double Density(const DenseRow &row)
Fractional Square(Fractional f)
const DenseRow & Transpose(const DenseColumn &col)
Similar comment as the other Transpose() implementation above.
Fractional SquaredNorm(const SparseColumn &v)
StrictITIVector< RowIndex, Fractional > DenseColumn
Column-vector types. Column-vector types are indexed by a row index.
void ApplyColumnPermutationToRowIndexedVector(const Permutation< ColIndex > &col_perm, RowIndexedVector *v)
const ScatteredRow & TransposedView(const ScatteredColumn &c)
In SWIG mode, we don't want anything besides these top-level includes.
#define IF_STATS_ENABLED(instructions)
#define SCOPED_TIME_STAT(stats)