00001
00002
00003 #ifndef ClpPackedMatrix_H
00004 #define ClpPackedMatrix_H
00005
00006 #include "CoinPragma.hpp"
00007
00008 #include "ClpMatrixBase.hpp"
00009
00016 class ClpPackedMatrix2;
00017 class ClpPackedMatrix3;
00018 class ClpPackedMatrix : public ClpMatrixBase {
00019
00020 public:
00023
00024 virtual CoinPackedMatrix * getPackedMatrix() const { return matrix_;}
00026 virtual bool isColOrdered() const { return matrix_->isColOrdered(); }
00028 virtual CoinBigIndex getNumElements() const
00029 { return matrix_->getNumElements(); }
00031 virtual int getNumCols() const { return matrix_->getNumCols(); }
00033 virtual int getNumRows() const { return matrix_->getNumRows(); }
00034
00039 virtual const double * getElements() const
00040 { return matrix_->getElements();}
00042 inline double * getMutableElements() const
00043 { return matrix_->getMutableElements();}
00049 virtual const int * getIndices() const
00050 { return matrix_->getIndices();}
00051
00052 virtual const CoinBigIndex * getVectorStarts() const
00053 { return matrix_->getVectorStarts();}
00055 virtual const int * getVectorLengths() const
00056 { return matrix_->getVectorLengths();}
00058 virtual int getVectorLength(int index) const
00059 { return matrix_->getVectorSize(index);}
00060
00062 virtual void deleteCols(const int numDel, const int * indDel);
00064 virtual void deleteRows(const int numDel, const int * indDel);
00065 #ifndef CLP_NO_VECTOR
00067 virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
00069 virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
00070 #endif
00071
00075 virtual int appendMatrix(int number, int type,
00076 const CoinBigIndex * starts, const int * index,
00077 const double * element, int numberOther=-1);
00082 virtual void replaceVector(const int index,
00083 const int numReplace, const double * newElements)
00084 {matrix_->replaceVector(index,numReplace,newElements);}
00088 virtual void modifyCoefficient(int row, int column, double newElement,
00089 bool keepZero=false)
00090 {matrix_->modifyCoefficient(row, column, newElement, keepZero);}
00092 virtual ClpMatrixBase * reverseOrderedCopy() const;
00094 virtual CoinBigIndex countBasis(ClpSimplex * model,
00095 const int * whichColumn,
00096 int numberRowBasic,
00097 int & numberColumnBasic);
00099 virtual void fillBasis(ClpSimplex * model,
00100 const int * whichColumn,
00101 int & numberColumnBasic,
00102 int * row, int * start,
00103 int * rowCount, int * columnCount,
00104 CoinFactorizationDouble * element);
00107 virtual int scale(ClpModel * model,const ClpSimplex * baseModel=NULL) const ;
00110 virtual void scaleRowCopy(ClpModel * model) const ;
00112 void createScaledMatrix(ClpSimplex * model) const;
00116 virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
00127 virtual bool allElementsInRange(ClpModel * model,
00128 double smallest, double largest,
00129 int check=15);
00133 virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
00134 double & smallestPositive, double & largestPositive);
00135
00138 virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
00139 int column) const ;
00144 virtual void unpackPacked(ClpSimplex * model,
00145 CoinIndexedVector * rowArray,
00146 int column) const;
00149 virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
00150 int column, double multiplier) const ;
00152 virtual void add(const ClpSimplex * model,double * array,
00153 int column, double multiplier) const;
00155 virtual void releasePackedMatrix() const { }
00160 virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
00162 virtual bool canDoPartialPricing() const;
00164 virtual void partialPricing(ClpSimplex * model, double start, double end,
00165 int & bestSequence, int & numberWanted);
00167 virtual int refresh(ClpSimplex * model);
00168
00169 virtual void reallyScale(const double * rowScale, const double * columnScale);
00175 virtual void setDimensions(int numrows, int numcols);
00177
00183 virtual void times(double scalar,
00184 const double * x, double * y) const;
00186 virtual void times(double scalar,
00187 const double * x, double * y,
00188 const double * rowScale,
00189 const double * columnScale) const;
00193 virtual void transposeTimes(double scalar,
00194 const double * x, double * y) const;
00196 virtual void transposeTimes(double scalar,
00197 const double * x, double * y,
00198 const double * rowScale,
00199 const double * columnScale,
00200 double * spare=NULL) const;
00205 void transposeTimesSubset( int number,
00206 const int * which,
00207 const double * pi, double * y,
00208 const double * rowScale,
00209 const double * columnScale,
00210 double * spare=NULL) const;
00215 virtual void transposeTimes(const ClpSimplex * model, double scalar,
00216 const CoinIndexedVector * x,
00217 CoinIndexedVector * y,
00218 CoinIndexedVector * z) const;
00223 void transposeTimesByColumn(const ClpSimplex * model, double scalar,
00224 const CoinIndexedVector * x,
00225 CoinIndexedVector * y,
00226 CoinIndexedVector * z) const;
00232 virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
00233 const CoinIndexedVector * x,
00234 CoinIndexedVector * y,
00235 CoinIndexedVector * z) const;
00239 virtual void subsetTransposeTimes(const ClpSimplex * model,
00240 const CoinIndexedVector * x,
00241 const CoinIndexedVector * y,
00242 CoinIndexedVector * z) const;
00245 virtual bool canCombine(const ClpSimplex * model,
00246 const CoinIndexedVector * pi) const;
00248 virtual void transposeTimes2(const ClpSimplex * model,
00249 const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
00250 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00251 CoinIndexedVector * spare,
00252 double referenceIn, double devex,
00253
00254 unsigned int * reference,
00255 double * weights, double scaleFactor);
00257 virtual void subsetTimes2(const ClpSimplex * model,
00258 CoinIndexedVector * dj1,
00259 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00260 double referenceIn, double devex,
00261
00262 unsigned int * reference,
00263 double * weights, double scaleFactor);
00265 void useEffectiveRhs(ClpSimplex * model);
00267
00270
00271 inline CoinPackedMatrix * matrix() const { return matrix_;}
00275 inline void setMatrixNull()
00276 { matrix_=NULL;}
00278 inline void makeSpecialColumnCopy()
00279 { flags_ |= 16;}
00281 void releaseSpecialColumnCopy();
00283 inline bool zeros() const
00284 { return ((flags_&1)!=0);}
00286 inline bool wantsSpecialColumnCopy() const
00287 { return ((flags_&16)!=0);}
00289 inline int flags() const
00290 { return flags_;}
00292 inline void checkGaps()
00293 { flags_ = (matrix_->hasGaps()) ? (flags_|2) : (flags_&(~2));}
00295
00296
00300 ClpPackedMatrix();
00302 virtual ~ClpPackedMatrix();
00304
00308 ClpPackedMatrix(const ClpPackedMatrix&);
00310 ClpPackedMatrix(const CoinPackedMatrix&);
00313 ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
00314 int numberRows, const int * whichRows,
00315 int numberColumns, const int * whichColumns);
00316 ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
00317 int numberRows, const int * whichRows,
00318 int numberColumns, const int * whichColumns);
00319
00321 ClpPackedMatrix(CoinPackedMatrix * matrix);
00322
00323 ClpPackedMatrix& operator=(const ClpPackedMatrix&);
00325 virtual ClpMatrixBase * clone() const ;
00327 virtual void copy(const ClpPackedMatrix * from);
00330 virtual ClpMatrixBase * subsetClone (
00331 int numberRows, const int * whichRows,
00332 int numberColumns, const int * whichColumns) const ;
00334 void specialRowCopy(ClpSimplex * model,const ClpMatrixBase * rowCopy);
00336 void specialColumnCopy(ClpSimplex * model);
00338 virtual void correctSequence(const ClpSimplex * model,int & sequenceIn, int & sequenceOut) ;
00340 private:
00342 int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00343 int * COIN_RESTRICT index,
00344 double * COIN_RESTRICT array,
00345 const double tolerance) const;
00347 int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00348 const double * COIN_RESTRICT columnScale,
00349 int * COIN_RESTRICT index,
00350 double * COIN_RESTRICT array,
00351 const double tolerance) const;
00353 int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
00354 int * COIN_RESTRICT index,
00355 double * COIN_RESTRICT output,
00356 int numberColumns,
00357 const double tolerance,
00358 const double scalar) const;
00360 int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
00361 int * COIN_RESTRICT index,
00362 double * COIN_RESTRICT output,
00363 int * COIN_RESTRICT lookup,
00364 char * COIN_RESTRICT marked,
00365 const double tolerance,
00366 const double scalar) const;
00368 void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00369 CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00371 void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00372 const double tolerance, const double scalar) const;
00374 void clearCopies();
00375
00376
00377 protected:
00379 void checkFlags(int type) const;
00383
00384 CoinPackedMatrix * matrix_;
00386 int numberActiveColumns_;
00394 int flags_;
00396 ClpPackedMatrix2 * rowCopy_;
00398 ClpPackedMatrix3 * columnCopy_;
00400 };
00401 #ifdef THREAD
00402 #include <pthread.h>
00403 typedef struct {
00404 double acceptablePivot;
00405 const ClpSimplex * model;
00406 double * spare;
00407 int * spareIndex;
00408 double * arrayTemp;
00409 int * indexTemp;
00410 int * numberInPtr;
00411 double * bestPossiblePtr;
00412 double * upperThetaPtr;
00413 int * posFreePtr;
00414 double * freePivotPtr;
00415 int * numberOutPtr;
00416 const unsigned short * count;
00417 const double * pi;
00418 const CoinBigIndex * rowStart;
00419 const double * element;
00420 const unsigned short * column;
00421 int offset;
00422 int numberInRowArray;
00423 int numberLook;
00424 } dualColumn0Struct;
00425 #endif
00426 class ClpPackedMatrix2 {
00427
00428 public:
00434 void transposeTimes(const ClpSimplex * model,
00435 const CoinPackedMatrix * rowCopy,
00436 const CoinIndexedVector * x,
00437 CoinIndexedVector * spareArray,
00438 CoinIndexedVector * z) const;
00440 inline bool usefulInfo() const
00441 { return rowStart_!=NULL;}
00443
00444
00448 ClpPackedMatrix2();
00450 ClpPackedMatrix2(ClpSimplex * model,const CoinPackedMatrix * rowCopy);
00452 virtual ~ClpPackedMatrix2();
00454
00458 ClpPackedMatrix2(const ClpPackedMatrix2&);
00459 ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
00461
00462
00463 protected:
00467
00468 int numberBlocks_;
00470 int numberRows_;
00472 int * offset_;
00474 mutable unsigned short * count_;
00476 mutable CoinBigIndex * rowStart_;
00478 unsigned short * column_;
00480 double * work_;
00481 #ifdef THREAD
00482 pthread_t * threadId_;
00483 dualColumn0Struct * info_;
00484 #endif
00485
00486 };
00487 typedef struct {
00488 CoinBigIndex startElements_;
00489 int startIndices_;
00490 int numberInBlock_;
00491 int numberPrice_;
00492 int numberElements_;
00493 } blockStruct;
00494 class ClpPackedMatrix3 {
00495
00496 public:
00502 void transposeTimes(const ClpSimplex * model,
00503 const double * pi,
00504 CoinIndexedVector * output) const;
00506 void transposeTimes2(const ClpSimplex * model,
00507 const double * pi, CoinIndexedVector * dj1,
00508 const double * piWeight,
00509 double referenceIn, double devex,
00510
00511 unsigned int * reference,
00512 double * weights, double scaleFactor);
00514
00515
00519 ClpPackedMatrix3();
00521 ClpPackedMatrix3(ClpSimplex * model,const CoinPackedMatrix * columnCopy);
00523 virtual ~ClpPackedMatrix3();
00525
00529 ClpPackedMatrix3(const ClpPackedMatrix3&);
00530 ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
00532
00535 void sortBlocks(const ClpSimplex * model);
00537 void swapOne(const ClpSimplex * model,const ClpPackedMatrix * matrix,
00538 int iColumn);
00540
00541
00542 protected:
00546
00547 int numberBlocks_;
00549 int numberColumns_;
00551 int * column_;
00553 CoinBigIndex * start_;
00555 int * row_;
00557 double * element_;
00559 blockStruct * block_;
00561 };
00562
00563 #endif