Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Protected Member Functions | Private Member Functions | Friends | List of all members
CoinPackedMatrix Class Reference

Sparse Matrix Base Class. More...

#include <CoinPackedMatrix.hpp>

Public Member Functions

Query members
double getExtraGap () const
 Return the current setting of the extra gap. More...
 
double getExtraMajor () const
 Return the current setting of the extra major. More...
 
void reserve (const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false)
 Reserve sufficient space for appending major-ordered vectors. More...
 
void clear ()
 Clear the data, but do not free any arrays. More...
 
bool isColOrdered () const
 Whether the packed matrix is column major ordered or not. More...
 
bool hasGaps () const
 Whether the packed matrix has gaps or not. More...
 
CoinBigIndex getNumElements () const
 Number of entries in the packed matrix. More...
 
int getNumCols () const
 Number of columns. More...
 
int getNumRows () const
 Number of rows. More...
 
const double * getElements () const
 A vector containing the elements in the packed matrix. More...
 
const int * getIndices () const
 A vector containing the minor indices of the elements in the packed matrix. More...
 
int getSizeVectorStarts () const
 The size of the vectorStarts array. More...
 
int getSizeVectorLengths () const
 The size of the vectorLengths array. More...
 
const CoinBigIndexgetVectorStarts () const
 The positions where the major-dimension vectors start in elements and indices. More...
 
const int * getVectorLengths () const
 The lengths of the major-dimension vectors. More...
 
CoinBigIndex getVectorFirst (const int i) const
 The position of the first element in the i'th major-dimension vector. More...
 
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. More...
 
int getVectorSize (const int i) const
 The length of i'th vector. More...
 
const CoinShallowPackedVector getVector (int i) const
 Return the i'th vector in matrix. More...
 
int * getMajorIndices () const
 Returns an array containing major indices. More...
 
Modifying members
void setDimensions (int numrows, int numcols)
 Set the dimensions of the matrix. More...
 
void setExtraGap (const double newGap)
 Set the extra gap to be allocated to the specified value. More...
 
void setExtraMajor (const double newMajor)
 Set the extra major to be allocated to the specified value. More...
 
void appendCol (const CoinPackedVectorBase &vec)
 Append a column to the end of the matrix. More...
 
void appendCol (const int vecsize, const int *vecind, const double *vecelem)
 Append a column to the end of the matrix. More...
 
void appendCols (const int numcols, const CoinPackedVectorBase *const *cols)
 Append a set of columns to the end of the matrix. More...
 
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. More...
 
void appendRow (const CoinPackedVectorBase &vec)
 Append a row to the end of the matrix. More...
 
void appendRow (const int vecsize, const int *vecind, const double *vecelem)
 Append a row to the end of the matrix. More...
 
void appendRows (const int numrows, const CoinPackedVectorBase *const *rows)
 Append a set of rows to the end of the matrix. More...
 
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. More...
 
void rightAppendPackedMatrix (const CoinPackedMatrix &matrix)
 Append the argument to the "right" of the current matrix. More...
 
void bottomAppendPackedMatrix (const CoinPackedMatrix &matrix)
 Append the argument to the "bottom" of the current matrix. More...
 
void deleteCols (const int numDel, const int *indDel)
 Delete the columns whose indices are listed in indDel. More...
 
void deleteRows (const int numDel, const int *indDel)
 Delete the rows whose indices are listed in indDel. More...
 
void replaceVector (const int index, const int numReplace, const double *newElements)
 Replace the elements of a vector. More...
 
void modifyCoefficient (int row, int column, double newElement, bool keepZero=false)
 Modify one element of packed matrix. More...
 
double getCoefficient (int row, int column) const
 Return one element of packed matrix. More...
 
CoinBigIndex compress (double threshold)
 Eliminate all elements in matrix whose absolute value is less than threshold. More...
 
CoinBigIndex eliminateDuplicates (double threshold)
 Eliminate all duplicate AND small elements in matrix The column starts are not affected. More...
 
void orderMatrix ()
 Sort all columns so indices are increasing.in each column. More...
 
