Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <markowitz.h>
Public Member Functions | |
MatrixNonZeroPattern ()=default | |
MatrixNonZeroPattern (const MatrixNonZeroPattern &)=delete | |
This type is neither copyable nor movable. | |
MatrixNonZeroPattern & | operator= (const MatrixNonZeroPattern &)=delete |
void | Clear () |
Releases the memory used by this class. | |
void | Reset (RowIndex num_rows, ColIndex num_cols) |
Resets the pattern to the one of an empty square matrix of the given size. | |
void | InitializeFromMatrixSubset (const CompactSparseMatrixView &basis_matrix, const RowPermutation &row_perm, const ColumnPermutation &col_perm, std::vector< ColIndex > *singleton_columns, std::vector< RowIndex > *singleton_rows) |
void | AddEntry (RowIndex row, ColIndex col) |
Adds a non-zero entry to the matrix. There should be no duplicates. | |
void | DeleteRowAndColumn (RowIndex pivot_row, ColIndex pivot_col) |
int32_t | DecreaseRowDegree (RowIndex row) |
int32_t | DecreaseColDegree (ColIndex col) |
bool | IsColumnDeleted (ColIndex col) const |
Returns true if the column has been deleted by DeleteRowAndColumn(). | |
void | RemoveDeletedColumnsFromRow (RowIndex row) |
ColIndex | GetFirstNonDeletedColumnFromRow (RowIndex row) const |
void | Update (RowIndex pivot_row, ColIndex pivot_col, const SparseColumn &column) |
int32_t | ColDegree (ColIndex col) const |
int32_t | RowDegree (RowIndex row) const |
const absl::InlinedVector< ColIndex, 6 > & | RowNonZero (RowIndex row) const |
Holds the non-zero positions (by row) and column/row degree of the residual matrix during the Gaussian elimination.
During each step of Gaussian elimination, a row and a column will be "removed" from the residual matrix. Note however that the row and column indices of the non-removed part do not change, so the residual matrix at a given step will only correspond to a subset of the initial indices.
Definition at line 102 of file markowitz.h.
|
default |
|
delete |
This type is neither copyable nor movable.
void operations_research::glop::MatrixNonZeroPattern::AddEntry | ( | RowIndex | row, |
ColIndex | col ) |
Adds a non-zero entry to the matrix. There should be no duplicates.
Definition at line 632 of file markowitz.cc.
void operations_research::glop::MatrixNonZeroPattern::Clear | ( | ) |
Releases the memory used by this class.
Definition at line 561 of file markowitz.cc.
|
inline |
Returns the degree (i.e. the number of non-zeros) of the given column. This is only valid for the column indices still in the residual matrix.
Definition at line 162 of file markowitz.h.
int32_t operations_research::glop::MatrixNonZeroPattern::DecreaseColDegree | ( | ColIndex | col | ) |
Definition at line 638 of file markowitz.cc.
int32_t operations_research::glop::MatrixNonZeroPattern::DecreaseRowDegree | ( | RowIndex | row | ) |
Decreases the degree of a row/column. This is the basic operation used to keep the correct degree after a call to DeleteRowAndColumn(). This is because row_non_zero_[row] is only lazily cleaned.
Definition at line 642 of file markowitz.cc.
void operations_research::glop::MatrixNonZeroPattern::DeleteRowAndColumn | ( | RowIndex | pivot_row, |
ColIndex | pivot_col ) |
Marks the given pivot row and column as deleted. This is called at each step of the Gaussian elimination on the pivot.
We do that to optimize RemoveColumnFromResidualMatrix().
Definition at line 646 of file markowitz.cc.
ColIndex operations_research::glop::MatrixNonZeroPattern::GetFirstNonDeletedColumnFromRow | ( | RowIndex | row | ) | const |
Returns the first non-deleted column index from this row or kInvalidCol if none can be found.
Definition at line 674 of file markowitz.cc.
void operations_research::glop::MatrixNonZeroPattern::InitializeFromMatrixSubset | ( | const CompactSparseMatrixView & | basis_matrix, |
const RowPermutation & | row_perm, | ||
const ColumnPermutation & | col_perm, | ||
std::vector< ColIndex > * | singleton_columns, | ||
std::vector< RowIndex > * | singleton_rows ) |
Resets the pattern to the one of the given matrix but only for the rows/columns whose given permutation is kInvalidRow or kInvalidCol. This also fills the singleton columns/rows with the corresponding entries.
Reset the matrix and initialize the vectors to the correct sizes.
Compute the number of entries in each row.
Reserve the row_non_zero_ vector sizes.
This is needed because in the row degree computation above, we do not test for row_perm[row] == kInvalidRow because it is a bit faster.
Initialize row_non_zero_.
Definition at line 580 of file markowitz.cc.
bool operations_research::glop::MatrixNonZeroPattern::IsColumnDeleted | ( | ColIndex | col | ) | const |
Returns true if the column has been deleted by DeleteRowAndColumn().
Definition at line 656 of file markowitz.cc.
|
delete |
void operations_research::glop::MatrixNonZeroPattern::RemoveDeletedColumnsFromRow | ( | RowIndex | row | ) |
Removes from the corresponding row_non_zero_[row] the columns that have been previously deleted by DeleteRowAndColumn().
Definition at line 660 of file markowitz.cc.
void operations_research::glop::MatrixNonZeroPattern::Reset | ( | RowIndex | num_rows, |
ColIndex | num_cols ) |
Resets the pattern to the one of an empty square matrix of the given size.
Definition at line 570 of file markowitz.cc.
|
inline |
Returns the degree (i.e. the number of non-zeros) of the given row. This is only valid for the row indices still in the residual matrix.
Definition at line 169 of file markowitz.h.
|
inline |
Returns the set of non-zeros of the given row (unsorted). Call RemoveDeletedColumnsFromRow(row) to clean the row first. This is only valid for the row indices still in the residual matrix.
Definition at line 174 of file markowitz.h.
void operations_research::glop::MatrixNonZeroPattern::Update | ( | RowIndex | pivot_row, |
ColIndex | pivot_col, | ||
const SparseColumn & | column ) |
Performs a generic Gaussian update of the residual matrix:
Important: as a small optimization, this function does not call DecreaseRowDegree() on the row in the pivot column. This has to be done by the client.
Since DeleteRowAndColumn() must be called just before this function, the pivot column has been marked as deleted but degrees have not been updated yet. Hence the +1.
We only need to merge the row for the position with a coefficient different from 0.0. Note that the column must contain all the symbolic non-zeros for the row degree to be updated correctly. Note also that decreasing the row degrees due to the deletion of pivot_col will happen outside this function.
If the row is fully dense, there is nothing to do (the merge below will not change anything). This is a small price to pay for a huge gain when the matrix becomes dense.
We only clean row_non_zero_[row] if there are more than 4 entries to delete. Note(user): the 4 is somewhat arbitrary, but gives good results on the Netlib (23/04/2013). Note that calling RemoveDeletedColumnsFromRow() is not mandatory and does not change the LU decomposition, so we could call it all the time or never and the algorithm would still work.
This is currently not used, but kept as an alternative algorithm to investigate. The performance is really similar, but the final L.U is different. Note that when this is used, there is no need to modify bool_scratchpad_ at the beginning of this function.
Definition at line 682 of file markowitz.cc.