27 transposed_matrix_(transposed_matrix),
28 variables_info_(variables_info),
30 basis_factorization_(basis_factorization),
31 unit_row_left_inverse_(),
32 non_zero_position_list_(),
33 non_zero_position_set_(),
35 compute_update_row_(true),
42 compute_update_row_ =
true;
46 DCHECK(!compute_update_row_);
47 return unit_row_left_inverse_;
51 RowIndex leaving_row) {
54 &unit_row_left_inverse_);
55 return unit_row_left_inverse_;
58 void UpdateRow::ComputeUnitRowLeftInverse(RowIndex leaving_row) {
61 &unit_row_left_inverse_);
66 unit_row_left_inverse_.
values) -
73 if (!compute_update_row_ && update_row_computed_for_ == leaving_row)
return;
74 compute_update_row_ =
false;
75 update_row_computed_for_ = leaving_row;
76 ComputeUnitRowLeftInverse(leaving_row);
79 if (parameters_.use_transposed_matrix()) {
81 EntryIndex num_row_wise_entries(0);
93 const Fractional drop_tolerance = parameters_.drop_tolerance();
94 unit_row_left_inverse_filtered_non_zeros_.clear();
95 if (unit_row_left_inverse_.
non_zeros.empty()) {
96 const ColIndex size = unit_row_left_inverse_.
values.
size();
97 for (ColIndex
col(0);
col < size; ++
col) {
98 if (std::abs(unit_row_left_inverse_.
values[
col]) > drop_tolerance) {
99 unit_row_left_inverse_filtered_non_zeros_.push_back(
col);
104 for (
const auto e : unit_row_left_inverse_) {
105 if (std::abs(e.coefficient()) > drop_tolerance) {
106 unit_row_left_inverse_filtered_non_zeros_.push_back(e.column());
107 num_row_wise_entries +=
114 const EntryIndex num_col_wise_entries =
120 const double row_wise =
static_cast<double>(num_row_wise_entries.value());
121 if (row_wise < 0.5 *
static_cast<double>(num_col_wise_entries.value())) {
122 if (row_wise < 1.1 *
static_cast<double>(matrix_.
num_cols().value())) {
123 ComputeUpdatesRowWiseHypersparse();
128 5 * num_row_wise_entries.value() + matrix_.
num_cols().value() / 64;
130 ComputeUpdatesRowWise();
132 num_row_wise_entries.value() + matrix_.
num_rows().value();
135 ComputeUpdatesColumnWise();
137 num_col_wise_entries.value() + matrix_.
num_cols().value();
140 ComputeUpdatesColumnWise();
146 static_cast<double>(non_zero_position_list_.size()) /
147 static_cast<double>(matrix_.
num_cols().value())));
151 const std::string& algorithm) {
152 unit_row_left_inverse_.
values = lhs;
154 if (algorithm ==
"column") {
155 ComputeUpdatesColumnWise();
156 }
else if (algorithm ==
"row") {
157 ComputeUpdatesRowWise();
158 }
else if (algorithm ==
"row_hypersparse") {
159 ComputeUpdatesRowWiseHypersparse();
161 LOG(DFATAL) <<
"Unknown algorithm in ComputeUpdateRowForBenchmark(): '"
169 return non_zero_position_list_;
178 void UpdateRow::ComputeUpdatesRowWise() {
180 const ColIndex num_cols = matrix_.
num_cols();
182 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
184 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
190 non_zero_position_list_.clear();
191 const Fractional drop_tolerance = parameters_.drop_tolerance();
193 if (std::abs(coefficient_[
col]) > drop_tolerance) {
194 non_zero_position_list_.push_back(
col);
201 void UpdateRow::ComputeUpdatesRowWiseHypersparse() {
203 const ColIndex num_cols = matrix_.
num_cols();
205 coefficient_.
resize(num_cols, 0.0);
206 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
208 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
211 if (!non_zero_position_set_.
IsSet(pos)) {
216 coefficient_[pos] = v;
217 non_zero_position_set_.
Set(pos);
219 coefficient_[pos] += v;
226 non_zero_position_list_.clear();
227 const Fractional drop_tolerance = parameters_.drop_tolerance();
228 for (
const ColIndex
col : non_zero_position_set_) {
233 if (std::abs(coefficient_[
col]) > drop_tolerance) {
234 non_zero_position_list_.push_back(
col);
243 CHECK(!compute_update_row_);
244 const ColIndex num_cols = matrix_.
num_cols();
245 const Fractional drop_tolerance = parameters_.drop_tolerance();
246 coefficient_.
resize(num_cols, 0.0);
247 non_zero_position_list_.clear();
250 coefficient_[basis_[leaving_row]] = 1.0;
251 non_zero_position_list_.push_back(basis_[leaving_row]);
257 if (std::abs(coeff) > drop_tolerance) {
258 non_zero_position_list_.push_back(
col);
259 coefficient_[
col] = coeff;
264 void UpdateRow::ComputeUpdatesColumnWise() {
267 const ColIndex num_cols = matrix_.
num_cols();
268 const Fractional drop_tolerance = parameters_.drop_tolerance();
269 coefficient_.
resize(num_cols, 0.0);
270 non_zero_position_list_.clear();
279 if (std::abs(coeff) > drop_tolerance) {
280 non_zero_position_list_.push_back(
col);
281 coefficient_[
col] = coeff;
#define DCHECK(condition)
void ClearAndResize(IndexType size)
void Intersection(const Bitset64< IndexType > &other)
bool IsSet(IndexType i) const
void LeftSolveForUnitRow(ColIndex j, ScatteredRow *y) const
void TemporaryLeftSolveForUnitRow(ColIndex j, ScatteredRow *y) const
ColIndex num_cols() const
::util::IntegerRange< EntryIndex > Column(ColIndex col) const
RowIndex num_rows() const
Fractional EntryCoefficient(EntryIndex i) const
Fractional ColumnScalarProduct(ColIndex col, const DenseRow &vector) const
RowIndex EntryRow(EntryIndex i) const
EntryIndex ColumnNumEntries(ColIndex col) const
void AssignToZero(IntType size)
void resize(IntType size)
const ScatteredRow & GetUnitRowLeftInverse() const
const ScatteredRow & ComputeAndGetUnitRowLeftInverse(RowIndex leaving_row)
const DenseRow & GetCoefficients() const
void ComputeUpdateRowForBenchmark(const DenseRow &lhs, const std::string &algorithm)
UpdateRow(const CompactSparseMatrix &matrix, const CompactSparseMatrix &transposed_matrix, const VariablesInfo &variables_info, const RowToColMapping &basis, const BasisFactorization &basis_factorization)
void RecomputeFullUpdateRow(RowIndex leaving_row)
void ComputeUpdateRow(RowIndex leaving_row)
void SetParameters(const GlopParameters ¶meters)
const ColIndexVector & GetNonZeroPositions() const
EntryIndex GetNumEntriesInRelevantColumns() const
const DenseBitRow & GetNotBasicBitRow() const
const DenseBitRow & GetIsRelevantBitRow() const
std::vector< ColIndex > ColIndexVector
void ComputeNonZeros(const StrictITIVector< IndexType, Fractional > &input, std::vector< IndexType > *non_zeros)
double Density(const DenseRow &row)
ColIndex RowToColIndex(RowIndex row)
Collection of objects used to extend the Constraint Solver library.
#define IF_STATS_ENABLED(instructions)
#define SCOPED_TIME_STAT(stats)
std::vector< Index > non_zeros
StrictITIVector< Index, Fractional > values