CoinBigIndex cleanMatrix (double threshold=1.0e-20)
 Really clean up matrix. More...
 
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. More...
 
void submatrixOf (const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
 Extract a submatrix from matrix. More...
 
void submatrixOfWithDuplicates (const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
 Extract a submatrix from matrix. More...
 
void copyOf (const CoinPackedMatrix &rhs)
 Copy method. More...
 
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. More...
 
void copyReuseArrays (const CoinPackedMatrix &rhs)
 Copy method. More...
 
void reverseOrderedCopyOf (const CoinPackedMatrix &rhs)
 Make a reverse-ordered copy. More...
 
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. More...
 
CoinPackedMatrixoperator= (const CoinPackedMatrix &rhs)
 Assignment operator. More...
 
void reverseOrdering ()
 Reverse the ordering of the packed matrix. More...
 
void transpose ()
 Transpose the matrix. More...
 
void swap (CoinPackedMatrix &matrix)
 Swap the content of two packed matrices. More...
 
Matrix times vector methods
void times (const double *x, double *y) const
 Return A * x in y. More...
 
void times (const CoinPackedVectorBase &x, double *y) const
 Return A * x in y. More...
 
void transposeTimes (const double *x, double *y) const
 Return x * A in y. More...
 
void transposeTimes (const CoinPackedVectorBase &x, double *y) const
 Return x * A in y. More...
 
Queries
int * countOrthoLength () const
 Count the number of entries in every minor-dimension vector and return an array containing these lengths. More...
 
void countOrthoLength (int *counts) const
 Count the number of entries in every minor-dimension vector and fill in an array containing these lengths. More...
 
int getMajorDim () const
 Major dimension. More...
 
void setMajorDim (int value)
 Set major dimension. More...
 
int getMinorDim () const
 Minor dimension. More...
 
void setMinorDim (int value)
 Set minor dimension. More...
 
int getMaxMajorDim () const
 Current maximum for major dimension. More...
 
void dumpMatrix (const char *fname=NULL) const
 Dump the matrix on stdout. More...
 
void printMatrixElement (const int row_val, const int col_val) const
 Print a single matrix element. More...
 
Append vectors

When compiled with COIN_DEBUG defined these methods throw an exception if the major (minor) vector contains an index that's invalid for the minor (major) dimension. Otherwise the methods assume that every index fits into the matrix.

void appendMajorVector (const CoinPackedVectorBase &vec)
 Append a major-dimension vector to the end of the matrix. More...
 
void appendMajorVector (const int vecsize, const int *vecind, const double *vecelem)
 Append a major-dimension vector to the end of the matrix. More...
 
void appendMajorVectors (const int numvecs, const CoinPackedVectorBase *const *vecs)
 Append several major-dimensonvectors to the end of the matrix. More...
 
void appendMinorVector (const CoinPackedVectorBase &vec)
 Append a minor-dimension vector to the end of the matrix. More...
 
void appendMinorVector (const int vecsize, const int *vecind, const double *vecelem)
 Append a minor-dimension vector to the end of the matrix. More...
 
void appendMinorVectors (const int numvecs, const CoinPackedVectorBase *const *vecs)
 Append several minor-dimension vectors to the end of the matrix. More...
 
void appendMinorFast (const int number, const CoinBigIndex *starts, const int *index, const double *element)
 Append a set of rows (columns) to the end of a column (row) ordered matrix. More...
 
Append matrices

We'll document these methods assuming that the current matrix is column major ordered (Hence in the ...SameOrdered() methods the argument is column ordered, in the OrthoOrdered() methods the argument is row ordered.)

void majorAppendSameOrdered (const CoinPackedMatrix &matrix)
 Append the columns of the argument to the right end of this matrix. More...
 
void minorAppendSameOrdered (const CoinPackedMatrix &matrix)
 Append the columns of the argument to the bottom end of this matrix. More...
 
void majorAppendOrthoOrdered (const CoinPackedMatrix &matrix)
 Append the rows of the argument to the right end of this matrix. More...
 
void minorAppendOrthoOrdered (const CoinPackedMatrix &matrix)
 Append the rows of the argument to the bottom end of this matrix. More...
 
Delete vectors
void deleteMajorVectors (const int numDel, const int *indDel)
 Delete the major-dimension vectors whose indices are listed in indDel. More...
 
void deleteMinorVectors (const int numDel, const int *indDel)
 Delete the minor-dimension vectors whose indices are listed in indDel. More...
 
Various dot products.
void timesMajor (const double *x, double *y) const
 Return A * x (multiplied from the "right" direction) in y. More...
 
void timesMajor (const CoinPackedVectorBase &x, double *y) const
 Return A * x (multiplied from the "right" direction) in y. More...
 
void timesMinor (const double *x, double *y) const
 Return A * x (multiplied from the "right" direction) in y. More...
 
void timesMinor (const CoinPackedVectorBase &x, double *y) const
 Return A * x (multiplied from the "right" direction) in y. More...
 
Logical Operations.
template<class FloatEqual >
bool isEquivalent (const CoinPackedMatrix &rhs, const FloatEqual &eq) const
 Test for equivalence. More...
 
bool isEquivalent2 (const CoinPackedMatrix &rhs) const
 Test for equivalence and report differences. More...
 
bool isEquivalent (const CoinPackedMatrix &rhs) const
 Test for equivalence. More...
 
Non-const methods

These are to be used with great care when doing column generation, etc.

double * getMutableElements () const
 A vector containing the elements in the packed matrix. More...
 
int * getMutableIndices () const
 A vector containing the minor indices of the elements in the packed matrix. More...
 
CoinBigIndexgetMutableVectorStarts () const
 The positions where the major-dimension vectors start in element_ and index_. More...
 
int * getMutableVectorLengths () const
 The lengths of the major-dimension vectors. More...
 
void setNumElements (CoinBigIndex value)
 Change the size of the bulk store after modifying - be careful. More...
 
void nullElementArray ()
 NULLify element array. More...
 
void nullStartArray ()
 NULLify start array. More...
 
void nullLengthArray ()
 NULLify length array. More...
 
void nullIndexArray ()
 NULLify index array. More...
 
Constructors and destructors
 CoinPackedMatrix ()
 Default Constructor creates an empty column ordered packed matrix. More...
 
 CoinPackedMatrix (const bool colordered, const double extraMajor, const double extraGap)
 A constructor where the ordering and the gaps are specified. More...
 
 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)
 
 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)
 
 CoinPackedMatrix (const bool colordered, const int *rowIndices, const int *colIndices, const double *elements, CoinBigIndex numels)
 Create packed matrix from triples. More...
 
 CoinPackedMatrix (const CoinPackedMatrix &m)
 Copy constructor. More...
 
 CoinPackedMatrix (const CoinPackedMatrix &m, int extraForMajor, int extraElements, bool reverseOrdering=false)
 Copy constructor with fine tuning. More...
 
 CoinPackedMatrix (const CoinPackedMatrix &wholeModel, int numberRows, const int *whichRows, int numberColumns, const int *whichColumns)
 Subset constructor (without gaps). More...
 
