4 #ifndef CoinPackedMatrix_H
5 #define CoinPackedMatrix_H
122 #ifndef COIN_FAST_CODE
124 throw CoinError(
"bad index",
"vectorFirst",
"CoinPackedMatrix");
131 #ifndef COIN_FAST_CODE
133 throw CoinError(
"bad index",
"vectorLast",
"CoinPackedMatrix");
139 #ifndef COIN_FAST_CODE
141 throw CoinError(
"bad index",
"vectorSize",
"CoinPackedMatrix");
145 #ifndef CLP_NO_VECTOR
148 #ifndef COIN_FAST_CODE
150 throw CoinError(
"bad index",
"vector",
"CoinPackedMatrix");
185 #ifndef CLP_NO_VECTOR
197 const int *vecind,
const double *vecelem);
198 #ifndef CLP_NO_VECTOR
212 const double * element,
int numberRows=-1);
213 #ifndef CLP_NO_VECTOR
225 const int *vecind,
const double *vecelem);
226 #ifndef CLP_NO_VECTOR
240 const double * element,
int numberColumns=-1);
254 void deleteCols(
const int numDel,
const int * indDel);
256 void deleteRows(
const int numDel,
const int * indDel);
262 const int numReplace,
const double * newElements);
268 bool keepZero=
false);
308 const int numMajor,
const int * indMajor);
313 const int numMajor,
const int * indMajor);
319 const int numMajor,
const int * indMajor,
320 const int numMinor,
const int * indMinor);
329 void copyOf(
const bool colordered,
330 const int minor,
const int major,
const CoinBigIndex numels,
331 const double * elem,
const int * ind,
333 const double extraMajor=0.0,
const double extraGap=0.0);
351 const int minor,
const int major,
353 double *& elem,
int *& ind,
355 const int maxmajor = -1,
const CoinBigIndex maxsize = -1);
384 void times(
const double * x,
double * y)
const;
385 #ifndef CLP_NO_VECTOR
394 #ifndef CLP_NO_VECTOR
434 void dumpMatrix(
const char* fname = NULL)
const;
447 #ifndef CLP_NO_VECTOR
453 const double *vecelem);
454 #ifndef CLP_NO_VECTOR
464 const double *vecelem);
465 #ifndef CLP_NO_VECTOR
523 void timesMajor(
const double * x,
double * y)
const;
524 #ifndef CLP_NO_VECTOR
534 void timesMinor(
const double * x,
double * y)
const;
535 #ifndef CLP_NO_VECTOR
547 #ifndef CLP_NO_VECTOR
553 template <
class FloatEqual>
bool
630 const double extraMajor,
const double extraGap);
633 const int minor,
const int major,
const CoinBigIndex numels,
634 const double * elem,
const int * ind,
636 const double extraMajor,
const double extraGap);
639 const int minor,
const int major,
const CoinBigIndex numels,
640 const double * elem,
const int * ind,
654 const int * rowIndices,
655 const int * colIndices,
656 const double * elements,
671 int numberRows,
const int * whichRows,
672 int numberColumns,
const int * whichColumns);
682 const int minor,
const int major,
const CoinBigIndex numels,
683 const double * elem,
const int * ind,
685 const double extraMajor=0.0,
const double extraGap=0.0);
688 const int minor,
const int major,
689 const double * elem,
const int * ind,
692 const int minor,
const int major,
const CoinBigIndex numels,
693 const double * elem,
const int * ind,
703 const double * element,
int numberOther=-1);
710 const double * element,
int numberOther=-1);
717 const double * element);
void appendMinorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several minor-dimensonvectors to the end of the matrix.
void clear()
Clear the data, but do not free any arrays.
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 reserve(const int newMaxMajorDim, const CoinBigIndex newMaxSize, bool create=false)
Reserve sufficient space for appending major-ordered vectors.
void deleteMajorVectors(const int numDel, const int *indDel)
Delete the major-dimension vectors whose indices are listed in indDel.
CoinBigIndex size_
the number of nonzero entries
CoinBigIndex getVectorFirst(const int i) const
The position of the first element in the i'th major-dimension vector.
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.
void setExtraMajor(const double newMajor)
Set the extra major to be allocated to the specified value.
Equality to a scaled tolerance.
void swap(CoinPackedMatrix &matrix)
Swap the content of the two packed matrix.
void appendMinorVector(const CoinPackedVectorBase &vec)
Append a minor-dimension vector to the end of the matrix.
void rightAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "right" of the current matrix.
void nullIndexArray()
NULLify index array - used when space is very tight.
void timesMajor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
void appendMinorFast(const int number, const CoinBigIndex *starts, const int *index, const double *element)
Append a set of rows/columns to the end of the matrix.
void minorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the bottom end of this matrix.
double extraGap_
This much times more space should be allocated for each major-dimension vector (with respect to the n...
CoinBigIndex getLastStart() const
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 times(const double *x, double *y) const
Return A * x in y.
int compress(double threshold)
Eliminate all elements in matrix whose absolute value is less than threshold.
void submatrixOf(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
const CoinShallowPackedVector getVector(int i) const
Return the i'th vector in matrix.
friend void CoinPackedMatrixUnitTest()
A function that tests the methods in the CoinPackedMatrix class.
void orderMatrix()
Sort all columns so indices are increasing.in each column.
void transposeTimes(const double *x, double *y) const
Return x * A in y.
bool hasGaps() const
Whether the packed matrix has gaps or not.
double getExtraGap() const
Return the current setting of the extra gap.
double extraMajor_
his much times more space should be allocated for major-dimension vectors when the matrix is resized...
int * index_
List of nonzero element minor-dimension indices.
int getNumRows() const
Number of rows.
void deleteCols(const int numDel, const int *indDel)
Delete the columns whose indices are listed in indDel.
Sparse Matrix Base Class.
int * countOrthoLength() const
Count the number of entries in every minor-dimension vector and return an array containing these leng...
void deleteMinorVectors(const int numDel, const int *indDel)
Delete the minor-dimension vectors whose indices are listed in indDel.
CoinBigIndex maxSize_
max space allocated for entries
virtual ~CoinPackedMatrix()
Destructor.
int getVectorSize(const int i) const
The length of i'th vector.
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.
Abstract base class for various sparse vectors.
void appendRow(const CoinPackedVectorBase &vec)
Append a row to the end of the matrix.
int maxMajorDim_
max space allocated for major-dimension
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.
bool colOrdered_
A flag indicating whether the matrix is column or row major ordered.
int minorDim_
size of other dimension
int getMinorDim() const
Minor dimension.
int getMajorDim() const
Major dimension.
void reverseOrderedCopyOf(const CoinPackedMatrix &rhs)
Reverse copy method.
void appendMajorVector(const CoinPackedVectorBase &vec)
Append a major-dimension vector to the end of the matrix.
void majorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the right end of this matrix.
void copyReuseArrays(const CoinPackedMatrix &rhs)
Copy method.
void majorAppendOrthoOrdered(const CoinPackedMatrix &matrix)
Append the rows of the argument to the right end of this matrix.
int getSizeVectorStarts() const
The size of the vectorStarts array.
double getCoefficient(int row, int column) const
Return one element of packed matrix.
const int * getIndices() const
A vector containing the minor indices of the elements in the packed matrix.
void dumpMatrix(const char *fname=NULL) const
Dump the matrix on stdout.
void replaceVector(const int index, const int numReplace, const double *newElements)
Replace the elements of a vector.
void CoinPackedMatrixUnitTest()
A function that tests the methods in the CoinPackedMatrix class.
const CoinBigIndex * getVectorStarts() const
The positions where the major-dimension vectors start in elements and indices.
void printMatrixElement(const int row_val, const int col_val) const
Print a single matrix element.
bool isEquivalent2(const CoinPackedMatrix &rhs) const
Equivalence.
int getMaxMajorDim() const
Current maximum for major dimension.
void reverseOrdering()
Reverse the ordering of the packed matrix.
int * length_
Lengths of major-dimension vectors.
CoinPackedMatrix()
Default Constructor creates an empty column ordered packed matrix.
void setNumElements(CoinBigIndex value)
Change size after modifying - be careful.
int cleanMatrix(double threshold=1.0e-20)
Really clean up matrix.
void nullLengthArray()
NULLify length array - used when space is very tight.
void setExtraGap(const double newGap)
Set the extra gap to be allocated to the specified value.
int getNumCols() const
Number of columns.
bool isEquivalent(const CoinPackedMatrix &rhs, const FloatEqual &eq) const
Equivalence.
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 submatrixOfWithDuplicates(const CoinPackedMatrix &matrix, const int numMajor, const int *indMajor)
Extract a submatrix from matrix.
void appendMajorVectors(const int numvecs, const CoinPackedVectorBase *const *vecs)
Append several major-dimensonvectors to the end of the matrix.
void modifyCoefficient(int row, int column, double newElement, bool keepZero=false)
Modify one element of packed matrix.
int * getMajorIndices() const
Returns an array containing major indices.
int * getMutableIndices() const
A vector containing the minor indices of the elements in the packed matrix.
void nullElementArray()
NULLify element array - used when space is very tight.
void bottomAppendPackedMatrix(const CoinPackedMatrix &matrix)
Append the argument to the "bottom" of the current matrix.
void transpose()
Transpose the matrix.
void timesMinor(const double *x, double *y) const
Return A * x (multiplied from the "right" direction) in y.
int majorDim_
number of vectors in matrix
void appendRows(const int numrows, const CoinPackedVectorBase *const *rows)
Append a set of rows to the end of the matrix.
Error Class thrown by an exception.
double * element_
List of nonzero element values.
CoinBigIndex * getMutableVectorStarts() 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.
void minorAppendSameOrdered(const CoinPackedMatrix &matrix)
Append the columns of the argument to the bottom end of this matrix.
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...
CoinBigIndex * start_
Starting positions of major-dimension vectors.
void setDimensions(int numrows, int numcols)
Set the dimansions of the matrix.
int * getMutableVectorLengths() const
The lengths of the major-dimension vectors.
bool isColOrdered() const
Whether the packed matrix is column major ordered or not.
int eliminateDuplicates(double threshold)
Eliminate all duplicate AND small elements in matrix The column starts are not affected.
int getSizeVectorLengths() const
The size of the vectorLengths array.
CoinBigIndex getNumElements() const
Number of entries in the packed matrix.
void nullStartArray()
NULLify start array - used when space is very tight.
Function objects for testing equality of real numbers.
void deleteRows(const int numDel, const int *indDel)
Delete the rows whose indices are listed in indDel.
void copyOf(const CoinPackedMatrix &rhs)
Copy method.
void appendCol(const CoinPackedVectorBase &vec)
Append a column to the end of the matrix.
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 appendCols(const int numcols, const CoinPackedVectorBase *const *cols)
Append a set of columns to the end of the matrix.
void removeGaps(double removeValue=-1.0)
Remove the gaps from the matrix if there were any Can also remove small elements fabs() <= removeValu...
CoinPackedMatrix & operator=(const CoinPackedMatrix &rhs)
Assignment operator.
double getExtraMajor() const
Return the current setting of the extra major.
const double * getElements() const
A vector containing the elements in the packed matrix.
const int * getVectorLengths() const
The lengths of the major-dimension vectors.