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 double * 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 virtual void transposeTimes(const ClpSimplex * model, double scalar,
00206 const CoinIndexedVector * x,
00207 CoinIndexedVector * y,
00208 CoinIndexedVector * z) const;
00213 void transposeTimesByColumn(const ClpSimplex * model, double scalar,
00214 const CoinIndexedVector * x,
00215 CoinIndexedVector * y,
00216 CoinIndexedVector * z) const;
00222 virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
00223 const CoinIndexedVector * x,
00224 CoinIndexedVector * y,
00225 CoinIndexedVector * z) const;
00229 virtual void subsetTransposeTimes(const ClpSimplex * model,
00230 const CoinIndexedVector * x,
00231 const CoinIndexedVector * y,
00232 CoinIndexedVector * z) const;
00235 virtual bool canCombine(const ClpSimplex * model,
00236 const CoinIndexedVector * pi) const;
00238 virtual void transposeTimes2(const ClpSimplex * model,
00239 const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
00240 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00241 CoinIndexedVector * spare,
00242 double referenceIn, double devex,
00243
00244 unsigned int * reference,
00245 double * weights, double scaleFactor);
00247 virtual void subsetTimes2(const ClpSimplex * model,
00248 CoinIndexedVector * dj1,
00249 const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
00250 double referenceIn, double devex,
00251
00252 unsigned int * reference,
00253 double * weights, double scaleFactor);
00255 void useEffectiveRhs(ClpSimplex * model);
00257
00260
00261 inline CoinPackedMatrix * matrix() const { return matrix_;}
00265 inline void setMatrixNull()
00266 { matrix_=NULL;}
00268 inline void makeSpecialColumnCopy()
00269 { flags_ |= 8;}
00271 void releaseSpecialColumnCopy();
00273 inline bool zeros() const
00274 { return ((flags_&1)!=0);}
00276 inline bool wantsSpecialColumnCopy() const
00277 { return ((flags_&8)!=0);}
00279
00280
00284 ClpPackedMatrix();
00286 virtual ~ClpPackedMatrix();
00288
00292 ClpPackedMatrix(const ClpPackedMatrix&);
00294 ClpPackedMatrix(const CoinPackedMatrix&);
00297 ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
00298 int numberRows, const int * whichRows,
00299 int numberColumns, const int * whichColumns);
00300 ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
00301 int numberRows, const int * whichRows,
00302 int numberColumns, const int * whichColumns);
00303
00305 ClpPackedMatrix(CoinPackedMatrix * matrix);
00306
00307 ClpPackedMatrix& operator=(const ClpPackedMatrix&);
00309 virtual ClpMatrixBase * clone() const ;
00311 virtual void copy(const ClpPackedMatrix * from);
00314 virtual ClpMatrixBase * subsetClone (
00315 int numberRows, const int * whichRows,
00316 int numberColumns, const int * whichColumns) const ;
00318 void specialRowCopy(ClpSimplex * model,const ClpMatrixBase * rowCopy);
00320 void specialColumnCopy(ClpSimplex * model);
00322 virtual void correctSequence(const ClpSimplex * model,int & sequenceIn, int & sequenceOut) ;
00324 private:
00326 void gutsOfTransposeTimesUnscaled(const double * pi,CoinIndexedVector * output, const double tolerance) const;
00328 void gutsOfTransposeTimesScaled(const double * pi,const double * columnScale, CoinIndexedVector * output, const double tolerance) const;
00330 void gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00331 CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00333 void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00334 CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00336 void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00337 const double tolerance, const double scalar) const;
00339 void clearCopies();
00340
00341
00342 protected:
00344 void checkFlags() const;
00348
00349 CoinPackedMatrix * matrix_;
00351 int numberActiveColumns_;
00358 int flags_;
00360 ClpPackedMatrix2 * rowCopy_;
00362 ClpPackedMatrix3 * columnCopy_;
00364 };
00365 #ifdef THREAD
00366 #include <pthread.h>
00367 typedef struct {
00368 double acceptablePivot;
00369 const ClpSimplex * model;
00370 double * spare;
00371 int * spareIndex;
00372 double * arrayTemp;
00373 int * indexTemp;
00374 int * numberInPtr;
00375 double * bestPossiblePtr;
00376 double * upperThetaPtr;
00377 int * posFreePtr;
00378 double * freePivotPtr;
00379 int * numberOutPtr;
00380 const unsigned short * count;
00381 const double * pi;
00382 const CoinBigIndex * rowStart;
00383 const double * element;
00384 const unsigned short * column;
00385 int offset;
00386 int numberInRowArray;
00387 int numberLook;
00388 } dualColumn0Struct;
00389 #endif
00390 class ClpPackedMatrix2 {
00391
00392 public:
00398 void transposeTimes(const ClpSimplex * model,
00399 const CoinPackedMatrix * rowCopy,
00400 const CoinIndexedVector * x,
00401 CoinIndexedVector * spareArray,
00402 CoinIndexedVector * z) const;
00404 inline bool usefulInfo() const
00405 { return rowStart_!=NULL;}
00407
00408
00412 ClpPackedMatrix2();
00414 ClpPackedMatrix2(ClpSimplex * model,const CoinPackedMatrix * rowCopy);
00416 virtual ~ClpPackedMatrix2();
00418
00422 ClpPackedMatrix2(const ClpPackedMatrix2&);
00423 ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
00425
00426
00427 protected:
00431
00432 int numberBlocks_;
00434 int numberRows_;
00436 int * offset_;
00438 mutable unsigned short * count_;
00440 mutable CoinBigIndex * rowStart_;
00442 unsigned short * column_;
00444 double * work_;
00445 #ifdef THREAD
00446 pthread_t * threadId_;
00447 dualColumn0Struct * info_;
00448 #endif
00449
00450 };
00451 typedef struct {
00452 CoinBigIndex startElements_;
00453 int startIndices_;
00454 int numberInBlock_;
00455 int numberPrice_;
00456 int numberElements_;
00457 } blockStruct;
00458 class ClpPackedMatrix3 {
00459
00460 public:
00466 void transposeTimes(const ClpSimplex * model,
00467 const double * pi,
00468 CoinIndexedVector * output) const;
00470 void transposeTimes2(const ClpSimplex * model,
00471 const double * pi, CoinIndexedVector * dj1,
00472 const double * piWeight,
00473 double referenceIn, double devex,
00474
00475 unsigned int * reference,
00476 double * weights, double scaleFactor);
00478
00479
00483 ClpPackedMatrix3();
00485 ClpPackedMatrix3(ClpSimplex * model,const CoinPackedMatrix * columnCopy);
00487 virtual ~ClpPackedMatrix3();
00489
00493 ClpPackedMatrix3(const ClpPackedMatrix3&);
00494 ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
00496
00499 void sortBlocks(const ClpSimplex * model);
00501 void swapOne(const ClpSimplex * model,const ClpPackedMatrix * matrix,
00502 int iColumn);
00504
00505
00506 protected:
00510
00511 int numberBlocks_;
00513 int numberColumns_;
00515 int * column_;
00517 CoinBigIndex * start_;
00519 int * row_;
00521 double * element_;
00523 blockStruct * block_;
00525 };
00526
00527 #endif