![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
Another matrix representation which is more efficient than a SparseMatrix but doesn't allow matrix modification. It is faster to construct, uses less memory and provides a better cache locality when iterating over the non-zeros of the matrix columns.
#include <sparse.h>
Classes | |
| class | ConstView |
Public Member Functions | |
| CompactSparseMatrix ()=default | |
| ConstView | view () const |
| CompactSparseMatrix (const SparseMatrix &matrix) | |
| CompactSparseMatrix (const CompactSparseMatrix &)=delete | |
| This type is neither copyable nor movable. | |
| CompactSparseMatrix & | operator= (const CompactSparseMatrix &)=delete |
| void | PopulateFromMatrixView (const MatrixView &input) |
| void | PopulateFromSparseMatrixAndAddSlacks (const SparseMatrix &input) |
| void | PopulateFromTranspose (const CompactSparseMatrix &input) |
| void | Reset (RowIndex num_rows) |
| void | AddEntryToCurrentColumn (RowIndex row, Fractional coeff) |
| Api to add columns one at the time. | |
| void | CloseCurrentColumn () |
| ColIndex | AddDenseColumn (const DenseColumn &dense_column) |
| ColIndex | AddDenseColumnPrefix (DenseColumn::ConstView dense_column, RowIndex start) |
| Same as AddDenseColumn(), but only adds the non-zero from the given start. | |
| ColIndex | AddDenseColumnWithNonZeros (const DenseColumn &dense_column, absl::Span< const RowIndex > non_zeros) |
| ColIndex | AddAndClearColumnWithNonZeros (DenseColumn *column, std::vector< RowIndex > *non_zeros) |
| EntryIndex | ColumnNumEntries (ColIndex col) const |
| Returns the number of entries (i.e. degree) of the given column. | |
| EntryIndex | num_entries () const |
| Returns the matrix dimensions. See same functions in SparseMatrix. | |
| RowIndex | num_rows () const |
| ColIndex | num_cols () const |
| bool | IsEmpty () const |
| Returns whether or not this matrix contains any non-zero entries. | |
| ColumnView | column (ColIndex col) const |
| bool | ColumnIsEmpty (ColIndex col) const |
| Fractional | ColumnScalarProduct (ColIndex col, const DenseRow &vector) const |
| void | ColumnAddMultipleToDenseColumn (ColIndex col, Fractional multiplier, DenseColumn::View dense_column) const |
| void | ColumnAddMultipleToDenseColumn (ColIndex col, Fractional multiplier, DenseColumn *dense_column) const |
| void | ColumnAddMultipleToSparseScatteredColumn (ColIndex col, Fractional multiplier, ScatteredColumn *column) const |
| void | ColumnCopyToDenseColumn (ColIndex col, DenseColumn *dense_column) const |
| void | ColumnCopyToClearedDenseColumn (ColIndex col, DenseColumn *dense_column) const |
| void | ColumnCopyToClearedDenseColumnWithNonZeros (ColIndex col, DenseColumn *dense_column, RowIndexVector *non_zeros) const |
| Same as ColumnCopyToClearedDenseColumn() but also fills non_zeros. | |
| void | Swap (CompactSparseMatrix *other) |
Protected Member Functions | |
| ::util::IntegerRange< EntryIndex > | Column (ColIndex col) const |
| Functions to iterate on the entries of a given column. | |
Protected Attributes | |
| RowIndex | num_rows_ |
| The matrix dimensions, properly updated by full and incremental builders. | |
| ColIndex | num_cols_ |
| StrictITIVector< EntryIndex, Fractional > | coefficients_ |
| StrictITIVector< EntryIndex, RowIndex > | rows_ |
| StrictITIVector< ColIndex, EntryIndex > | starts_ |
|
default |
|
inlineexplicit |
|
delete |
This type is neither copyable nor movable.
| ColIndex operations_research::glop::CompactSparseMatrix::AddAndClearColumnWithNonZeros | ( | DenseColumn * | column, |
| std::vector< RowIndex > * | non_zeros ) |
Adds a dense column for which we know the non-zero positions and clears it.
| ColIndex operations_research::glop::CompactSparseMatrix::AddDenseColumn | ( | const DenseColumn & | dense_column | ) |
Adds a dense column to the CompactSparseMatrix (only the non-zero will be actually stored). This work in O(input.size()) and returns the index of the added column.
| ColIndex operations_research::glop::CompactSparseMatrix::AddDenseColumnPrefix | ( | DenseColumn::ConstView | dense_column, |
| RowIndex | start ) |
Same as AddDenseColumn(), but only adds the non-zero from the given start.
| ColIndex operations_research::glop::CompactSparseMatrix::AddDenseColumnWithNonZeros | ( | const DenseColumn & | dense_column, |
| absl::Span< const RowIndex > | non_zeros ) |
Same as AddDenseColumn(), but uses the given non_zeros pattern of input. If non_zeros is empty, this actually calls AddDenseColumn().
| void operations_research::glop::CompactSparseMatrix::AddEntryToCurrentColumn | ( | RowIndex | row, |
| Fractional | coeff ) |
| void operations_research::glop::CompactSparseMatrix::CloseCurrentColumn | ( | ) |
|
inlineprotected |
|
inline |
Alternative iteration API compatible with the one from SparseMatrix. The ConstView alternative should be faster.
|
inline |
|
inline |
|
inline |
Same as ColumnAddMultipleToDenseColumn() but also adds the new non-zeros to the non_zeros vector. A non-zero is "new" if is_non_zero[row] was false, and we update dense_column[row]. This function also updates is_non_zero.
|
inline |
Same as ColumnCopyToDenseColumn() but assumes the column to be initially all zero.
|
inline |
Same as ColumnCopyToClearedDenseColumn() but also fills non_zeros.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Returns the matrix dimensions. See same functions in SparseMatrix.
|
inline |
|
delete |
| void operations_research::glop::CompactSparseMatrix::PopulateFromMatrixView | ( | const MatrixView & | input | ) |
Creates a CompactSparseMatrix from the given MatrixView. The matrices are the same, only the representation differ. Note that the entry order in each column is preserved.
| void operations_research::glop::CompactSparseMatrix::PopulateFromSparseMatrixAndAddSlacks | ( | const SparseMatrix & | input | ) |
Creates a CompactSparseMatrix by copying the input and adding an identity matrix to the left of it.
| void operations_research::glop::CompactSparseMatrix::PopulateFromTranspose | ( | const CompactSparseMatrix & | input | ) |
Creates a CompactSparseMatrix from the transpose of the given CompactSparseMatrix. Note that the entries in each columns will be ordered by row indices.
Fill the starts_ vector by computing the number of entries of each rows and then doing a cumulative sum. After this step starts_[col + 1] will be the actual start of the column col when we are done.
Use starts_ to fill the matrix. Note that starts_ is modified so that at the end it has its final values.
| void operations_research::glop::CompactSparseMatrix::Reset | ( | RowIndex | num_rows | ) |
| void operations_research::glop::CompactSparseMatrix::Swap | ( | CompactSparseMatrix * | other | ) |
|
inline |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |