00001
00002
00003
00004 #ifndef ClpPackedMatrix_H
00005 #define ClpPackedMatrix_H
00006
00007 #include "CoinPragma.hpp"
00008
00009 #include "ClpMatrixBase.hpp"
00010
00017 class ClpPackedMatrix2;
00018 class ClpPackedMatrix3;
00019 class ClpPackedMatrix : public ClpMatrixBase {
00020
00021 public:
00024
00025 virtual CoinPackedMatrix * getPackedMatrix() const {
00026 return matrix_;
00027 }
00029 virtual bool isColOrdered() const {
00030 return matrix_->isColOrdered();
00031 }
00033 virtual CoinBigIndex getNumElements() const {
00034 return matrix_->getNumElements();
00035 }
00037 virtual int getNumCols() const {
00038 return matrix_->getNumCols();
00039 }
00041 virtual int getNumRows() const {
00042 return matrix_->getNumRows();
00043 }
00044
00049 virtual const double * getElements() const {
00050 return matrix_->getElements();
00051 }
00053 inline double * getMutableElements() const {
00054 return matrix_->getMutableElements();
00055 }
00061 virtual const int * getIndices() const {
00062 return matrix_->getIndices();
00063 }
00064
00065 virtual const CoinBigIndex * getVectorStarts() const {
00066 return matrix_->getVectorStarts();
00067 }
00069 virtual const int * getVectorLengths() const {
00070 return matrix_->getVectorLengths();
00071 }
00073 virtual int getVectorLength(int index) const {
00074 return matrix_->getVectorSize(index);
00075 }
00076
00078 virtual void deleteCols(const int numDel, const int * indDel);
00080 virtual void deleteRows(const int numDel, const int * indDel);
00081 #ifndef CLP_NO_VECTOR
00082
00083 virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
00085 virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
00086 #endif
00087
00091 virtual int appendMatrix(int number, int type,
00092 const CoinBigIndex * starts, const int * index,
00093 const double * element, int numberOther = -1);
00098 virtual void replaceVector(const int index,
00099 const int numReplace, const double * newElements) {
00100 matrix_->replaceVector(index, numReplace, newElements);
00101 }
00105 virtual void modifyCoefficient(int row, int column, double newElement,
00106 bool keepZero = false) {
00107 matrix_->modifyCoefficient(row, column, newElement, keepZero);
00108 }
00110 virtual ClpMatrixBase * reverseOrderedCopy() const;
00112 virtual CoinBigIndex countBasis(const int * whichColumn,
00113 int & numberColumnBasic);
00115 virtual void fillBasis(ClpSimplex * model,
00116 const int * whichColumn,
00117 int & numberColumnBasic,
00118 int * row, int * start,
00119 int * rowCount, int * columnCount,
00120 CoinFactorizationDouble * element);
00123 virtual int scale(ClpModel * model, const ClpSimplex * baseModel = NULL) const ;
00126 virtual void scaleRowCopy(ClpModel * model) const ;
00128 void createScaledMatrix(ClpSimplex * model) const;
00132 virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
00143 virtual bool allElementsInRange(ClpModel * model,
00144 double smallest, double largest,
00145 int check = 15);
00149 virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
00150 double & smallestPositive, double & largestPositive);
00151
00154 virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
00155 int column) const ;
00160 virtual void unpackPacked(ClpSimplex * model,
00161 CoinIndexedVector * rowArray,
00162 int column) const;
00165 virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
00166 int column, double multiplier) const ;
00168 virtual void add(const ClpSimplex * model, double * array,
00169 int column, double multiplier) const;
00171 virtual void releasePackedMatrix() const { }
00176 virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
00178 virtual bool canDoPartialPricing() const;
00180 virtual void partialPricing(ClpSimplex * model, double start, double end,
00181 int & bestSequence, int & numberWanted);
00183 virtual int refresh(ClpSimplex * model);
00184
00185 virtual void reallyScale(const double * rowScale, const double * columnScale);
00191 virtual void setDimensions(int numrows, int numcols);
00193
00199 virtual void times(double scalar,
00200 const double * x, double * y) const;
00202 virtual void times(double scalar,
00203 const double * x, double * y,
00204 const double * rowScale,
00205 const double * columnScale) const;
00209 virtual void transposeTimes(double scalar,
00210 const double * x, double * y) const;
00212 virtual void transposeTimes(double scalar,
00213 const double * x, double * y,
00214 const double * rowScale,
00215 const double * columnScale,
00216 double * spare = NULL) const;
00221 void transposeTimesSubset( int number,
00222 const int * which,
00223 const double * pi, double * y,
00224 const double * rowScale,
00225 const double * columnScale,
00226 double * spare = NULL) const;
00231 virtual void transposeTimes(const ClpSimplex * model, double scalar,
00232 const CoinIndexedVector * x,
00233 CoinIndexedVector * y,
00234 CoinIndexedVector * z) const;
00239 void transposeTimesByColumn(const ClpSimplex * model, double scalar,
00240 const CoinIndexedVector * x,
00241 CoinIndexedVector * y,
00242 CoinIndexedVector * z) const;
00248 virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
00249 const CoinIndexedVector * x,
00250 CoinIndexedVector * y,
00251 CoinIndexedVector * z) const;
00255 virtual void subsetTransposeTimes(const ClpSimplex * model,
00256 const CoinIndexedVector * x,
00257 const CoinIndexedVector * y,
00258 CoinIndexedVector * z) const;
00261 virtual bool canCombine(const ClpSimplex * model,
00262 const CoinIndexedVector * pi) const;
00264 virtual void transposeTimes2(const ClpSimplex * model,
00265 const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
00266 const CoinIndexedVector * pi2,
00267 CoinIndexedVector * spare,
00268 double referenceIn, double devex,
00269
00270 unsigned int * reference,
00271 double * weights, double scaleFactor);
00273 virtual void subsetTimes2(const ClpSimplex * model,
00274 CoinIndexedVector * dj1,
00275 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00276 double referenceIn, double devex,
00277
00278 unsigned int * reference,
00279 double * weights, double scaleFactor);
00281 void useEffectiveRhs(ClpSimplex * model);
00282 #if COIN_LONG_WORK
00283
00284 virtual void times(CoinWorkDouble scalar,
00285 const CoinWorkDouble * x, CoinWorkDouble * y) const ;
00286 virtual void transposeTimes(CoinWorkDouble scalar,
00287 const CoinWorkDouble * x, CoinWorkDouble * y) const ;
00288 #endif
00289
00290
00293
00294 inline CoinPackedMatrix * matrix() const {
00295 return matrix_;
00296 }
00300 inline void setMatrixNull() {
00301 matrix_ = NULL;
00302 }
00304 inline void makeSpecialColumnCopy() {
00305 flags_ |= 16;
00306 }
00308 void releaseSpecialColumnCopy();
00310 inline bool zeros() const {
00311 return ((flags_ & 1) != 0);
00312 }
00314 inline bool wantsSpecialColumnCopy() const {
00315 return ((flags_ & 16) != 0);
00316 }
00318 inline int flags() const {
00319 return flags_;
00320 }
00322 inline void checkGaps() {
00323 flags_ = (matrix_->hasGaps()) ? (flags_ | 2) : (flags_ & (~2));
00324 }
00326
00327
00331 ClpPackedMatrix();
00333 virtual ~ClpPackedMatrix();
00335
00339 ClpPackedMatrix(const ClpPackedMatrix&);
00341 ClpPackedMatrix(const CoinPackedMatrix&);
00344 ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
00345 int numberRows, const int * whichRows,
00346 int numberColumns, const int * whichColumns);
00347 ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
00348 int numberRows, const int * whichRows,
00349 int numberColumns, const int * whichColumns);
00350
00352 ClpPackedMatrix(CoinPackedMatrix * matrix);
00353
00354 ClpPackedMatrix& operator=(const ClpPackedMatrix&);
00356 virtual ClpMatrixBase * clone() const ;
00358 virtual void copy(const ClpPackedMatrix * from);
00361 virtual ClpMatrixBase * subsetClone (
00362 int numberRows, const int * whichRows,
00363 int numberColumns, const int * whichColumns) const ;
00365 void specialRowCopy(ClpSimplex * model, const ClpMatrixBase * rowCopy);
00367 void specialColumnCopy(ClpSimplex * model);
00369 virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
00371 private:
00373 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00374 int * COIN_RESTRICT index,
00375 double * COIN_RESTRICT array,
00376 const double tolerance) const;
00378 int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00379 const double * COIN_RESTRICT columnScale,
00380 int * COIN_RESTRICT index,
00381 double * COIN_RESTRICT array,
00382 const double tolerance) const;
00384 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00385 int * COIN_RESTRICT index,
00386 double * COIN_RESTRICT array,
00387 const unsigned char * status,
00388 const double tolerance) const;
00391 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00392 int * COIN_RESTRICT index,
00393 double * COIN_RESTRICT array,
00394 const unsigned char * status,
00395 int * COIN_RESTRICT spareIndex,
00396 double * COIN_RESTRICT spareArray,
00397 const double * COIN_RESTRICT reducedCost,
00398 double & upperTheta,
00399 double & bestPossible,
00400 double acceptablePivot,
00401 double dualTolerance,
00402 int & numberRemaining,
00403 const double zeroTolerance) const;
00405 int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00406 const double * COIN_RESTRICT columnScale,
00407 int * COIN_RESTRICT index,
00408 double * COIN_RESTRICT array,
00409 const unsigned char * status,
00410 const double tolerance) const;
00412 int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
00413 int * COIN_RESTRICT index,
00414 double * COIN_RESTRICT output,
00415 int numberColumns,
00416 const double tolerance,
00417 const double scalar) const;
00419 int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
00420 int * COIN_RESTRICT index,
00421 double * COIN_RESTRICT output,
00422 int * COIN_RESTRICT lookup,
00423 char * COIN_RESTRICT marked,
00424 const double tolerance,
00425 const double scalar) const;
00427 void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00428 CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00430 void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00431 const double tolerance, const double scalar) const;
00433 void clearCopies();
00434
00435
00436 protected:
00438 void checkFlags(int type) const;
00442
00443 CoinPackedMatrix * matrix_;
00445 int numberActiveColumns_;
00453 int flags_;
00455 ClpPackedMatrix2 * rowCopy_;
00457 ClpPackedMatrix3 * columnCopy_;
00459 };
00460 #ifdef THREAD
00461 #include <pthread.h>
00462 typedef struct {
00463 double acceptablePivot;
00464 const ClpSimplex * model;
00465 double * spare;
00466 int * spareIndex;
00467 double * arrayTemp;
00468 int * indexTemp;
00469 int * numberInPtr;
00470 double * bestPossiblePtr;
00471 double * upperThetaPtr;
00472 int * posFreePtr;
00473 double * freePivotPtr;
00474 int * numberOutPtr;
00475 const unsigned short * count;
00476 const double * pi;
00477 const CoinBigIndex * rowStart;
00478 const double * element;
00479 const unsigned short * column;
00480 int offset;
00481 int numberInRowArray;
00482 int numberLook;
00483 } dualColumn0Struct;
00484 #endif
00485 class ClpPackedMatrix2 {
00486
00487 public:
00493 void transposeTimes(const ClpSimplex * model,
00494 const CoinPackedMatrix * rowCopy,
00495 const CoinIndexedVector * x,
00496 CoinIndexedVector * spareArray,
00497 CoinIndexedVector * z) const;
00499 inline bool usefulInfo() const {
00500 return rowStart_ != NULL;
00501 }
00503
00504
00508 ClpPackedMatrix2();
00510 ClpPackedMatrix2(ClpSimplex * model, const CoinPackedMatrix * rowCopy);
00512 virtual ~ClpPackedMatrix2();
00514
00518 ClpPackedMatrix2(const ClpPackedMatrix2&);
00519 ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
00521
00522
00523 protected:
00527
00528 int numberBlocks_;
00530 int numberRows_;
00532 int * offset_;
00534 mutable unsigned short * count_;
00536 mutable CoinBigIndex * rowStart_;
00538 unsigned short * column_;
00540 double * work_;
00541 #ifdef THREAD
00542 pthread_t * threadId_;
00543 dualColumn0Struct * info_;
00544 #endif
00545
00546 };
00547 typedef struct {
00548 CoinBigIndex startElements_;
00549 int startIndices_;
00550 int numberInBlock_;
00551 int numberPrice_;
00552 int numberElements_;
00553 } blockStruct;
00554 class ClpPackedMatrix3 {
00555
00556 public:
00562 void transposeTimes(const ClpSimplex * model,
00563 const double * pi,
00564 CoinIndexedVector * output) const;
00566 void transposeTimes2(const ClpSimplex * model,
00567 const double * pi, CoinIndexedVector * dj1,
00568 const double * piWeight,
00569 double referenceIn, double devex,
00570
00571 unsigned int * reference,
00572 double * weights, double scaleFactor);
00574
00575
00579 ClpPackedMatrix3();
00581 ClpPackedMatrix3(ClpSimplex * model, const CoinPackedMatrix * columnCopy);
00583 virtual ~ClpPackedMatrix3();
00585
00589 ClpPackedMatrix3(const ClpPackedMatrix3&);
00590 ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
00592
00595 void sortBlocks(const ClpSimplex * model);
00597 void swapOne(const ClpSimplex * model, const ClpPackedMatrix * matrix,
00598 int iColumn);
00600
00601
00602 protected:
00606
00607 int numberBlocks_;
00609 int numberColumns_;
00611 int * column_;
00613 CoinBigIndex * start_;
00615 int * row_;
00617 double * element_;
00619 blockStruct * block_;
00621 };
00622
00623 #endif