virtual ~CoinPackedMatrix ()
 Destructor. More...
 
Debug Utilities
int verifyMtx (int verbosity=1, bool zeroesAreError=false) const
 Scan the matrix for anomalies. More...
 

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. More...
 
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 a row (colum) ordered matrix. More...
 
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 a column (row) ordered matrix. More...
 

Protected Attributes

Data members

The data members are protected to allow access for derived classes.

bool colOrdered_
 A flag indicating whether the matrix is column or row major ordered. More...
 
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. More...
 
double extraMajor_
 his much times more space should be allocated for major-dimension vectors when the matrix is resized. More...
 
double * element_
 List of nonzero element values. More...
 
int * index_
 List of nonzero element minor-dimension indices. More...
 
CoinBigIndexstart_
 Starting positions of major-dimension vectors. More...
 
int * length_
 Lengths of major-dimension vectors. More...
 
int majorDim_
 number of vectors in matrix More...
 
int minorDim_
 size of other dimension More...
 
CoinBigIndex size_
 the number of nonzero entries More...
 
int maxMajorDim_
 max space allocated for major-dimension More...
 
CoinBigIndex maxSize_
 max space allocated for entries More...
 

Private Member Functions

CoinBigIndex getLastStart () const
 

Friends

void CoinPackedMatrixUnitTest ()
 Test the methods in the CoinPackedMatrix class. More...
 

