CoinPackedMatrix

Sparse Matrix Base Class.

Sparse Matrix Base Class.

Description

This class is intended to represent sparse matrices using row-major or column-major ordering. The representation is very efficient for adding, deleting, or retrieving major-dimension vectors. Adding a minor-dimension vector is less efficient, but can be helped by providing "extra" space as described in the next paragraph. Deleting a minor-dimension vector requires inspecting all coefficients in the matrix. Retrieving a minor-dimension vector would incur the same cost and is not supported (except in the sense that you can write a loop to retrieve all coefficients one at a time). Consider physically transposing the matrix, or keeping a second copy with the other major-vector ordering. The sparse represention can be completely compact or it can have "extra" space available at the end of each major vector. Incorporating extra space into the sparse matrix representation can improve performance in cases where new data needs to be inserted into the packed matrix against the major-vector orientation (e.g, inserting a row into a matrix stored in column-major order). 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. Compiling this class with CLP_NO_VECTOR defined will excise all methods which use CoinPackedVectorBase, CoinPackedVector, or CoinShallowPackedVector as parameters or return types. Compiling this class with COIN_FAST_CODE defined removes index range checks.

Public Methods

getExtraGap

Return the current setting of the extra gap.

double getExtraGap()

getExtraMajor

Return the current setting of the extra major.

double getExtraMajor()

reserve

Reserve sufficient space for appending major-ordered vectors.

void reserve(const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create = false)

Parameters:

clear

Clear the data, but do not free any arrays.

void clear()

isColOrdered

Whether the packed matrix is column major ordered or not.

bool isColOrdered()

hasGaps

Whether the packed matrix has gaps or not.

bool hasGaps()

getNumElements

Number of entries in the packed matrix.

CoinBigIndex getNumElements()

getNumCols

Number of columns.

int getNumCols()

getNumRows

Number of rows.

int getNumRows()

getElements

A vector containing the elements in the packed matrix.

const double * getElements()

getIndices

A vector containing the minor indices of the elements in the packed matrix.

const int * getIndices()

getSizeVectorStarts

The size of the vectorStarts array.

int getSizeVectorStarts()

getSizeVectorLengths

The size of the vectorLengths array.

int getSizeVectorLengths()

getVectorStarts

The positions where the major-dimension vectors start in elements and indices.

const CoinBigIndex * getVectorStarts()

getVectorLengths

The lengths of the major-dimension vectors.

const int * getVectorLengths()

getVectorFirst

The position of the first element in the i'th major-dimension vector.

CoinBigIndex getVectorFirst(const int i)

Parameters:

getVectorLast

The position of the last element (well, one entry past the last) in the i'th major-dimension vector.

CoinBigIndex getVectorLast(const int i)

Parameters:

getVectorSize

The length of i'th vector.

int getVectorSize(const int i)

Parameters:

getVector

Return the i'th vector in matrix.

const CoinShallowPackedVector getVector(int i)

Parameters:

getMajorIndices

Returns an array containing major indices.

int * getMajorIndices()

setDimensions

Set the dimensions of the matrix.

void setDimensions(int numrows, int numcols)

Parameters:

setExtraGap

Set the extra gap to be allocated to the specified value.

void setExtraGap(const double newGap)

Parameters:

setExtraMajor

Set the extra major to be allocated to the specified value.

void setExtraMajor(const double newMajor)

Parameters:

appendCol

void appendCol(const CoinPackedVectorBase & vec)

Parameters:

appendCol

void appendCol(const int vecsize, const int * vecind, const double * vecelem)

Parameters:

appendCols

void appendCols(const int numcols, const CoinPackedVectorBase *const * cols)

Parameters:

appendCols

int appendCols(const int numcols, const CoinBigIndex * columnStarts, const int * row, const double * element, int numberRows = -1)

Parameters:

appendRow

void appendRow(const CoinPackedVectorBase & vec)

Parameters:

appendRow

void appendRow(const int vecsize, const int * vecind, const double * vecelem)

Parameters:

appendRows

void appendRows(const int numrows, const CoinPackedVectorBase *const * rows)

Parameters:

appendRows

int appendRows(const int numrows, const CoinBigIndex * rowStarts, const int * column, const double * element, int numberColumns = -1)

Parameters:

rightAppendPackedMatrix

Append the argument to the "right" of the current matrix.

void rightAppendPackedMatrix(const CoinPackedMatrix & matrix)

Parameters:

bottomAppendPackedMatrix

Append the argument to the "bottom" of the current matrix.

void bottomAppendPackedMatrix(const CoinPackedMatrix & matrix)

Parameters:

deleteCols

Delete the columns whose indices are listed in indDel.

void deleteCols(const int numDel, const int * indDel)

Parameters:

deleteRows

Delete the rows whose indices are listed in indDel.

void deleteRows(const int numDel, const int * indDel)

Parameters:

replaceVector

Replace the elements of a vector.

void replaceVector(const int index, const int numReplace, const double * newElements)

Parameters:

modifyCoefficient

Modify one element of packed matrix.

void modifyCoefficient(int row, int column, double newElement, bool keepZero = false)

Parameters:

getCoefficient

Return one element of packed matrix.

double getCoefficient(int row, int column)

Parameters:

compress

Eliminate all elements in matrix whose absolute value is less than threshold.

CoinBigIndex compress(double threshold)

Parameters:

eliminateDuplicates

Eliminate all duplicate AND small elements in matrix The column starts are not affected.

CoinBigIndex eliminateDuplicates(double threshold)

Parameters:

orderMatrix

Sort all columns so indices are increasing.in each column.

void orderMatrix()

cleanMatrix

Really clean up matrix.

CoinBigIndex cleanMatrix(double threshold = 1.0e-20)

Parameters:

removeGaps

Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValue.

void removeGaps(double removeValue = -1.0)

Parameters:

submatrixOf

Extract a submatrix from matrix.

void submatrixOf(const CoinPackedMatrix & matrix, const int numMajor, const int * indMajor)

Parameters:

submatrixOfWithDuplicates

Extract a submatrix from matrix.

void submatrixOfWithDuplicates(const CoinPackedMatrix & matrix, const int numMajor, const int * indMajor)

Parameters:

copyOf

Copy method.

void copyOf(const CoinPackedMatrix & rhs)

Parameters:

copyOf

Copy the arguments to the matrix.

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)

Parameters:

copyReuseArrays

Copy method.

void copyReuseArrays(const CoinPackedMatrix & rhs)

Parameters:

reverseOrderedCopyOf

Make a reverse-ordered copy.

void reverseOrderedCopyOf(const CoinPackedMatrix & rhs)

Parameters:

assignMatrix

Assign the arguments to the matrix.

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)

Parameters:

operator=

Assignment operator.

CoinPackedMatrix & operator=(const CoinPackedMatrix & rhs)

Parameters:

reverseOrdering

Reverse the ordering of the packed matrix.

void reverseOrdering()

transpose

Transpose the matrix.

void transpose()

swap

Swap the content of two packed matrices.

void swap(CoinPackedMatrix & matrix)

Parameters:

times

Return A * x in y.

void times(const double * x, double * y)

Parameters:

times

Return A * x in y.

void times(const CoinPackedVectorBase & x, double * y)

Parameters:

transposeTimes

Return x * A in y.

void transposeTimes(const double * x, double * y)

Parameters:

transposeTimes

Return x * A in y.

void transposeTimes(const CoinPackedVectorBase & x, double * y)

Parameters:

countOrthoLength

Count the number of entries in every minor-dimension vector and return an array containing these lengths.

int * countOrthoLength()

countOrthoLength

Count the number of entries in every minor-dimension vector and fill in an array containing these lengths.

void countOrthoLength(int * counts)

Parameters:

getMajorDim

Major dimension.

int getMajorDim()

setMajorDim

Set major dimension.

void setMajorDim(int value)

Parameters:

getMinorDim

Minor dimension.

int getMinorDim()

setMinorDim

Set minor dimension.

void setMinorDim(int value)

Parameters:

getMaxMajorDim

Current maximum for major dimension.

int getMaxMajorDim()

dumpMatrix

Dump the matrix on stdout.

void dumpMatrix(const char * fname = NULL)

Parameters:

printMatrixElement

Print a single matrix element.

void printMatrixElement(const int row_val, const int col_val)

Parameters:

appendMajorVector

Append a major-dimension vector to the end of the matrix.

void appendMajorVector(const CoinPackedVectorBase & vec)

Parameters:

appendMajorVector

Append a major-dimension vector to the end of the matrix.

void appendMajorVector(const int vecsize, const int * vecind, const double * vecelem)

Parameters:

appendMajorVectors

Append several major-dimensonvectors to the end of the matrix.

void appendMajorVectors(const int numvecs, const CoinPackedVectorBase *const * vecs)

Parameters:

appendMinorVector

Append a minor-dimension vector to the end of the matrix.

void appendMinorVector(const CoinPackedVectorBase & vec)

Parameters:

appendMinorVector

Append a minor-dimension vector to the end of the matrix.

void appendMinorVector(const int vecsize, const int * vecind, const double * vecelem)

