73#ifndef OR_TOOLS_GLOP_MARKOWITZ_H_
74#define OR_TOOLS_GLOP_MARKOWITZ_H_
81#include "absl/container/inlined_vector.h"
84#include "ortools/glop/parameters.pb.h"
114 void Reset(RowIndex num_rows, ColIndex num_cols);
123 std::vector<ColIndex>* singleton_columns,
124 std::vector<RowIndex>* singleton_rows);
127 void AddEntry(RowIndex row, ColIndex col);
158 void Update(RowIndex pivot_row, ColIndex pivot_col,
164 DCHECK(!deleted_columns_[col]);
165 return col_degree_[col];
170 int32_t
RowDegree(RowIndex row)
const {
return row_degree_[row]; }
175 const absl::InlinedVector<ColIndex, 6>&
RowNonZero(RowIndex row)
const {
176 return row_non_zero_[row];
182 void MergeInto(RowIndex pivot_row, RowIndex row);
189 void MergeIntoSorted(RowIndex pivot_row, RowIndex row);
204 std::vector<ColIndex> col_scratchpad_;
205 ColIndex num_non_deleted_columns_;
221 void Reset(int32_t max_degree, ColIndex num_cols);
233 void Remove(ColIndex col, int32_t old_degree);
234 void Insert(ColIndex col, int32_t degree);
245 std::vector<ColIndex> col_by_degree_;
263 void Reset(ColIndex num_cols);
286 std::vector<int> free_columns_;
287 std::vector<SparseColumn> columns_;
308 ABSL_MUST_USE_RESULT
Status
334 std::string
StatString()
const {
return stats_.StatString(); }
338 parameters_ = parameters;
346 basis_singleton_column_ratio(
"basis_singleton_column_ratio", this),
347 basis_residual_singleton_column_ratio(
348 "basis_residual_singleton_column_ratio", this),
349 pivots_without_fill_in_ratio(
"pivots_without_fill_in_ratio", this),
350 degree_two_pivot_columns(
"degree_two_pivot_columns", this) {}
364 void ExtractSingletonColumns(
const CompactSparseMatrixView& basis_matrix,
375 void ExtractResidualSingletonColumns(
376 const CompactSparseMatrixView& basis_matrix,
RowPermutation* row_perm,
381 bool IsResidualSingletonColumn(
382 const ColumnView& column,
383 StrictITISpan<RowIndex, const RowIndex> row_perm, RowIndex* row);
407 ColIndex* pivot_col,
Fractional* pivot_coefficient);
411 void UpdateDegree(ColIndex col,
int degree);
415 void RemoveRowFromResidualMatrix(RowIndex pivot_row, ColIndex pivot_col);
416 void RemoveColumnFromResidualMatrix(RowIndex pivot_row, ColIndex pivot_col);
422 void UpdateResidualMatrix(RowIndex pivot_row, ColIndex pivot_col);
429 MatrixEntry() =
default;
430 MatrixEntry(RowIndex r, ColIndex c,
Fractional coeff)
431 : row(r), col(c), coefficient(coeff) {}
432 bool operator<(
const MatrixEntry& o)
const {
return row < o.row; }
434 std::vector<MatrixEntry> tmp_singleton_entries_;
437 CompactSparseMatrixView
const* basis_matrix_;
442 SparseMatrixWithReusableColumnMemory permuted_lower_;
443 SparseMatrixWithReusableColumnMemory permuted_upper_;
448 TriangularMatrix lower_;
449 TriangularMatrix upper_;
458 MatrixNonZeroPattern residual_matrix_non_zero_;
461 ColumnPriorityQueue col_by_degree_;
464 bool contains_only_singleton_columns_;
467 bool is_col_by_degree_initialized_;
471 std::vector<ColIndex> examined_col_;
476 std::vector<ColIndex> singleton_column_;
479 std::vector<RowIndex> singleton_row_;
482 GlopParameters parameters_;
485 int64_t num_fp_operations_;
Statistic on the distribution of a sequence of ratios, displayed as %.
Base class to print a nice summary of a group of statistics.
ColumnPriorityQueue(const ColumnPriorityQueue &)=delete
This type is neither copyable nor movable.
void PushOrAdjust(ColIndex col, int32_t degree)
ColumnPriorityQueue()=default
ColumnPriorityQueue & operator=(const ColumnPriorityQueue &)=delete
void Reset(int32_t max_degree, ColIndex num_cols)
Markowitz & operator=(const Markowitz &)=delete
void Clear()
Releases the memory used by this class.
std::string StatString() const
Returns a string containing the statistics for this class.
ABSL_MUST_USE_RESULT Status ComputeRowAndColumnPermutation(const CompactSparseMatrixView &basis_matrix, RowPermutation *row_perm, ColumnPermutation *col_perm)
double DeterministicTimeOfLastFactorization() const
Returns an estimate of the time spent in the last factorization.
ABSL_MUST_USE_RESULT Status ComputeLU(const CompactSparseMatrixView &basis_matrix, RowPermutation *row_perm, ColumnPermutation *col_perm, TriangularMatrix *lower, TriangularMatrix *upper)
Markowitz(const Markowitz &)=delete
This type is neither copyable nor movable.
void SetParameters(const GlopParameters ¶meters)
Sets the current parameters.
int32_t DecreaseColDegree(ColIndex col)
void AddEntry(RowIndex row, ColIndex col)
Adds a non-zero entry to the matrix. There should be no duplicates.
bool IsColumnDeleted(ColIndex col) const
Returns true if the column has been deleted by DeleteRowAndColumn().
MatrixNonZeroPattern()=default
int32_t ColDegree(ColIndex col) const
MatrixNonZeroPattern(const MatrixNonZeroPattern &)=delete
This type is neither copyable nor movable.
void InitializeFromMatrixSubset(const CompactSparseMatrixView &basis_matrix, StrictITISpan< RowIndex, const RowIndex > row_perm, StrictITISpan< ColIndex, const ColIndex > col_perm, std::vector< ColIndex > *singleton_columns, std::vector< RowIndex > *singleton_rows)
ColIndex GetFirstNonDeletedColumnFromRow(RowIndex row) const
const absl::InlinedVector< ColIndex, 6 > & RowNonZero(RowIndex row) const
int32_t DecreaseRowDegree(RowIndex row)
MatrixNonZeroPattern & operator=(const MatrixNonZeroPattern &)=delete
void Reset(RowIndex num_rows, ColIndex num_cols)
Resets the pattern to the one of an empty square matrix of the given size.
void DeleteRowAndColumn(RowIndex pivot_row, ColIndex pivot_col)
void RemoveDeletedColumnsFromRow(RowIndex row)
void Update(RowIndex pivot_row, ColIndex pivot_col, const SparseColumn &column)
int32_t RowDegree(RowIndex row) const
void Clear()
Releases the memory used by this class.
SparseMatrixWithReusableColumnMemory(const SparseMatrixWithReusableColumnMemory &)=delete
This type is neither copyable nor movable.
void ClearAndReleaseColumn(ColIndex col)
SparseMatrixWithReusableColumnMemory()=default
const SparseColumn & column(ColIndex col) const
Returns the column with given index.
SparseColumn * mutable_column(ColIndex col)
void Reset(ColIndex num_cols)
Resets the repository to num_cols empty columns.
SparseMatrixWithReusableColumnMemory & operator=(const SparseMatrixWithReusableColumnMemory &)=delete
Permutation< ColIndex > ColumnPermutation
Permutation< RowIndex > RowPermutation
StrictITIVector< ColIndex, bool > DenseBooleanRow
Row of booleans.
In SWIG mode, we don't want anything besides these top-level includes.
util_intops::StrongVector< ColumnEntryIndex, ElementIndex > SparseColumn