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 { return matrix_;}
00027 virtual bool isColOrdered() const { return matrix_->isColOrdered(); }
00029 virtual CoinBigIndex getNumElements() const
00030 { return matrix_->getNumElements(); }
00032 virtual int getNumCols() const { return matrix_->getNumCols(); }
00034 virtual int getNumRows() const { return matrix_->getNumRows(); }
00035
00040 virtual const double * getElements() const
00041 { return matrix_->getElements();}
00043 inline double * getMutableElements() const
00044 { return matrix_->getMutableElements();}
00050 virtual const int * getIndices() const
00051 { return matrix_->getIndices();}
00052
00053 virtual const CoinBigIndex * getVectorStarts() const
00054 { return matrix_->getVectorStarts();}
00056 virtual const int * getVectorLengths() const
00057 { return matrix_->getVectorLengths();}
00059 virtual int getVectorLength(int index) const
00060 { return matrix_->getVectorSize(index);}
00061
00063 virtual void deleteCols(const int numDel, const int * indDel);
00065 virtual void deleteRows(const int numDel, const int * indDel);
00066 #ifndef CLP_NO_VECTOR
00067
00068 virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
00070 virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
00071 #endif
00072
00076 virtual int appendMatrix(int number, int type,
00077 const CoinBigIndex * starts, const int * index,
00078 const double * element, int numberOther=-1);
00083 virtual void replaceVector(const int index,
00084 const int numReplace, const double * newElements)
00085 {matrix_->replaceVector(index,numReplace,newElements);}
00089 virtual void modifyCoefficient(int row, int column, double newElement,
00090 bool keepZero=false)
00091 {matrix_->modifyCoefficient(row, column, newElement, keepZero);}
00093 virtual ClpMatrixBase * reverseOrderedCopy() const;
00095 virtual CoinBigIndex countBasis(const int * whichColumn,
00096 int & numberColumnBasic);
00098 virtual void fillBasis(ClpSimplex * model,
00099 const int * whichColumn,
00100 int & numberColumnBasic,
00101 int * row, int * start,
00102 int * rowCount, int * columnCount,
00103 CoinFactorizationDouble * element);
00106 virtual int scale(ClpModel * model,const ClpSimplex * baseModel=NULL) const ;
00109 virtual void scaleRowCopy(ClpModel * model) const ;
00111 void createScaledMatrix(ClpSimplex * model) const;
00115 virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
00126 virtual bool allElementsInRange(ClpModel * model,
00127 double smallest, double largest,
00128 int check=15);
00132 virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
00133 double & smallestPositive, double & largestPositive);
00134
00137 virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
00138 int column) const ;
00143 virtual void unpackPacked(ClpSimplex * model,
00144 CoinIndexedVector * rowArray,
00145 int column) const;
00148 virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
00149 int column, double multiplier) const ;
00151 virtual void add(const ClpSimplex * model,double * array,
00152 int column, double multiplier) const;
00154 virtual void releasePackedMatrix() const { }
00159 virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
00161 virtual bool canDoPartialPricing() const;
00163 virtual void partialPricing(ClpSimplex * model, double start, double end,
00164 int & bestSequence, int & numberWanted);
00166 virtual int refresh(ClpSimplex * model);
00167
00168 virtual void reallyScale(const double * rowScale, const double * columnScale);
00174 virtual void setDimensions(int numrows, int numcols);
00176
00182 virtual void times(double scalar,
00183 const double * x, double * y) const;
00185 virtual void times(double scalar,
00186 const double * x, double * y,
00187 const double * rowScale,
00188 const double * columnScale) const;
00192 virtual void transposeTimes(double scalar,
00193 const double * x, double * y) const;
00195 virtual void transposeTimes(double scalar,
00196 const double * x, double * y,
00197 const double * rowScale,
00198 const double * columnScale,
00199 double * spare=NULL) const;
00204 void transposeTimesSubset( int number,
00205 const int * which,
00206 const double * pi, double * y,
00207 const double * rowScale,
00208 const double * columnScale,
00209 double * spare=NULL) const;
00214 virtual void transposeTimes(const ClpSimplex * model, double scalar,
00215 const CoinIndexedVector * x,
00216 CoinIndexedVector * y,
00217 CoinIndexedVector * z) const;
00222 void transposeTimesByColumn(const ClpSimplex * model, double scalar,
00223 const CoinIndexedVector * x,
00224 CoinIndexedVector * y,
00225 CoinIndexedVector * z) const;
00231 virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
00232 const CoinIndexedVector * x,
00233 CoinIndexedVector * y,
00234 CoinIndexedVector * z) const;
00238 virtual void subsetTransposeTimes(const ClpSimplex * model,
00239 const CoinIndexedVector * x,
00240 const CoinIndexedVector * y,
00241 CoinIndexedVector * z) const;
00244 virtual bool canCombine(const ClpSimplex * model,
00245 const CoinIndexedVector * pi) const;
00247 virtual void transposeTimes2(const ClpSimplex * model,
00248 const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
00249 const CoinIndexedVector * pi2,
00250 CoinIndexedVector * spare,
00251 double referenceIn, double devex,
00252
00253 unsigned int * reference,
00254 double * weights, double scaleFactor);
00256 virtual void subsetTimes2(const ClpSimplex * model,
00257 CoinIndexedVector * dj1,
00258 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00259 double referenceIn, double devex,
00260
00261 unsigned int * reference,
00262 double * weights, double scaleFactor);
00264 void useEffectiveRhs(ClpSimplex * model);
00265 #if COIN_LONG_WORK
00266
00267 virtual void times(CoinWorkDouble scalar,
00268 const CoinWorkDouble * x, CoinWorkDouble * y) const ;
00269 virtual void transposeTimes(CoinWorkDouble scalar,
00270 const CoinWorkDouble * x, CoinWorkDouble * y) const ;
00271 #endif
00272
00273
00276
00277 inline CoinPackedMatrix * matrix() const { return matrix_;}
00281 inline void setMatrixNull()
00282 { matrix_=NULL;}
00284 inline void makeSpecialColumnCopy()
00285 { flags_ |= 16;}
00287 void releaseSpecialColumnCopy();
00289 inline bool zeros() const
00290 { return ((flags_&1)!=0);}
00292 inline bool wantsSpecialColumnCopy() const
00293 { return ((flags_&16)!=0);}
00295 inline int flags() const
00296 { return flags_;}
00298 inline void checkGaps()
00299 { flags_ = (matrix_->hasGaps()) ? (flags_|2) : (flags_&(~2));}
00301
00302
00306 ClpPackedMatrix();
00308 virtual ~ClpPackedMatrix();
00310
00314 ClpPackedMatrix(const ClpPackedMatrix&);
00316 ClpPackedMatrix(const CoinPackedMatrix&);
00319 ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
00320 int numberRows, const int * whichRows,
00321 int numberColumns, const int * whichColumns);
00322 ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
00323 int numberRows, const int * whichRows,
00324 int numberColumns, const int * whichColumns);
00325
00327 ClpPackedMatrix(CoinPackedMatrix * matrix);
00328
00329 ClpPackedMatrix& operator=(const ClpPackedMatrix&);
00331 virtual ClpMatrixBase * clone() const ;
00333 virtual void copy(const ClpPackedMatrix * from);
00336 virtual ClpMatrixBase * subsetClone (
00337 int numberRows, const int * whichRows,
00338 int numberColumns, const int * whichColumns) const ;
00340 void specialRowCopy(ClpSimplex * model,const ClpMatrixBase * rowCopy);
00342 void specialColumnCopy(ClpSimplex * model);
00344 virtual void correctSequence(const ClpSimplex * model,int & sequenceIn, int & sequenceOut) ;
00346 private:
00348 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00349 int * COIN_RESTRICT index,
00350 double * COIN_RESTRICT array,
00351 const double tolerance) const;
00353 int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00354 const double * COIN_RESTRICT columnScale,
00355 int * COIN_RESTRICT index,
00356 double * COIN_RESTRICT array,
00357 const double tolerance) const;
00359 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00360 int * COIN_RESTRICT index,
00361 double * COIN_RESTRICT array,
00362 const unsigned char * status,
00363 const double tolerance) const;
00366 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00367 int * COIN_RESTRICT index,
00368 double * COIN_RESTRICT array,
00369 const unsigned char * status,
00370 int * COIN_RESTRICT spareIndex,
00371 double * COIN_RESTRICT spareArray,
00372 const double * COIN_RESTRICT reducedCost,
00373 double & upperTheta,
00374 double & bestPossible,
00375 double acceptablePivot,
00376 double dualTolerance,
00377 int & numberRemaining,
00378 const double zeroTolerance) const;
00380 int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00381 const double * COIN_RESTRICT columnScale,
00382 int * COIN_RESTRICT index,
00383 double * COIN_RESTRICT array,
00384 const unsigned char * status,
00385 const double tolerance) const;
00387 int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
00388 int * COIN_RESTRICT index,
00389 double * COIN_RESTRICT output,
00390 int numberColumns,
00391 const double tolerance,
00392 const double scalar) const;
00394 int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
00395 int * COIN_RESTRICT index,
00396 double * COIN_RESTRICT output,
00397 int * COIN_RESTRICT lookup,
00398 char * COIN_RESTRICT marked,
00399 const double tolerance,
00400 const double scalar) const;
00402 void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00403 CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00405 void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00406 const double tolerance, const double scalar) const;
00408 void clearCopies();
00409
00410
00411 protected:
00413 void checkFlags(int type) const;
00417
00418 CoinPackedMatrix * matrix_;
00420 int numberActiveColumns_;
00428 int flags_;
00430 ClpPackedMatrix2 * rowCopy_;
00432 ClpPackedMatrix3 * columnCopy_;
00434 };
00435 #ifdef THREAD
00436 #include <pthread.h>
00437 typedef struct {
00438 double acceptablePivot;
00439 const ClpSimplex * model;
00440 double * spare;
00441 int * spareIndex;
00442 double * arrayTemp;
00443 int * indexTemp;
00444 int * numberInPtr;
00445 double * bestPossiblePtr;
00446 double * upperThetaPtr;
00447 int * posFreePtr;
00448 double * freePivotPtr;
00449 int * numberOutPtr;
00450 const unsigned short * count;
00451 const double * pi;
00452 const CoinBigIndex * rowStart;
00453 const double * element;
00454 const unsigned short * column;
00455 int offset;
00456 int numberInRowArray;
00457 int numberLook;
00458 } dualColumn0Struct;
00459 #endif
00460 class ClpPackedMatrix2 {
00461
00462 public:
00468 void transposeTimes(const ClpSimplex * model,
00469 const CoinPackedMatrix * rowCopy,
00470 const CoinIndexedVector * x,
00471 CoinIndexedVector * spareArray,
00472 CoinIndexedVector * z) const;
00474 inline bool usefulInfo() const
00475 { return rowStart_!=NULL;}
00477
00478
00482 ClpPackedMatrix2();
00484 ClpPackedMatrix2(ClpSimplex * model,const CoinPackedMatrix * rowCopy);
00486 virtual ~ClpPackedMatrix2();
00488
00492 ClpPackedMatrix2(const ClpPackedMatrix2&);
00493 ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
00495
00496
00497 protected:
00501
00502 int numberBlocks_;
00504 int numberRows_;
00506 int * offset_;
00508 mutable unsigned short * count_;
00510 mutable CoinBigIndex * rowStart_;
00512 unsigned short * column_;
00514 double * work_;
00515 #ifdef THREAD
00516 pthread_t * threadId_;
00517 dualColumn0Struct * info_;
00518 #endif
00519
00520 };
00521 typedef struct {
00522 CoinBigIndex startElements_;
00523 int startIndices_;
00524 int numberInBlock_;
00525 int numberPrice_;
00526 int numberElements_;
00527 } blockStruct;
00528 class ClpPackedMatrix3 {
00529
00530 public:
00536 void transposeTimes(const ClpSimplex * model,
00537 const double * pi,
00538 CoinIndexedVector * output) const;
00540 void transposeTimes2(const ClpSimplex * model,
00541 const double * pi, CoinIndexedVector * dj1,
00542 const double * piWeight,
00543 double referenceIn, double devex,
00544
00545 unsigned int * reference,
00546 double * weights, double scaleFactor);
00548
00549
00553 ClpPackedMatrix3();
00555 ClpPackedMatrix3(ClpSimplex * model,const CoinPackedMatrix * columnCopy);
00557 virtual ~ClpPackedMatrix3();
00559
00563 ClpPackedMatrix3(const ClpPackedMatrix3&);
00564 ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
00566
00569 void sortBlocks(const ClpSimplex * model);
00571 void swapOne(const ClpSimplex * model,const ClpPackedMatrix * matrix,
00572 int iColumn);
00574
00575
00576 protected:
00580
00581 int numberBlocks_;
00583 int numberColumns_;
00585 int * column_;
00587 CoinBigIndex * start_;
00589 int * row_;
00591 double * element_;
00593 blockStruct * block_;
00595 };
00596
00597 #endif