Parameters:

appendMinorVectors

Append several minor-dimension vectors to the end of the matrix.

void appendMinorVectors(const int numvecs, const CoinPackedVectorBase *const * vecs)

Parameters:

appendMinorFast

Append a set of rows (columns) to the end of a column (row) ordered matrix.

void appendMinorFast(const int number, const CoinBigIndex * starts, const int * index, const double * element)

Parameters:

majorAppendSameOrdered

Append the columns of the argument to the right end of this matrix.

void majorAppendSameOrdered(const CoinPackedMatrix & matrix)

Parameters:

minorAppendSameOrdered

Append the columns of the argument to the bottom end of this matrix.

void minorAppendSameOrdered(const CoinPackedMatrix & matrix)

Parameters:

majorAppendOrthoOrdered

Append the rows of the argument to the right end of this matrix.

void majorAppendOrthoOrdered(const CoinPackedMatrix & matrix)

Parameters:

minorAppendOrthoOrdered

Append the rows of the argument to the bottom end of this matrix.

void minorAppendOrthoOrdered(const CoinPackedMatrix & matrix)

Parameters:

deleteMajorVectors

Delete the major-dimension vectors whose indices are listed in indDel.

void deleteMajorVectors(const int numDel, const int * indDel)

Parameters:

deleteMinorVectors

Delete the minor-dimension vectors whose indices are listed in indDel.

void deleteMinorVectors(const int numDel, const int * indDel)

Parameters:

timesMajor

Return A * x (multiplied from the "right" direction) in y.

void timesMajor(const double * x, double * y)

Parameters:

timesMajor

Return A * x (multiplied from the "right" direction) in y.

void timesMajor(const CoinPackedVectorBase & x, double * y)

Parameters:

timesMinor

Return A * x (multiplied from the "right" direction) in y.

void timesMinor(const double * x, double * y)

Parameters:

timesMinor

Return A * x (multiplied from the "right" direction) in y.

void timesMinor(const CoinPackedVectorBase & x, double * y)

Parameters:

isEquivalent

Test for equivalence.

bool isEquivalent(const CoinPackedMatrix & rhs, const FloatEqual & eq)

Parameters:

isEquivalent2

Test for equivalence and report differences.

bool isEquivalent2(const CoinPackedMatrix & rhs)

Parameters:

isEquivalent

Test for equivalence.

bool isEquivalent(const CoinPackedMatrix & rhs)

Parameters:

getMutableElements

A vector containing the elements in the packed matrix.

double * getMutableElements()

getMutableIndices

A vector containing the minor indices of the elements in the packed matrix.

int * getMutableIndices()

getMutableVectorStarts

The positions where the major-dimension vectors start in element_ and index_.

CoinBigIndex * getMutableVectorStarts()

getMutableVectorLengths

The lengths of the major-dimension vectors.

int * getMutableVectorLengths()

setNumElements

Change the size of the bulk store after modifying - be careful.

void setNumElements(CoinBigIndex value)

Parameters:

nullElementArray

void nullElementArray()

nullStartArray

void nullStartArray()

nullLengthArray

void nullLengthArray()

nullIndexArray

void nullIndexArray()

CoinPackedMatrix

Default Constructor creates an empty column ordered packed matrix.

 CoinPackedMatrix()

CoinPackedMatrix

A constructor where the ordering and the gaps are specified.

 CoinPackedMatrix(const bool colordered, const double extraMajor, const double extraGap)

Parameters:

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)

Parameters:

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)

Parameters:

CoinPackedMatrix

Create packed matrix from triples.

 CoinPackedMatrix(const bool colordered, const int * rowIndices, const int * colIndices, const double * elements, CoinBigIndex numels)

Parameters:

CoinPackedMatrix

Copy constructor.

 CoinPackedMatrix(const CoinPackedMatrix & m)

Parameters:

CoinPackedMatrix

Copy constructor with fine tuning.

 CoinPackedMatrix(const CoinPackedMatrix & m, int extraForMajor, int extraElements, bool reverseOrdering = false)

Parameters:

CoinPackedMatrix

Subset constructor (without gaps).

 CoinPackedMatrix(const CoinPackedMatrix & wholeModel, int numberRows, const int * whichRows, int numberColumns, const int * whichColumns)

Parameters:

~CoinPackedMatrix

Destructor.

 ~CoinPackedMatrix()

verifyMtx

Scan the matrix for anomalies.

int verifyMtx(int verbosity = 1, bool zeroesAreError = false)

Parameters:

Source

Header: layer-0/CoinUtils/src/CoinPackedMatrix.hpp