Detailed Description

Sparse Matrix Base Class.

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.

Definition at line 79 of file CoinPackedMatrix.hpp.

Constructor & Destructor Documentation

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 
)
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 
)
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 with fine tuning.

This constructor allows for the specification of an exact amount of extra space and/or reverse ordering.

extraForMajor is the exact number of spare major vector slots after any possible reverse ordering. If extraForMajor < 0, all gaps and small elements will be removed from the copy, otherwise gaps and small elements are preserved.

extraElements is the exact number of spare element entries.

The usual multipliers, extraMajor_ and extraGap_, are 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.

Member Function Documentation

double CoinPackedMatrix::getExtraGap ( ) const
inline

Return the current setting of the extra gap.

Definition at line 87 of file CoinPackedMatrix.hpp.

double CoinPackedMatrix::getExtraMajor ( ) const
inline

Return the current setting of the extra major.

Definition at line 89 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.

bool CoinPackedMatrix::isColOrdered ( ) const
inline

Whether the packed matrix is column major ordered or not.

Definition at line 99 of file CoinPackedMatrix.hpp.

bool CoinPackedMatrix::hasGaps ( ) const
inline

Whether the packed matrix has gaps or not.

Definition at line 102 of file CoinPackedMatrix.hpp.

CoinBigIndex CoinPackedMatrix::getNumElements ( ) const
inline

Number of entries in the packed matrix.

Definition at line 105 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::getNumCols ( ) const
inline

Number of columns.

Definition at line 108 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::getNumRows ( ) const
inline

Number of rows.

Definition at line 114 of file CoinPackedMatrix.hpp.

const double* CoinPackedMatrix::getElements ( ) const
inline

A vector containing the elements in the packed matrix.

Returns #elements_. Note that there might be gaps in this vector, entries that do not belong to any major-dimension vector. To get the actual elements one should look at this vector together with vectorStarts (start_) and vectorLengths (length_).

Definition at line 126 of file CoinPackedMatrix.hpp.

const int* CoinPackedMatrix::getIndices ( ) const
inline

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

Returns index_. 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 (start_) and vectorLengths (length_).

Definition at line 136 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::getSizeVectorStarts ( ) const
inline

The size of the vectorStarts array.

See start_.

Definition at line 142 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::getSizeVectorLengths ( ) const
inline

The size of the vectorLengths array.

See length_.

Definition at line 151 of file CoinPackedMatrix.hpp.

const CoinBigIndex* CoinPackedMatrix::getVectorStarts ( ) const
inline

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

See start_.

Definition at line 158 of file CoinPackedMatrix.hpp.

const int* CoinPackedMatrix::getVectorLengths ( ) const
inline

The lengths of the major-dimension vectors.

See length_.

Definition at line 164 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 168 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 178 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::getVectorSize ( const int  i) const
inline

The length of i'th vector.

Definition at line 187 of file CoinPackedMatrix.hpp.

const CoinShallowPackedVector CoinPackedMatrix::getVector ( int  i) const
inline

Return the i'th vector in matrix.

Definition at line 197 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 dimensions of the matrix.

The method name is deceptive; the effect is to append empty columns and/or rows to the matrix to reach the specified dimensions. A negative number for either dimension means that that dimension doesn't change. An exception will be thrown if the specified dimensions are smaller than the current dimensions.

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 compiled with COIN_DEBUG defined this method throws an exception if the column vector specifies a nonexistent row index. 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 compiled with COIN_DEBUG defined this method throws an exception if the column vector specifies a nonexistent row index. 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 compiled with COIN_DEBUG defined this method throws an exception if any of the column vectors specify a nonexistent row index. 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 the number of errors (nonexistent or duplicate row index). No error checking is performed if numberRows < 0.

