Go to the documentation of this file.
6 #ifndef CoinPackedMatrix_H
7 #define CoinPackedMatrix_H
165 #ifndef COIN_FAST_CODE
167 throw CoinError(
"bad index",
"vectorFirst",
"CoinPackedMatrix");
174 #ifndef COIN_FAST_CODE
176 throw CoinError(
"bad index",
"vectorLast",
"CoinPackedMatrix");
182 #ifndef COIN_FAST_CODE
184 throw CoinError(
"bad index",
"vectorSize",
"CoinPackedMatrix");
188 #ifndef CLP_NO_VECTOR
191 #ifndef COIN_FAST_CODE
193 throw CoinError(
"bad index",
"vector",
"CoinPackedMatrix");
231 #ifndef CLP_NO_VECTOR
247 const int *vecind,
const double *vecelem);
248 #ifndef CLP_NO_VECTOR
265 const double * element,
int numberRows=-1);
266 #ifndef CLP_NO_VECTOR
282 const int *vecind,
const double *vecelem);
283 #ifndef CLP_NO_VECTOR
300 const double * element,
int numberColumns=-1);
322 const int numReplace,
const double * newElements);
328 bool keepZero=
false);
368 const int numMajor,
const int * indMajor);
373 const int numMajor,
const int * indMajor);
379 const int numMajor,
const int * indMajor,
380 const int numMinor,
const int * indMinor);
390 const int minor,
const int major,
const CoinBigIndex numels,
391 const double * elem,
const int * ind,
393 const double extraMajor=0.0,
const double extraGap=0.0);
417 const int minor,
const int major,
419 double *& elem,
int *& ind,
421 const int maxmajor = -1,
const CoinBigIndex maxsize = -1);
459 void times(
const double * x,
double * y)
const;
460 #ifndef CLP_NO_VECTOR
469 #ifndef CLP_NO_VECTOR
531 #ifndef CLP_NO_VECTOR
537 const double *vecelem);
538 #ifndef CLP_NO_VECTOR
548 const double *vecelem);
549 #ifndef CLP_NO_VECTOR
568 const double * element);
624 #ifndef CLP_NO_VECTOR
635 #ifndef CLP_NO_VECTOR
647 #ifndef CLP_NO_VECTOR
655 template <
class FloatEqual>
bool
758 const double extraMajor,
const double extraGap);
761 const int minor,
const int major,
const CoinBigIndex numels,
762 const double * elem,
const int * ind,
764 const double extraMajor,
const double extraGap);
767 const int minor,
const int major,
const CoinBigIndex numels,
768 const double * elem,
const int * ind,
782 const int * rowIndices,
783 const int * colIndices,
784 const double * elements,
805 int extraForMajor,
int extraElements,
811 int numberRows,
const int * whichRows,
812 int numberColumns,
const int * whichColumns);
841 int verifyMtx(
int verbosity = 1,
bool zeroesAreError =
false)
const ;
848 const int minor,
const int major,
const CoinBigIndex numels,
849 const double * elem,
const int * ind,
851 const double extraMajor=0.0,
const double extraGap=0.0);
854 const int minor,
const int major,
855 const double * elem,
const int * ind,
858 const int minor,
const int major,
const CoinBigIndex numels,
859 const double * elem,
const int * ind,
875 const double * element,
int numberOther=-1);
887 const double * element,
int numberOther=-1);
void copyReuseArrays(const CoinPackedMatrix &rhs)
Copy method.
CoinBigIndex size_
the number of nonzero entries
CoinPackedMatrix(const CoinPackedMatrix &m, int extraForMajor, int extraElements, bool reverseOrdering=false)
Copy constructor with fine tuning.
void rightAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "right" of the current matrix.
bool colOrdered_
A flag indicating whether the matrix is column or row major ordered.
void setExtraGap(const double newGap)
Set the extra gap to be allocated to the specified value.
void reserve(const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false)
Reserve sufficient space for appending major-ordered vectors.
int getVectorSize(const int i) const
The length of i'th vector.
void submatrixOfWithDuplicates(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
int * index_
List of nonzero element minor-dimension indices.
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 times(const CoinPackedVectorBase &x, double *y) const
Return A * x in y.
void setExtraMajor(const double newMajor)
Set the extra major to be allocated to the specified value.
void modifyCoefficient(int row, int column, double newElement, bool keepZero=false)
Modify one element of packed matrix.
int majorDim_
number of vectors in matrix
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.
void majorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the right end of this matrix.
CoinBigIndex * start_
Starting positions of major-dimension vectors.
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)
void appendMajorVector(const int vecsize, const int *vecind, const double *vecelem)
Append a major-dimension vector to the end of the matrix.
void appendRow(const CoinPackedVectorBase &vec)
Append a row to the end of the matrix.
void nullLengthArray()
NULLify length array.
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.
CoinBigIndex maxSize_
max space allocated for entries
double * element_
List of nonzero element values.
int cleanMatrix(double threshold=1.0e-20)
Really clean up matrix.
CoinBigIndex getNumElements() const
Number of entries in the packed matrix.
void nullIndexArray()
NULLify index array.
void transpose()
Transpose the matrix.
int * countOrthoLength() const
Count the number of entries in every minor-dimension vector and return an array containing these leng...
void transposeTimes(const CoinPackedVectorBase &x, double *y) const
Return x * A in y.
int getNumRows() const
Number of rows.
void timesMajor(const CoinPackedVectorBase &x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
void resizeForAddingMajorVectors(const int numVec, const int *lengthVec)
int minorDim_
size of other dimension
CoinPackedMatrix(const CoinPackedMatrix &wholeModel, int numberRows, const int *whichRows, int numberColumns, const int *whichColumns)
Subset constructor (without gaps).
const double * getElements() const
A vector containing the elements in the packed matrix.
int * getMutableVectorLengths() const
The lengths of the major-dimension vectors.
void appendMinorVector(const int vecsize, const int *vecind, const double *vecelem)
Append a minor-dimension vector to the end of the matrix.
void dumpMatrix(const char *fname=NULL) const
Dump the matrix on stdout.
int * length_
Lengths of major-dimension vectors.
void submatrixOf(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
CoinPackedMatrix & operator=(const CoinPackedMatrix &rhs)
Assignment operator.
double extraMajor_
his much times more space should be allocated for major-dimension vectors when the matrix is resized.
CoinBigIndex * getMutableVectorStarts() const
The positions where the major-dimension vectors start in element_ and index_.
bool isEquivalent(const CoinPackedMatrix &rhs) const
Test for equivalence.
void nullStartArray()
NULLify start array.
int * getMutableIndices() const
A vector containing the minor indices of the elements in the packed matrix.
double getCoefficient(int row, int column) const
Return one element of packed matrix.
CoinBigIndex getLastStart() const
int getSizeVectorStarts() const
The size of the vectorStarts array.
double getExtraMajor() const
Return the current setting of the extra major.
void setDimensions(int numrows, int numcols)
Set the dimensions of the matrix.
void reverseOrderedCopyOf(const CoinPackedMatrix &rhs)
Make a reverse-ordered copy.
void clear()
Clear the data, but do not free any arrays.
void transposeTimes(const double *x, double *y) const
Return x * A in y.
int compress(double threshold)
Eliminate all elements in matrix whose absolute value is less than threshold.
int maxMajorDim_
max space allocated for major-dimension
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.
void deleteMinorVectors(const int numDel, const int *indDel)
Delete the minor-dimension vectors whose indices are listed in indDel.
void printMatrixElement(const int row_val, const int col_val) const
Print a single matrix element.
void minorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the bottom end of this matrix.
const CoinBigIndex * getVectorStarts() const
The positions where the major-dimension vectors start in elements and indices.
double * getMutableElements() 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.
virtual ~CoinPackedMatrix()
Destructor.
void setNumElements(CoinBigIndex value)
Change the size of the bulk store after modifying - be careful.
CoinBigIndex getVectorFirst(const int i) const
The position of the first element in the i'th major-dimension vector.
const int * getVectorLengths() const
The lengths of the major-dimension vectors.
void appendMinorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several minor-dimension vectors to the end of the matrix.
bool isEquivalent2(const CoinPackedMatrix &rhs) const
Test for equivalence and report differences.
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.
const CoinShallowPackedVector getVector(int i) const
Return the i'th vector in matrix.
int getSizeVectorLengths() const
The size of the vectorLengths array.
CoinPackedMatrix(const CoinPackedMatrix &m)
Copy constructor.
void minorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the bottom end of this matrix.
void deleteRows(const int numDel, const int *indDel)
Delete the rows whose indices are listed in indDel.
void appendCol(const CoinPackedVectorBase &vec)
Append a column to the end of the matrix.
void times(const double *x, double *y) const
Return A * x in y.
void countOrthoLength(int *counts) const
Count the number of entries in every minor-dimension vector and fill in an array containing these len...
bool hasGaps() const
Whether the packed matrix has gaps or not.
Abstract base class for various sparse vectors.
void bottomAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "bottom" of the current matrix.
void timesMinor(const CoinPackedVectorBase &x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
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 setMajorDim(int value)
Set major dimension.
CoinPackedMatrix(const bool colordered, const double extraMajor, const double extraGap)
A constructor where the ordering and the gaps are specified.
int getMaxMajorDim() const
Current maximum for major dimension.
int getMinorDim() const
Minor dimension.
Sparse Matrix Base Class.
int getMajorDim() const
Major dimension.
void orderMatrix()
Sort all columns so indices are increasing.in each column.
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 setMinorDim(int value)
Set minor dimension.
void nullElementArray()
NULLify element array.
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.
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 timesMajor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
void appendRow(const int vecsize, const int *vecind, const double *vecelem)
Append a row to the end of the matrix.
void replaceVector(const int index, const int numReplace, const double *newElements)
Replace the elements of a vector.
double getExtraGap() const
Return the current setting of the extra gap.
void appendMajorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several major-dimensonvectors to the end of the matrix.
void CoinPackedMatrixUnitTest()
Test the methods in the CoinPackedMatrix class.
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.
int * getMajorIndices() const
Returns an array containing major indices.
void reverseOrdering()
Reverse the ordering of the packed matrix.
void appendMajorVector(const CoinPackedVectorBase &vec)
Append a major-dimension vector to the end of the matrix.
double extraGap_
This much times more space should be allocated for each major-dimension vector (with respect to the n...
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.
void appendMinorVector(const CoinPackedVectorBase &vec)
Append a minor-dimension vector to the end of the matrix.
Error Class thrown by an exception.
int verifyMtx(int verbosity=1, bool zeroesAreError=false) const
Scan the matrix for anomalies.
bool isEquivalent(const CoinPackedVectorBase &rhs, const FloatEqual &eq) const
equivalent - If shallow packed vector A & B are equivalent, then they are still equivalent no matter ...
void appendCols(const int numcols, const CoinPackedVectorBase *const *cols)
Append a set of columns to the end of the matrix.
CoinPackedMatrix(const bool colordered, const int *rowIndices, const int *colIndices, const double *elements, CoinBigIndex numels)
Create packed matrix from triples.
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)
Equality to a scaled tolerance.
friend void CoinPackedMatrixUnitTest()
Test the methods in the CoinPackedMatrix class.
void appendCol(const int vecsize, const int *vecind, const double *vecelem)
Append a column to the end of the matrix.
void deleteMajorVectors(const int numDel, const int *indDel)
Delete the major-dimension vectors whose indices are listed in indDel.
void copyOf(const CoinPackedMatrix &rhs)
Copy method.
bool isColOrdered() const
Whether the packed matrix is column major ordered or not.
void removeGaps(double removeValue=-1.0)
Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValu...
void timesMinor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
void majorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the right end of this matrix.
void appendRows(const int numrows, const CoinPackedVectorBase *const *rows)
Append a set of rows to the end of the matrix.
CoinPackedMatrix()
Default Constructor creates an empty column ordered packed matrix.
void resizeForAddingMinorVectors(const int *addedEntries)
int eliminateDuplicates(double threshold)
Eliminate all duplicate AND small elements in matrix The column starts are not affected.
void deleteCols(const int numDel, const int *indDel)
Delete the columns whose indices are listed in indDel.
void swap(CoinPackedMatrix &matrix)
Swap the content of two packed matrices.
int getNumCols() const
Number of columns.
bool isEquivalent(const CoinPackedMatrix &rhs, const FloatEqual &eq) const
Test for equivalence.