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 return unit_row_left_inverse_;
50 RowIndex leaving_row) {
53 &unit_row_left_inverse_);
54 return unit_row_left_inverse_;
60 &unit_row_left_inverse_);
65 unit_row_left_inverse_.
values) -
72 if (!compute_update_row_ && update_row_computed_for_ == leaving_row)
return;
73 compute_update_row_ =
false;
74 update_row_computed_for_ = leaving_row;
78 if (parameters_.use_transposed_matrix()) {
80 EntryIndex num_row_wise_entries(0);
92 const Fractional drop_tolerance = parameters_.drop_tolerance();
93 unit_row_left_inverse_filtered_non_zeros_.clear();
94 if (unit_row_left_inverse_.
non_zeros.empty()) {
95 const ColIndex size = unit_row_left_inverse_.
values.
size();
96 for (ColIndex
col(0);
col < size; ++
col) {
97 if (std::abs(unit_row_left_inverse_.
values[
col]) > drop_tolerance) {
98 unit_row_left_inverse_filtered_non_zeros_.push_back(
col);
103 for (
const auto e : unit_row_left_inverse_) {
104 if (std::abs(e.coefficient()) > drop_tolerance) {
105 unit_row_left_inverse_filtered_non_zeros_.push_back(e.column());
106 num_row_wise_entries +=
113 const EntryIndex num_col_wise_entries =
119 const double row_wise =
static_cast<double>(num_row_wise_entries.value());
120 if (row_wise < 0.5 *
static_cast<double>(num_col_wise_entries.value())) {
121 if (row_wise < 1.1 *
static_cast<double>(matrix_.
num_cols().value())) {
122 ComputeUpdatesRowWiseHypersparse();
127 5 * num_row_wise_entries.value() + matrix_.
num_cols().value() / 64;
129 ComputeUpdatesRowWise();
131 num_row_wise_entries.value() + matrix_.
num_rows().value();
134 ComputeUpdatesColumnWise();
136 num_col_wise_entries.value() + matrix_.
num_cols().value();
139 ComputeUpdatesColumnWise();
145 static_cast<double>(non_zero_position_list_.size()) /
146 static_cast<double>(matrix_.
num_cols().value())));
150 const std::string& algorithm) {
151 unit_row_left_inverse_.
values = lhs;
153 if (algorithm ==
"column") {
154 ComputeUpdatesColumnWise();
155 }
else if (algorithm ==
"row") {
156 ComputeUpdatesRowWise();
157 }
else if (algorithm ==
"row_hypersparse") {
158 ComputeUpdatesRowWiseHypersparse();
160 LOG(DFATAL) <<
"Unknown algorithm in ComputeUpdateRowForBenchmark(): '"
168 return non_zero_position_list_;
177void UpdateRow::ComputeUpdatesRowWise() {
179 const ColIndex num_cols = matrix_.
num_cols();
181 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
183 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
189 non_zero_position_list_.clear();
190 const Fractional drop_tolerance = parameters_.drop_tolerance();
192 if (std::abs(coefficient_[
col]) > drop_tolerance) {
193 non_zero_position_list_.push_back(
col);
200void UpdateRow::ComputeUpdatesRowWiseHypersparse() {
202 const ColIndex num_cols = matrix_.
num_cols();
204 coefficient_.
resize(num_cols, 0.0);
205 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
207 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
210 if (!non_zero_position_set_.
IsSet(pos)) {
215 coefficient_[pos] = v;
216 non_zero_position_set_.
Set(pos);
218 coefficient_[pos] += v;
225 non_zero_position_list_.clear();
226 const Fractional drop_tolerance = parameters_.drop_tolerance();
227 for (
const ColIndex
col : non_zero_position_set_) {
232 if (std::abs(coefficient_[
col]) > drop_tolerance) {
233 non_zero_position_list_.push_back(
col);
242 CHECK(!compute_update_row_);
243 const ColIndex num_cols = matrix_.
num_cols();
244 const Fractional drop_tolerance = parameters_.drop_tolerance();
245 coefficient_.
resize(num_cols, 0.0);
246 non_zero_position_list_.clear();
249 coefficient_[basis_[leaving_row]] = 1.0;
250 non_zero_position_list_.push_back(basis_[leaving_row]);
256 if (std::abs(
coeff) > drop_tolerance) {
257 non_zero_position_list_.push_back(
col);
263void UpdateRow::ComputeUpdatesColumnWise() {
266 const ColIndex num_cols = matrix_.
num_cols();
267 const Fractional drop_tolerance = parameters_.drop_tolerance();
268 coefficient_.
resize(num_cols, 0.0);
269 non_zero_position_list_.clear();
278 if (std::abs(
coeff) > drop_tolerance) {
279 non_zero_position_list_.push_back(
col);
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
RowIndex num_rows() const
Fractional EntryCoefficient(EntryIndex i) const
Fractional ColumnScalarProduct(ColIndex col, const DenseRow &vector) const
::util::IntegerRange< EntryIndex > Column(ColIndex col) 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)
void ComputeUnitRowLeftInverse(RowIndex leaving_row)
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