void CoinPackedMatrix::appendRow ( const CoinPackedVectorBase vec)

Append a row to the end of the matrix.

When compiled with COIN_DEBUG defined this method throws an exception if the row vector specifies a nonexistent column index. 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 compiled with COIN_DEBUG defined this method throws an exception if the row vector specifies a nonexistent column index. 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 compiled with COIN_DEBUG defined this method throws an exception if any of the row vectors specify a nonexistent column index. 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 the number of errors (nonexistent or duplicate column index). No error checking is performed 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

CoinBigIndex 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

CoinBigIndex 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.

CoinBigIndex 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)

Make a reverse-ordered copy.

This method makes an exact replica of the argument with the major vector orientation changed from row (column) to column (row). The extra space parameters are also copied and reversed. (Cf. reverseOrdering, which does the same thing in place.)

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.

void CoinPackedMatrix::reverseOrdering ( )

Reverse the ordering of the packed matrix.

Change the major vector orientation of the matrix data structures from row (column) to column (row). (Cf. reverseOrderedCopyOf, which does the same thing but produces a new matrix.)

void CoinPackedMatrix::transpose ( )

Transpose the matrix.

Note
If you start with a column-ordered matrix and invoke transpose, you will have a row-ordered transposed matrix. To change the major vector orientation (e.g., to transform a column-ordered matrix to a column-ordered transposed matrix), invoke transpose() followed by reverseOrdering().
void CoinPackedMatrix::swap ( CoinPackedMatrix matrix)

Swap the content of two packed matrices.

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

Return A * x in y.

Precondition
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.

Precondition
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 504 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::setMajorDim ( int  value)
inline

Set major dimension.

For row ordered matrix this would be the number of rows. Use with great care.

Definition at line 507 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 510 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::setMinorDim ( int  value)
inline

Set minor dimension.

For row ordered matrix this would be the number of columns. Use with great care.

Definition at line 513 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 517 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-dimension vectors to the end of the matrix.

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

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

This case is when we know there are no gaps and majorDim_ will not change.

Todo:
This method really belongs in the group of protected methods with appendMinor; there are no safeties here even with COIN_DEBUG. Apparently this method was needed in ClpPackedMatrix and giving it proper visibility was too much trouble. Should be moved.
void CoinPackedMatrix::majorAppendSameOrdered ( const CoinPackedMatrix matrix)

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

Precondition
minorDim_ == matrix.minorDim_
This method throws an exception if the minor dimensions are not the same.
void CoinPackedMatrix::minorAppendSameOrdered ( const CoinPackedMatrix matrix)

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

Precondition
majorDim_ == matrix.majorDim_
This method throws an exception if the major dimensions are not the same.
void CoinPackedMatrix::majorAppendOrthoOrdered ( const CoinPackedMatrix matrix)

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

Precondition
minorDim_ == matrix.majorDim_
This method throws an exception if the minor dimension of the current matrix is not the same as the major dimension of the argument matrix.
void CoinPackedMatrix::minorAppendOrthoOrdered ( const CoinPackedMatrix matrix)

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

Precondition
majorDim_ == matrix.minorDim_
This method throws an exception if the major dimension of the current matrix is not the same as the minor dimension of the argument matrix.
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.

Precondition
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.

Precondition
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.

template<class FloatEqual >
bool CoinPackedMatrix::isEquivalent ( const CoinPackedMatrix rhs,
const FloatEqual &  eq 
) const
inline

Test for equivalence.

Two matrices are equivalent if they are both row- or column-ordered, they have the same dimensions, and each (major) vector is equivalent. The operator used to test for equality can be specified using the FloatEqual template parameter.

Definition at line 663 of file CoinPackedMatrix.hpp.

bool CoinPackedMatrix::isEquivalent2 ( const CoinPackedMatrix rhs) const

Test for equivalence and report differences.

Equivalence is defined as for isEquivalent. In addition, this method will print differences to std::cerr. Intended for use in unit tests and for debugging.

