Sparse Matrix Base Class. More...
#include <CoinPackedMatrix.hpp>
Public Member Functions | |
Query members | |
double | getExtraGap () const |
Return the current setting of the extra gap. | |
double | getExtraMajor () const |
Return the current setting of the extra major. | |
void | reserve (const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false) |
Reserve sufficient space for appending major-ordered vectors. | |
void | clear () |
Clear the data, but do not free any arrays. | |
bool | isColOrdered () const |
Whether the packed matrix is column major ordered or not. | |
CoinBigIndex | getNumElements () const |
Number of entries in the packed matrix. | |
int | getNumCols () const |
Number of columns. | |
int | getNumRows () const |
Number of rows. | |
const double * | getElements () const |
A vector containing the elements in the packed matrix. | |
const int * | getIndices () const |
A vector containing the minor indices of the elements in the packed matrix. | |
int | getSizeVectorStarts () const |
The size of the vectorStarts array. | |
int | getSizeVectorLengths () const |
The size of the vectorLengths array. | |
const CoinBigIndex * | getVectorStarts () const |
The positions where the major-dimension vectors start in elements and indices. | |
const int * | getVectorLengths () const |
The lengths of the major-dimension vectors. | |
CoinBigIndex | getVectorFirst (const int i) const |
The position of the first element in the i'th major-dimension vector. | |
CoinBigIndex | getVectorLast (const int i) const |
The position of the last element (well, one entry past the last) in the i'th major-dimension vector. | |
int | getVectorSize (const int i) const |
The length of i'th vector. | |
const CoinShallowPackedVector | getVector (int i) const |
Return the i'th vector in matrix. | |
int * | getMajorIndices () const |
Returns an array containing major indices. | |
Modifying members. | |
void | setDimensions (int numrows, int numcols) |
Set the dimansions of the matrix. | |
void | setExtraGap (const double newGap) |
Set the extra gap to be allocated to the specified value. | |
void | setExtraMajor (const double newMajor) |
Set the extra major to be allocated to the specified value. | |
void | appendCol (const CoinPackedVectorBase &vec) |
Append a column to the end of the matrix. | |
void | appendCol (const int vecsize, const int *vecind, const double *vecelem) |
Append a column to the end of the matrix. | |
void | appendCols (const int numcols, const CoinPackedVectorBase *const *cols) |
Append a set of columns to the end of the matrix. | |
int | appendCols (const int numcols, const CoinBigIndex *columnStarts, const int *row, const double *element, int numberRows=-1) |
Append a set of columns to the end of the matrix. | |
void | appendRow (const CoinPackedVectorBase &vec) |
Append a row to the end of the matrix. | |
void | appendRow (const int vecsize, const int *vecind, const double *vecelem) |
Append a row to the end of the matrix. | |
void | appendRows (const int numrows, const CoinPackedVectorBase *const *rows) |
Append a set of rows to the end of the matrix. | |
int | appendRows (const int numrows, const CoinBigIndex *rowStarts, const int *column, const double *element, int numberColumns=-1) |
Append a set of rows to the end of the matrix. | |
void | rightAppendPackedMatrix (const CoinPackedMatrix &matrix) |
Append the argument to the "right" of the current matrix. | |
void | bottomAppendPackedMatrix (const CoinPackedMatrix &matrix) |
Append the argument to the "bottom" of the current matrix. | |
void | deleteCols (const int numDel, const int *indDel) |
Delete the columns whose indices are listed in indDel . | |
void | deleteRows (const int numDel, const int *indDel) |
Delete the rows whose indices are listed in indDel . | |
void | replaceVector (const int index, const int numReplace, const double *newElements) |
Replace the elements of a vector. | |
void | modifyCoefficient (int row, int column, double newElement, bool keepZero=false) |
Modify one element of packed matrix. | |
double | getCoefficient (int row, int column) const |
Return one element of packed matrix. | |
int | compress (double threshold) |
Eliminate all elements in matrix whose absolute value is less than threshold. | |
int | eliminateDuplicates (double threshold) |
Eliminate all duplicate AND small elements in matrix The column starts are not affected. | |
void | orderMatrix () |
Sort all columns so indices are increasing.in each column. | |
int | cleanMatrix (double threshold=1.0e-20) |
Really clean up matrix. | |
Methods that reorganize the whole matrix | |
void | removeGaps (double removeValue=-1.0) |
Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValue. | |
void | submatrixOf (const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor) |
Extract a submatrix from matrix. | |
void | submatrixOfWithDuplicates (const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor) |
Extract a submatrix from matrix. | |
void | copyOf (const CoinPackedMatrix &rhs) |
Copy method. | |
void | copyOf (const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len, const double extraMajor=0.0, const double extraGap=0.0) |
Copy the arguments to the matrix. | |
void | copyReuseArrays (const CoinPackedMatrix &rhs) |
Copy method. | |
void | reverseOrderedCopyOf (const CoinPackedMatrix &rhs) |
Reverse copy method. | |
void | assignMatrix (const bool colordered, const int minor, const int major, const CoinBigIndex numels, double *&elem, int *&ind, CoinBigIndex *&start, int *&len, const int maxmajor=-1, const CoinBigIndex maxsize=-1) |
Assign the arguments to the matrix. | |
CoinPackedMatrix & | operator= (const CoinPackedMatrix &rhs) |
Assignment operator. | |
void | reverseOrdering () |
Reverse the ordering of the packed matrix. | |
void | transpose () |
Transpose the matrix. | |
void | swap (CoinPackedMatrix &matrix) |
Swap the content of the two packed matrix. | |
Matrix times vector methods | |
void | times (const double *x, double *y) const |
Return A * x in y . | |
void | times (const CoinPackedVectorBase &x, double *y) const |
Return A * x in y . | |
void | transposeTimes (const double *x, double *y) const |
Return x * A in y . | |
void | transposeTimes (const CoinPackedVectorBase &x, double *y) const |
Return x * A in y . | |
Queries | |
int * | countOrthoLength () const |
Count the number of entries in every minor-dimension vector and return an array containing these lengths. | |
void | countOrthoLength (int *counts) const |
Count the number of entries in every minor-dimension vector and fill in an array containing these lengths. | |
int | getMajorDim () const |
Major dimension. | |
int | getMinorDim () const |
Minor dimension. | |
int | getMaxMajorDim () const |
Current maximum for major dimension. | |
void | dumpMatrix (const char *fname=NULL) const |
Dump the matrix on stdout. | |
void | printMatrixElement (const int row_val, const int col_val) const |
Print a single matrix element. | |
Append vectors. <br> | |
void | appendMajorVector (const CoinPackedVectorBase &vec) |
Append a major-dimension vector to the end of the matrix. | |
void | appendMajorVector (const int vecsize, const int *vecind, const double *vecelem) |
Append a major-dimension vector to the end of the matrix. | |
void | appendMajorVectors (const int numvecs, const CoinPackedVectorBase *const *vecs) |
Append several major-dimensonvectors to the end of the matrix. | |
void | appendMinorVector (const CoinPackedVectorBase &vec) |
Append a minor-dimension vector to the end of the matrix. | |
void | appendMinorVector (const int vecsize, const int *vecind, const double *vecelem) |
Append a minor-dimension vector to the end of the matrix. | |
void | appendMinorVectors (const int numvecs, const CoinPackedVectorBase *const *vecs) |
Append several minor-dimensonvectors to the end of the matrix. | |
Append matrices. | |
void | majorAppendSameOrdered (const CoinPackedMatrix &matrix) |
Append the columns of the argument to the right end of this matrix. | |
void | minorAppendSameOrdered (const CoinPackedMatrix &matrix) |
Append the columns of the argument to the bottom end of this matrix. | |
void | majorAppendOrthoOrdered (const CoinPackedMatrix &matrix) |
Append the rows of the argument to the right end of this matrix. | |
void | minorAppendOrthoOrdered (const CoinPackedMatrix &matrix) |
Append the rows of the argument to the bottom end of this matrix. | |
Delete vectors | |
void | deleteMajorVectors (const int numDel, const int *indDel) |
Delete the major-dimension vectors whose indices are listed in indDel . | |
void | deleteMinorVectors (const int numDel, const int *indDel) |
Delete the minor-dimension vectors whose indices are listed in indDel . | |
Various dot products. | |
void | timesMajor (const double *x, double *y) const |
Return A * x (multiplied from the "right" direction) in y . | |
void | timesMajor (const CoinPackedVectorBase &x, double *y) const |
Return A * x (multiplied from the "right" direction) in y . | |
void | timesMinor (const double *x, double *y) const |
Return A * x (multiplied from the "right" direction) in y . | |
void | timesMinor (const CoinPackedVectorBase &x, double *y) const |
Return A * x (multiplied from the "right" direction) in y . | |
Logical Operations. | |
template<class FloatEqual > | |
bool | isEquivalent (const CoinPackedMatrix &rhs, const FloatEqual &eq) const |
Equivalence. | |
bool | isEquivalent2 (const CoinPackedMatrix &rhs) const |
Equivalence. | |
bool | isEquivalent (const CoinPackedMatrix &rhs) const |
The default equivalence test is that the entries are relatively equal. | |
non const methods. | |
double * | getMutableElements () const |
A vector containing the elements in the packed matrix. | |
int * | getMutableIndices () const |
A vector containing the minor indices of the elements in the packed matrix. | |
CoinBigIndex * | getMutableVectorStarts () const |
The positions where the major-dimension vectors start in elements and indices. | |
int * | getMutableVectorLengths () const |
The lengths of the major-dimension vectors. | |
void | setNumElements (CoinBigIndex value) |
Change size after modifying - be careful. | |
void | nullElementArray () |
NULLify element array - used when space is very tight. | |
void | nullStartArray () |
NULLify start array - used when space is very tight. | |
void | nullLengthArray () |
NULLify length array - used when space is very tight. | |
void | nullIndexArray () |
NULLify index array - used when space is very tight. | |
Constructors, destructors and major modifying methods | |
CoinPackedMatrix () | |
Default Constructor creates an empty column ordered packed matrix. | |
CoinPackedMatrix (const bool colordered, const double extraMajor, const double extraGap) | |
A constructor where the ordering and the gaps are specified. | |
CoinPackedMatrix (const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len, const double extraMajor, const double extraGap) | |
Default Constructor creates an empty column ordered packed matrix. | |
CoinPackedMatrix (const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len) | |
Default Constructor creates an empty column ordered packed matrix. | |
CoinPackedMatrix (const bool colordered, const int *rowIndices, const int *colIndices, const double *elements, CoinBigIndex numels) | |
Create packed matrix from triples. | |
CoinPackedMatrix (const CoinPackedMatrix &m) | |
Copy constructor. | |
CoinPackedMatrix (const CoinPackedMatrix &m, int extraForMajor, int extraElements, bool reverseOrdering=false) | |
Copy constructor - fine tuning - allowing extra space and/or reverse ordering. | |
CoinPackedMatrix (const CoinPackedMatrix &wholeModel, int numberRows, const int *whichRows, int numberColumns, const int *whichColumns) | |
Subset constructor (without gaps). | |
virtual | ~CoinPackedMatrix () |
Destructor. | |
Protected Member Functions | |
void | gutsOfDestructor () |
void | gutsOfCopyOf (const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len, const double extraMajor=0.0, const double extraGap=0.0) |
void | gutsOfCopyOfNoGaps (const bool colordered, const int minor, const int major, const double *elem, const int *ind, const CoinBigIndex *start) |
When no gaps we can do faster. | |
void | gutsOfOpEqual (const bool colordered, const int minor, const int major, const CoinBigIndex numels, const double *elem, const int *ind, const CoinBigIndex *start, const int *len) |
void | resizeForAddingMajorVectors (const int numVec, const int *lengthVec) |
void | resizeForAddingMinorVectors (const int *addedEntries) |
int | appendMajor (const int number, const CoinBigIndex *starts, const int *index, const double *element, int numberOther=-1) |
Append a set of rows/columns to the end of the matrix. | |
int | appendMinor (const int number, const CoinBigIndex *starts, const int *index, const double *element, int numberOther=-1) |
Append a set of rows/columns to the end of the matrix. | |
Protected Attributes | |
Data members | |
bool | colOrdered_ |
A flag indicating whether the matrix is column or row major ordered. | |
double | extraGap_ |
This much times more space should be allocated for each major-dimension vector (with respect to the number of entries in the vector) when the matrix is resized. | |
double | extraMajor_ |
his much times more space should be allocated for major-dimension vectors when the matrix is resized. | |
double * | element_ |
List of nonzero element values. | |
int * | index_ |
List of nonzero element minor-dimension indices. | |
CoinBigIndex * | start_ |
Starting positions of major-dimension vectors. | |
int * | length_ |
Lengths of major-dimension vectors. | |
int | majorDim_ |
number of vectors in matrix | |
int | minorDim_ |
size of other dimension | |
CoinBigIndex | size_ |
the number of nonzero entries | |
int | maxMajorDim_ |
max space allocated for major-dimension | |
CoinBigIndex | maxSize_ |
max space allocated for entries | |
Private Member Functions | |
CoinBigIndex | getLastStart () const |
Friends | |
void | CoinPackedMatrixUnitTest () |
A function that tests the methods in the CoinPackedMatrix class. |
Sparse Matrix Base Class.
This class is used for storing a matrix by rows or columns.
The sparse represention can be completely compact or it can have "extra" space. The extra space can be added at the end of rows and/or columns. Incorporating extra space into the sparse matrix representation can improve performance in cases where new data needs to be inserted into the packed matrix.
For example if the matrix:
3 1 0 -2 -1 0 0 -1 0 2 1.1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 2.8 0 0 -1.2 0 5.6 0 0 0 1 0 0 1.9 was stored by rows (with no extra space) in CoinPackedMatrix r then: r.getElements() returns a vector containing: 3 1 -2 -1 -1 2 1.1 1 1 2.8 -1.2 5.6 1 1.9 r.getIndices() returns a vector containing: 0 1 3 4 7 1 2 2 5 3 6 0 4 7 r.getVectorStarts() returns a vector containing: 0 5 7 9 11 14 r.getNumElements() returns 14. r.getMajorDim() returns 5. r.getVectorSize(0) returns 5. r.getVectorSize(1) returns 2. r.getVectorSize(2) returns 2. r.getVectorSize(3) returns 2. r.getVectorSize(4) returns 3. If stored by columns (with no extra space) then: c.getElements() returns a vector containing: 3 5.6 1 2 1.1 1 -2 2.8 -1 1 1 -1.2 -1 1.9 c.getIndices() returns a vector containing: 0 4 0 1 1 2 0 3 0 4 2 3 0 4 c.getVectorStarts() returns a vector containing: 0 2 4 6 8 10 11 12 14 c.getNumElements() returns 14. c.getMajorDim() returns 8.
Definition at line 61 of file CoinPackedMatrix.hpp.
CoinPackedMatrix::CoinPackedMatrix | ( | ) |
Default Constructor creates an empty column ordered packed matrix.
CoinPackedMatrix::CoinPackedMatrix | ( | const bool | colordered, | |
const double | extraMajor, | |||
const double | extraGap | |||
) |
A constructor where the ordering and the gaps are specified.
CoinPackedMatrix::CoinPackedMatrix | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start, | |||
const int * | len, | |||
const double | extraMajor, | |||
const double | extraGap | |||
) |
Default Constructor creates an empty column ordered packed matrix.
CoinPackedMatrix::CoinPackedMatrix | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start, | |||
const int * | len | |||
) |
Default Constructor creates an empty column ordered packed matrix.
CoinPackedMatrix::CoinPackedMatrix | ( | const bool | colordered, | |
const int * | rowIndices, | |||
const int * | colIndices, | |||
const double * | elements, | |||
CoinBigIndex | numels | |||
) |
Create packed matrix from triples.
If colordered is true then the created matrix will be column ordered. Duplicate matrix elements are allowed. The created matrix will have the sum of the duplicates.
For example if:
rowIndices[0]=2; colIndices[0]=5; elements[0]=2.0
rowIndices[1]=2; colIndices[1]=5; elements[1]=0.5
then the created matrix will contain a value of 2.5 in row 2 and column 5.
The matrix is created without gaps.
CoinPackedMatrix::CoinPackedMatrix | ( | const CoinPackedMatrix & | m | ) |
Copy constructor.
CoinPackedMatrix::CoinPackedMatrix | ( | const CoinPackedMatrix & | m, | |
int | extraForMajor, | |||
int | extraElements, | |||
bool | reverseOrdering = false | |||
) |
Copy constructor - fine tuning - allowing extra space and/or reverse ordering.
extraForMajor is exact extra after any possible reverse ordering. extraMajor_ and extraGap_ set to zero.
CoinPackedMatrix::CoinPackedMatrix | ( | const CoinPackedMatrix & | wholeModel, | |
int | numberRows, | |||
const int * | whichRows, | |||
int | numberColumns, | |||
const int * | whichColumns | |||
) |
Subset constructor (without gaps).
Duplicates are allowed and order is as given
virtual CoinPackedMatrix::~CoinPackedMatrix | ( | ) | [virtual] |
Destructor.
double CoinPackedMatrix::getExtraGap | ( | ) | const [inline] |
Return the current setting of the extra gap.
Definition at line 71 of file CoinPackedMatrix.hpp.
double CoinPackedMatrix::getExtraMajor | ( | ) | const [inline] |
Return the current setting of the extra major.
Definition at line 73 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::reserve | ( | const int | newMaxMajorDim, | |
const CoinBigIndex | newMaxSize, | |||
bool | create = false | |||
) |
Reserve sufficient space for appending major-ordered vectors.
If create is true, empty columns are created (for column generation)
void CoinPackedMatrix::clear | ( | ) |
Clear the data, but do not free any arrays.
Reimplemented in BCP_lp_relax.
bool CoinPackedMatrix::isColOrdered | ( | ) | const [inline] |
Whether the packed matrix is column major ordered or not.
Definition at line 83 of file CoinPackedMatrix.hpp.
CoinBigIndex CoinPackedMatrix::getNumElements | ( | ) | const [inline] |
Number of entries in the packed matrix.
Definition at line 85 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getNumCols | ( | ) | const [inline] |
Number of columns.
Definition at line 87 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getNumRows | ( | ) | const [inline] |
Number of rows.
Definition at line 89 of file CoinPackedMatrix.hpp.
const double* CoinPackedMatrix::getElements | ( | ) | const [inline] |
A vector containing the elements in the packed matrix.
Note that there might be gaps in this list, entries that do not belong to any major-dimension vector. To get the actual elements one should look at this vector together with vectorStarts and vectorLengths.
Definition at line 95 of file CoinPackedMatrix.hpp.
const int* CoinPackedMatrix::getIndices | ( | ) | const [inline] |
A vector containing the minor indices of the elements in the packed matrix.
Note that there might be gaps in this list, entries that do not belong to any major-dimension vector. To get the actual elements one should look at this vector together with vectorStarts and vectorLengths.
Definition at line 101 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getSizeVectorStarts | ( | ) | const [inline] |
The size of the vectorStarts
array.
Definition at line 104 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getSizeVectorLengths | ( | ) | const [inline] |
The size of the vectorLengths
array.
Definition at line 106 of file CoinPackedMatrix.hpp.
const CoinBigIndex* CoinPackedMatrix::getVectorStarts | ( | ) | const [inline] |
The positions where the major-dimension vectors start in elements and indices.
Definition at line 109 of file CoinPackedMatrix.hpp.
const int* CoinPackedMatrix::getVectorLengths | ( | ) | const [inline] |
The lengths of the major-dimension vectors.
Definition at line 111 of file CoinPackedMatrix.hpp.
CoinBigIndex CoinPackedMatrix::getVectorFirst | ( | const int | i | ) | const [inline] |
The position of the first element in the i'th major-dimension vector.
Definition at line 116 of file CoinPackedMatrix.hpp.
CoinBigIndex CoinPackedMatrix::getVectorLast | ( | const int | i | ) | const [inline] |
The position of the last element (well, one entry past the last) in the i'th major-dimension vector.
Definition at line 123 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getVectorSize | ( | const int | i | ) | const [inline] |
The length of i'th vector.
Definition at line 129 of file CoinPackedMatrix.hpp.
const CoinShallowPackedVector CoinPackedMatrix::getVector | ( | int | i | ) | const [inline] |
Return the i'th vector in matrix.
Definition at line 136 of file CoinPackedMatrix.hpp.
int* CoinPackedMatrix::getMajorIndices | ( | ) | const |
Returns an array containing major indices.
The array is getNumElements long and if getVectorStarts() is 0,2,5 then the array would start 0,0,1,1,1,2... This method is provided to go back from a packed format to a triple format. It returns NULL if there are gaps in matrix so user should use removeGaps() if there are any gaps. It does this as this array has to match getElements() and getIndices() and because it makes no sense otherwise. The returned array is allocated with new int[]
, free it with delete[]
.
void CoinPackedMatrix::setDimensions | ( | int | numrows, | |
int | numcols | |||
) |
Set the dimansions of the matrix.
In effect, append new empty columns/rows to the matrix. A negative number for either dimension means that that dimension doesn't change. Otherwise the new dimensions MUST be at least as large as the current ones otherwise an exception is thrown.
void CoinPackedMatrix::setExtraGap | ( | const double | newGap | ) |
Set the extra gap to be allocated to the specified value.
void CoinPackedMatrix::setExtraMajor | ( | const double | newMajor | ) |
Set the extra major to be allocated to the specified value.
void CoinPackedMatrix::appendCol | ( | const CoinPackedVectorBase & | vec | ) |
Append a column to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if the new column contains an index that's larger than the number of rows (-1). Otherwise the method assumes that every index fits into the matrix.
void CoinPackedMatrix::appendCol | ( | const int | vecsize, | |
const int * | vecind, | |||
const double * | vecelem | |||
) |
Append a column to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if the new column contains an index that's larger than the number of rows (-1). Otherwise the method assumes that every index fits into the matrix.
void CoinPackedMatrix::appendCols | ( | const int | numcols, | |
const CoinPackedVectorBase *const * | cols | |||
) |
Append a set of columns to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if any of the new columns contain an index that's larger than the number of rows (-1). Otherwise the method assumes that every index fits into the matrix.
int CoinPackedMatrix::appendCols | ( | const int | numcols, | |
const CoinBigIndex * | columnStarts, | |||
const int * | row, | |||
const double * | element, | |||
int | numberRows = -1 | |||
) |
Append a set of columns to the end of the matrix.
Returns number of errors i.e. if any of the new columns contain an index that's larger than the number of rows-1 (if numberRows>0) or duplicates (if numberRows>0).
void CoinPackedMatrix::appendRow | ( | const CoinPackedVectorBase & | vec | ) |
Append a row to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if the new row contains an index that's larger than the number of columns (-1). Otherwise the method assumes that every index fits into the matrix.
void CoinPackedMatrix::appendRow | ( | const int | vecsize, | |
const int * | vecind, | |||
const double * | vecelem | |||
) |
Append a row to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if the new row contains an index that's larger than the number of columns (-1). Otherwise the method assumes that every index fits into the matrix.
void CoinPackedMatrix::appendRows | ( | const int | numrows, | |
const CoinPackedVectorBase *const * | rows | |||
) |
Append a set of rows to the end of the matrix.
When libosi is compiled with a COIN_DEBUG defined then this method throws an exception if any of the new rows contain an index that's larger than the number of columns (-1). Otherwise the method assumes that every index fits into the matrix.
int CoinPackedMatrix::appendRows | ( | const int | numrows, | |
const CoinBigIndex * | rowStarts, | |||
const int * | column, | |||
const double * | element, | |||
int | numberColumns = -1 | |||
) |
Append a set of rows to the end of the matrix.
Returns number of errors i.e. if any of the new rows contain an index that's larger than the number of columns-1 (if numberColumns>0) or duplicates (if numberColumns>0).
void CoinPackedMatrix::rightAppendPackedMatrix | ( | const CoinPackedMatrix & | matrix | ) |
Append the argument to the "right" of the current matrix.
Imagine this as adding new columns (don't worry about how the matrices are ordered, that is taken care of). An exception is thrown if the number of rows is different in the matrices.
void CoinPackedMatrix::bottomAppendPackedMatrix | ( | const CoinPackedMatrix & | matrix | ) |
Append the argument to the "bottom" of the current matrix.
Imagine this as adding new rows (don't worry about how the matrices are ordered, that is taken care of). An exception is thrown if the number of columns is different in the matrices.
void CoinPackedMatrix::deleteCols | ( | const int | numDel, | |
const int * | indDel | |||
) |
Delete the columns whose indices are listed in indDel
.
void CoinPackedMatrix::deleteRows | ( | const int | numDel, | |
const int * | indDel | |||
) |
Delete the rows whose indices are listed in indDel
.
void CoinPackedMatrix::replaceVector | ( | const int | index, | |
const int | numReplace, | |||
const double * | newElements | |||
) |
Replace the elements of a vector.
The indices remain the same. At most the number specified will be replaced. The index is between 0 and major dimension of matrix
void CoinPackedMatrix::modifyCoefficient | ( | int | row, | |
int | column, | |||
double | newElement, | |||
bool | keepZero = false | |||
) |
Modify one element of packed matrix.
An element may be added. This works for either ordering If the new element is zero it will be deleted unless keepZero true
double CoinPackedMatrix::getCoefficient | ( | int | row, | |
int | column | |||
) | const |
Return one element of packed matrix.
This works for either ordering If it is not present will return 0.0
int CoinPackedMatrix::compress | ( | double | threshold | ) |
Eliminate all elements in matrix whose absolute value is less than threshold.
The column starts are not affected. Returns number of elements eliminated. Elements eliminated are at end of each vector
int CoinPackedMatrix::eliminateDuplicates | ( | double | threshold | ) |
Eliminate all duplicate AND small elements in matrix The column starts are not affected.
Returns number of elements eliminated.
void CoinPackedMatrix::orderMatrix | ( | ) |
Sort all columns so indices are increasing.in each column.
int CoinPackedMatrix::cleanMatrix | ( | double | threshold = 1.0e-20 |
) |
Really clean up matrix.
a) eliminate all duplicate AND small elements in matrix b) remove all gaps and set extraGap_ and extraMajor_ to 0.0 c) reallocate arrays and make max lengths equal to lengths d) orders elements returns number of elements eliminated
void CoinPackedMatrix::removeGaps | ( | double | removeValue = -1.0 |
) |
Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValue.
void CoinPackedMatrix::submatrixOf | ( | const CoinPackedMatrix & | matrix, | |
const int | numMajor, | |||
const int * | indMajor | |||
) |
Extract a submatrix from matrix.
Those major-dimension vectors of the matrix comprise the submatrix whose indices are given in the arguments. Does not allow duplicates.
void CoinPackedMatrix::submatrixOfWithDuplicates | ( | const CoinPackedMatrix & | matrix, | |
const int | numMajor, | |||
const int * | indMajor | |||
) |
Extract a submatrix from matrix.
Those major-dimension vectors of the matrix comprise the submatrix whose indices are given in the arguments. Allows duplicates and keeps order.
void CoinPackedMatrix::copyOf | ( | const CoinPackedMatrix & | rhs | ) |
Copy method.
This method makes an exact replica of the argument, including the extra space parameters.
void CoinPackedMatrix::copyOf | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start, | |||
const int * | len, | |||
const double | extraMajor = 0.0 , |
|||
const double | extraGap = 0.0 | |||
) |
Copy the arguments to the matrix.
If len
is a NULL pointer then the matrix is assumed to have no gaps in it and len
will be created accordingly.
void CoinPackedMatrix::copyReuseArrays | ( | const CoinPackedMatrix & | rhs | ) |
Copy method.
This method makes an exact replica of the argument, including the extra space parameters. If there is room it will re-use arrays
void CoinPackedMatrix::reverseOrderedCopyOf | ( | const CoinPackedMatrix & | rhs | ) |
Reverse copy method.
This method makes an exact replica of the argument, but the major ordering reversed. The extra space parameters are copied and reversed, too.
void CoinPackedMatrix::assignMatrix | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
double *& | elem, | |||
int *& | ind, | |||
CoinBigIndex *& | start, | |||
int *& | len, | |||
const int | maxmajor = -1 , |
|||
const CoinBigIndex | maxsize = -1 | |||
) |
Assign the arguments to the matrix.
If len
is a NULL pointer then the matrix is assumed to have no gaps in it and len
will be created accordingly.
NOTE 1: After this method returns the pointers passed to the method will be NULL pointers!
NOTE 2: When the matrix is eventually destructed the arrays will be deleted by delete[]
. Hence one should use this method ONLY if all array swere allocated by new[]
!
CoinPackedMatrix& CoinPackedMatrix::operator= | ( | const CoinPackedMatrix & | rhs | ) |
Assignment operator.
This copies out the data, but uses the current matrix's extra space parameters.
Reimplemented in BCP_lp_relax.
void CoinPackedMatrix::reverseOrdering | ( | ) |
Reverse the ordering of the packed matrix.
void CoinPackedMatrix::transpose | ( | ) |
Transpose the matrix.
NOTE: All this routine does is to flip the ordering! Of course, then the matrix describes the transposed matrix. To get the matrix physically transposed (e.g., for a column ordered matrix to get the transpose in column ordered format) one has to invoke this method AND reverseOrdering()
.
void CoinPackedMatrix::swap | ( | CoinPackedMatrix & | matrix | ) |
Swap the content of the two packed matrix.
void CoinPackedMatrix::times | ( | const double * | x, | |
double * | y | |||
) | const |
Return A * x
in y
.
x
must be of size numColumns()
y
must be of size numRows()
void CoinPackedMatrix::times | ( | const CoinPackedVectorBase & | x, | |
double * | y | |||
) | const |
Return A * x
in y
.
Same as the previous method, just x
is given in the form of a packed vector.
void CoinPackedMatrix::transposeTimes | ( | const double * | x, | |
double * | y | |||
) | const |
Return x * A
in y
.
x
must be of size numRows()
y
must be of size numColumns()
void CoinPackedMatrix::transposeTimes | ( | const CoinPackedVectorBase & | x, | |
double * | y | |||
) | const |
Return x * A
in y
.
Same as the previous method, just x
is given in the form of a packed vector.
int* CoinPackedMatrix::countOrthoLength | ( | ) | const |
Count the number of entries in every minor-dimension vector and return an array containing these lengths.
The returned array is allocated with new int[]
, free it with delete[]
.
void CoinPackedMatrix::countOrthoLength | ( | int * | counts | ) | const |
Count the number of entries in every minor-dimension vector and fill in an array containing these lengths.
int CoinPackedMatrix::getMajorDim | ( | ) | const [inline] |
Major dimension.
For row ordered matrix this would be the number of rows.
Definition at line 410 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getMinorDim | ( | ) | const [inline] |
Minor dimension.
For row ordered matrix this would be the number of columns.
Definition at line 413 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::getMaxMajorDim | ( | ) | const [inline] |
Current maximum for major dimension.
For row ordered matrix this many rows can be added without reallocating the vector related to the major dimension (start_
and length_
).
Definition at line 417 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::dumpMatrix | ( | const char * | fname = NULL |
) | const |
Dump the matrix on stdout.
When in dire straits this method can help.
void CoinPackedMatrix::printMatrixElement | ( | const int | row_val, | |
const int | col_val | |||
) | const |
Print a single matrix element.
void CoinPackedMatrix::appendMajorVector | ( | const CoinPackedVectorBase & | vec | ) |
Append a major-dimension vector to the end of the matrix.
void CoinPackedMatrix::appendMajorVector | ( | const int | vecsize, | |
const int * | vecind, | |||
const double * | vecelem | |||
) |
Append a major-dimension vector to the end of the matrix.
void CoinPackedMatrix::appendMajorVectors | ( | const int | numvecs, | |
const CoinPackedVectorBase *const * | vecs | |||
) |
Append several major-dimensonvectors to the end of the matrix.
void CoinPackedMatrix::appendMinorVector | ( | const CoinPackedVectorBase & | vec | ) |
Append a minor-dimension vector to the end of the matrix.
void CoinPackedMatrix::appendMinorVector | ( | const int | vecsize, | |
const int * | vecind, | |||
const double * | vecelem | |||
) |
Append a minor-dimension vector to the end of the matrix.
void CoinPackedMatrix::appendMinorVectors | ( | const int | numvecs, | |
const CoinPackedVectorBase *const * | vecs | |||
) |
Append several minor-dimensonvectors to the end of the matrix.
void CoinPackedMatrix::majorAppendSameOrdered | ( | const CoinPackedMatrix & | matrix | ) |
Append the columns of the argument to the right end of this matrix.
minorDim_ == matrix.minorDim_
void CoinPackedMatrix::minorAppendSameOrdered | ( | const CoinPackedMatrix & | matrix | ) |
Append the columns of the argument to the bottom end of this matrix.
majorDim_ == matrix.majorDim_
void CoinPackedMatrix::majorAppendOrthoOrdered | ( | const CoinPackedMatrix & | matrix | ) |
Append the rows of the argument to the right end of this matrix.
minorDim_ == matrix.majorDim_
void CoinPackedMatrix::minorAppendOrthoOrdered | ( | const CoinPackedMatrix & | matrix | ) |
Append the rows of the argument to the bottom end of this matrix.
majorDim_ == matrix.minorDim_
void CoinPackedMatrix::deleteMajorVectors | ( | const int | numDel, | |
const int * | indDel | |||
) |
Delete the major-dimension vectors whose indices are listed in indDel
.
void CoinPackedMatrix::deleteMinorVectors | ( | const int | numDel, | |
const int * | indDel | |||
) |
Delete the minor-dimension vectors whose indices are listed in indDel
.
void CoinPackedMatrix::timesMajor | ( | const double * | x, | |
double * | y | |||
) | const |
Return A * x
(multiplied from the "right" direction) in y
.
x
must be of size majorDim()
y
must be of size minorDim()
void CoinPackedMatrix::timesMajor | ( | const CoinPackedVectorBase & | x, | |
double * | y | |||
) | const |
Return A * x
(multiplied from the "right" direction) in y
.
Same as the previous method, just x
is given in the form of a packed vector.
void CoinPackedMatrix::timesMinor | ( | const double * | x, | |
double * | y | |||
) | const |
Return A * x
(multiplied from the "right" direction) in y
.
x
must be of size minorDim()
y
must be of size majorDim()
void CoinPackedMatrix::timesMinor | ( | const CoinPackedVectorBase & | x, | |
double * | y | |||
) | const |
Return A * x
(multiplied from the "right" direction) in y
.
Same as the previous method, just x
is given in the form of a packed vector.
bool CoinPackedMatrix::isEquivalent | ( | const CoinPackedMatrix & | rhs, | |
const FloatEqual & | eq | |||
) | const [inline] |
Equivalence.
Two matrices are equivalent if they are both by rows or both by columns, they have the same dimensions, and each vector is equivalent. In this method the FloatEqual function operator can be specified.
Definition at line 541 of file CoinPackedMatrix.hpp.
bool CoinPackedMatrix::isEquivalent2 | ( | const CoinPackedMatrix & | rhs | ) | const |
Equivalence.
Two matrices are equivalent if they are both by rows or both by columns, they have the same dimensions, and each vector is equivalent. In this method the FloatEqual function operator can be specified.
bool CoinPackedMatrix::isEquivalent | ( | const CoinPackedMatrix & | rhs | ) | const [inline] |
The default equivalence test is that the entries are relatively equal.
Definition at line 569 of file CoinPackedMatrix.hpp.
double* CoinPackedMatrix::getMutableElements | ( | ) | const [inline] |
A vector containing the elements in the packed matrix.
Note that there might be gaps in this list, entries that do not belong to any major-dimension vector. To get the actual elements one should look at this vector together with vectorStarts and vectorLengths.
Definition at line 583 of file CoinPackedMatrix.hpp.
int* CoinPackedMatrix::getMutableIndices | ( | ) | const [inline] |
A vector containing the minor indices of the elements in the packed matrix.
Note that there might be gaps in this list, entries that do not belong to any major-dimension vector. To get the actual elements one should look at this vector together with vectorStarts and vectorLengths.
Definition at line 589 of file CoinPackedMatrix.hpp.
CoinBigIndex* CoinPackedMatrix::getMutableVectorStarts | ( | ) | const [inline] |
The positions where the major-dimension vectors start in elements and indices.
Definition at line 593 of file CoinPackedMatrix.hpp.
int* CoinPackedMatrix::getMutableVectorLengths | ( | ) | const [inline] |
The lengths of the major-dimension vectors.
Definition at line 595 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::setNumElements | ( | CoinBigIndex | value | ) | [inline] |
Change size after modifying - be careful.
Definition at line 597 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::nullElementArray | ( | ) | [inline] |
NULLify element array - used when space is very tight.
Definition at line 600 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::nullStartArray | ( | ) | [inline] |
NULLify start array - used when space is very tight.
Definition at line 602 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::nullLengthArray | ( | ) | [inline] |
NULLify length array - used when space is very tight.
Definition at line 604 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::nullIndexArray | ( | ) | [inline] |
NULLify index array - used when space is very tight.
Definition at line 606 of file CoinPackedMatrix.hpp.
void CoinPackedMatrix::gutsOfDestructor | ( | ) | [protected] |
void CoinPackedMatrix::gutsOfCopyOf | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start, | |||
const int * | len, | |||
const double | extraMajor = 0.0 , |
|||
const double | extraGap = 0.0 | |||
) | [protected] |
void CoinPackedMatrix::gutsOfCopyOfNoGaps | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start | |||
) | [protected] |
When no gaps we can do faster.
void CoinPackedMatrix::gutsOfOpEqual | ( | const bool | colordered, | |
const int | minor, | |||
const int | major, | |||
const CoinBigIndex | numels, | |||
const double * | elem, | |||
const int * | ind, | |||
const CoinBigIndex * | start, | |||
const int * | len | |||
) | [protected] |
void CoinPackedMatrix::resizeForAddingMajorVectors | ( | const int | numVec, | |
const int * | lengthVec | |||
) | [protected] |
void CoinPackedMatrix::resizeForAddingMinorVectors | ( | const int * | addedEntries | ) | [protected] |
int CoinPackedMatrix::appendMajor | ( | const int | number, | |
const CoinBigIndex * | starts, | |||
const int * | index, | |||
const double * | element, | |||
int | numberOther = -1 | |||
) | [protected] |
Append a set of rows/columns to the end of the matrix.
Returns number of errors i.e. if any of the new rows/columns contain an index that's larger than the number of columns-1/rows-1 (if numberOther>0) or duplicates This version is easy one i.e. adding columns to column ordered
int CoinPackedMatrix::appendMinor | ( | const int | number, | |
const CoinBigIndex * | starts, | |||
const int * | index, | |||
const double * | element, | |||
int | numberOther = -1 | |||
) | [protected] |
Append a set of rows/columns to the end of the matrix.
Returns number of errors i.e. if any of the new rows/columns contain an index that's larger than the number of columns-1/rows-1 (if numberOther>0) or duplicates This version is harder one i.e. adding columns to row ordered
CoinBigIndex CoinPackedMatrix::getLastStart | ( | ) | const [inline, private] |
Definition at line 699 of file CoinPackedMatrix.hpp.
void CoinPackedMatrixUnitTest | ( | ) | [friend] |
A function that tests the methods in the CoinPackedMatrix class.
The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging.
bool CoinPackedMatrix::colOrdered_ [protected] |
A flag indicating whether the matrix is column or row major ordered.
Definition at line 709 of file CoinPackedMatrix.hpp.
double CoinPackedMatrix::extraGap_ [protected] |
This much times more space should be allocated for each major-dimension vector (with respect to the number of entries in the vector) when the matrix is resized.
The purpose of these gaps is to allow fast insertion of new minor-dimension vectors.
Definition at line 714 of file CoinPackedMatrix.hpp.
double CoinPackedMatrix::extraMajor_ [protected] |
his much times more space should be allocated for major-dimension vectors when the matrix is resized.
The purpose of these gaps is to allow fast addition of new major-dimension vectors.
Definition at line 718 of file CoinPackedMatrix.hpp.
double* CoinPackedMatrix::element_ [protected] |
List of nonzero element values.
The entries in the gaps between major-dimension vectors are undefined.
Definition at line 722 of file CoinPackedMatrix.hpp.
int* CoinPackedMatrix::index_ [protected] |
List of nonzero element minor-dimension indices.
The entries in the gaps between major-dimension vectors are undefined.
Definition at line 725 of file CoinPackedMatrix.hpp.
CoinBigIndex* CoinPackedMatrix::start_ [protected] |
Starting positions of major-dimension vectors.
Definition at line 727 of file CoinPackedMatrix.hpp.
int* CoinPackedMatrix::length_ [protected] |
Lengths of major-dimension vectors.
Definition at line 729 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::majorDim_ [protected] |
number of vectors in matrix
Definition at line 732 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::minorDim_ [protected] |
size of other dimension
Definition at line 734 of file CoinPackedMatrix.hpp.
CoinBigIndex CoinPackedMatrix::size_ [protected] |
the number of nonzero entries
Definition at line 736 of file CoinPackedMatrix.hpp.
int CoinPackedMatrix::maxMajorDim_ [protected] |
max space allocated for major-dimension
Definition at line 739 of file CoinPackedMatrix.hpp.
CoinBigIndex CoinPackedMatrix::maxSize_ [protected] |
max space allocated for entries
Definition at line 741 of file CoinPackedMatrix.hpp.