bool CoinPackedMatrix::isEquivalent ( const CoinPackedMatrix rhs) const

Test for equivalence.

The test for element equality is the default CoinRelFltEq operator.

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 start_ and length_.

Definition at line 713 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 start_ and length_.

Definition at line 719 of file CoinPackedMatrix.hpp.

CoinBigIndex* CoinPackedMatrix::getMutableVectorStarts ( ) const
inline

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

Definition at line 723 of file CoinPackedMatrix.hpp.

int* CoinPackedMatrix::getMutableVectorLengths ( ) const
inline

The lengths of the major-dimension vectors.

Definition at line 725 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::setNumElements ( CoinBigIndex  value)
inline

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

Definition at line 727 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::nullElementArray ( )
inline

NULLify element array.

Used when space is very tight. Does not free the space!

Definition at line 735 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::nullStartArray ( )
inline

NULLify start array.

Used when space is very tight. Does not free the space!

Definition at line 741 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::nullLengthArray ( )
inline

NULLify length array.

Used when space is very tight. Does not free the space!

Definition at line 747 of file CoinPackedMatrix.hpp.

void CoinPackedMatrix::nullIndexArray ( )
inline

NULLify index array.

Used when space is very tight. Does not free the space!

Definition at line 753 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::verifyMtx ( int  verbosity = 1,
bool  zeroesAreError = false 
) const

Scan the matrix for anomalies.

Returns the number of anomalies. Scans the structure for gaps, obviously bogus indices and coefficients, and inconsistencies. Gaps are not an error unless hasGaps() says the matrix should be gap-free. Zeroes are not an error unless zeroesAreError is set to true.

Values for verbosity are:

  • 0: No messages, just the return value
  • 1: Messages about errors
  • 2: If there are no errors, a message indicating the matrix was checked is printed (positive confirmation).
  • 3: Adds a bit more information about the matrix.
  • 4: Prints warnings about zeroes even if they're not considered errors.

Obviously bogus coefficients are coefficients that are NaN or have absolute value greater than 1e50. Zeros have absolute value less than 1e-50.

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 a row (colum) ordered matrix.

If numberOther > 0 the method will check if any of the new rows (columns) contain duplicate indices or invalid indices and return the number of errors. A valid minor index must satisfy

0 <= k < numberOther

If numberOther < 0 no checking is performed.

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 a column (row) ordered matrix.

If numberOther > 0 the method will check if any of the new rows (columns) contain duplicate indices or indices outside the current range for the major dimension and return the number of violations. If numberOther <= 0 the major dimension will be expanded as necessary and there are no checks for duplicate indices.

CoinBigIndex CoinPackedMatrix::getLastStart ( ) const
inlineprivate

Definition at line 896 of file CoinPackedMatrix.hpp.

Friends And Related Function Documentation

void CoinPackedMatrixUnitTest ( )
friend

Test 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.

Member Data Documentation

bool CoinPackedMatrix::colOrdered_
protected

A flag indicating whether the matrix is column or row major ordered.

Definition at line 907 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 912 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 916 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 920 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 923 of file CoinPackedMatrix.hpp.

CoinBigIndex* CoinPackedMatrix::start_
protected

Starting positions of major-dimension vectors.

Definition at line 925 of file CoinPackedMatrix.hpp.

int* CoinPackedMatrix::length_
protected

Lengths of major-dimension vectors.

Definition at line 927 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::majorDim_
protected

number of vectors in matrix

Definition at line 930 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::minorDim_
protected

size of other dimension

Definition at line 932 of file CoinPackedMatrix.hpp.

CoinBigIndex CoinPackedMatrix::size_
protected

the number of nonzero entries

Definition at line 934 of file CoinPackedMatrix.hpp.

int CoinPackedMatrix::maxMajorDim_
protected

max space allocated for major-dimension

Definition at line 937 of file CoinPackedMatrix.hpp.

CoinBigIndex CoinPackedMatrix::maxSize_
protected

max space allocated for entries

Definition at line 939 of file CoinPackedMatrix.hpp.


The documentation for this class was generated from the following file: