- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Clp-1.5.0/Clp/src/ClpPackedMatrix.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2002, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    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();}
    00046    virtual const int * getIndices() const
    00047   { return matrix_->getIndices();}
    00048
    00049    virtual const CoinBigIndex * getVectorStarts() const
    00050   { return matrix_->getVectorStarts();}
    00052    virtual const int * getVectorLengths() const
    00053   { return matrix_->getVectorLengths();}
    00055   virtual int getVectorLength(int index) const
    00056   { return matrix_->getVectorSize(index);}
    00057
    00059   virtual void deleteCols(const int numDel, const int * indDel);
    00061   virtual void deleteRows(const int numDel, const int * indDel);
    00062 #ifndef CLP_NO_VECTOR
    00064   virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
    00066   virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
    00067 #endif
    00068
    00072   virtual int appendMatrix(int number, int type,
    00073                            const CoinBigIndex * starts, const int * index,
    00074                            const double * element, int numberOther=-1);
    00079   virtual void replaceVector(const int index,
    00080                        const int numReplace, const double * newElements)
    00081       {matrix_->replaceVector(index,numReplace,newElements);}
    00085   virtual void modifyCoefficient(int row, int column, double newElement,
    00086                            bool keepZero=false)
    00087        {matrix_->modifyCoefficient(row, column, newElement, keepZero);}
    00089   virtual ClpMatrixBase * reverseOrderedCopy() const;
    00091   virtual CoinBigIndex countBasis(ClpSimplex * model,
    00092                                  const int * whichColumn,
    00093                                  int numberRowBasic,
    00094                                   int & numberColumnBasic);
    00096   virtual void fillBasis(ClpSimplex * model,
    00097                                  const int * whichColumn,
    00098                                  int & numberColumnBasic,
    00099                                  int * row, int * start,
    00100                                  int * rowCount, int * columnCount,
    00101                                  double * element);
    00104   virtual int scale(ClpModel * model) const ;
    00107   virtual void scaleRowCopy(ClpModel * model) const ;
    00111   virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
    00122   virtual bool allElementsInRange(ClpModel * model,
    00123                                   double smallest, double largest,
    00124                                   int check=15);
    00128   virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
    00129                        double & smallestPositive, double & largestPositive);
    00130
    00133   virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
    00134                    int column) const ;
    00139   virtual void unpackPacked(ClpSimplex * model,
    00140                             CoinIndexedVector * rowArray,
    00141                             int column) const;
    00144   virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
    00145                    int column, double multiplier) const ;
    00147   virtual void add(const ClpSimplex * model,double * array,
    00148                    int column, double multiplier) const;
    00150    virtual void releasePackedMatrix() const { }
    00155   virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
    00157   virtual bool canDoPartialPricing() const;
    00159   virtual void partialPricing(ClpSimplex * model, double start, double end,
    00160                       int & bestSequence, int & numberWanted);
    00162   virtual int refresh(ClpSimplex * model);
    00163   // Really scale matrix
    00164   virtual void reallyScale(const double * rowScale, const double * columnScale);
    00170   virtual void setDimensions(int numrows, int numcols);
    00172
    00178   virtual void times(double scalar,
    00179                        const double * x, double * y) const;
    00181   virtual void times(double scalar,
    00182                      const double * x, double * y,
    00183                      const double * rowScale,
    00184                      const double * columnScale) const;
    00188     virtual void transposeTimes(double scalar,
    00189                                 const double * x, double * y) const;
    00191     virtual void transposeTimes(double scalar,
    00192                                 const double * x, double * y,
    00193                                 const double * rowScale,
    00194                                 const double * columnScale,
    00195                                 double * spare=NULL) const;
    00200   virtual void transposeTimes(const ClpSimplex * model, double scalar,
    00201                               const CoinIndexedVector * x,
    00202                               CoinIndexedVector * y,
    00203                               CoinIndexedVector * z) const;
    00208   void transposeTimesByColumn(const ClpSimplex * model, double scalar,
    00209                               const CoinIndexedVector * x,
    00210                               CoinIndexedVector * y,
    00211                               CoinIndexedVector * z) const;
    00217   virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
    00218                               const CoinIndexedVector * x,
    00219                               CoinIndexedVector * y,
    00220                               CoinIndexedVector * z) const;
    00224   virtual void subsetTransposeTimes(const ClpSimplex * model,
    00225                                     const CoinIndexedVector * x,
    00226                                     const CoinIndexedVector * y,
    00227                                     CoinIndexedVector * z) const;
    00230   virtual bool canCombine(const ClpSimplex * model,
    00231                           const CoinIndexedVector * pi) const;
    00233   virtual void transposeTimes2(const ClpSimplex * model,
    00234                                const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
    00235                                const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
    00236                                CoinIndexedVector * spare,
    00237                                double referenceIn, double devex,
    00238                                // Array for exact devex to say what is in reference framework
    00239                                unsigned int * reference,
    00240                                double * weights, double scaleFactor);
    00242   virtual void subsetTimes2(const ClpSimplex * model,
    00243                                 CoinIndexedVector * dj1,
    00244                                const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
    00245                                double referenceIn, double devex,
    00246                                // Array for exact devex to say what is in reference framework
    00247                                unsigned int * reference,
    00248                                double * weights, double scaleFactor);
    00250   void useEffectiveRhs(ClpSimplex * model);
    00252
    00255
    00256   inline CoinPackedMatrix * matrix() const { return matrix_;}
    00260   inline void setMatrixNull()
    00261   { matrix_=NULL;}
    00263   inline void makeSpecialColumnCopy()
    00264   { flags_ |= 8;}
    00266   void releaseSpecialColumnCopy();
    00268   inline bool zeros() const
    00269   { return ((flags_&1)!=0);}
    00271   inline bool wantsSpecialColumnCopy() const
    00272   { return ((flags_&8)!=0);}
    00274
    00275
    00279    ClpPackedMatrix();
    00281    virtual ~ClpPackedMatrix();
    00283
    00287    ClpPackedMatrix(const ClpPackedMatrix&);
    00289    ClpPackedMatrix(const CoinPackedMatrix&);
    00292   ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
    00293                     int numberRows, const int * whichRows,
    00294                     int numberColumns, const int * whichColumns);
    00295   ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
    00296                     int numberRows, const int * whichRows,
    00297                     int numberColumns, const int * whichColumns);
    00298
    00300    ClpPackedMatrix(CoinPackedMatrix * matrix);
    00301
    00302    ClpPackedMatrix& operator=(const ClpPackedMatrix&);
    00304   virtual ClpMatrixBase * clone() const ;
    00307   virtual ClpMatrixBase * subsetClone (
    00308                     int numberRows, const int * whichRows,
    00309                     int numberColumns, const int * whichColumns) const ;
    00311   void specialRowCopy(ClpSimplex * model,const ClpMatrixBase * rowCopy);
    00313   void specialColumnCopy(ClpSimplex * model);
    00315   virtual void correctSequence(const ClpSimplex * model,int & sequenceIn, int & sequenceOut) ;
    00317 private:
    00319   void gutsOfTransposeTimesUnscaled(const double * pi,CoinIndexedVector * output, const double tolerance) const;
    00321   void gutsOfTransposeTimesScaled(const double * pi,const double * columnScale, CoinIndexedVector * output, const double tolerance) const;
    00323   void gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00324                                    CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
    00326   void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00327                                    CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
    00329   void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00330                                    const double tolerance, const double scalar) const;
    00332   void clearCopies();
    00333
    00334
    00335 protected:
    00337   void checkFlags() const;
    00341
    00342   CoinPackedMatrix * matrix_;
    00344   int numberActiveColumns_;
    00351   int flags_;
    00353   ClpPackedMatrix2 * rowCopy_;
    00355   ClpPackedMatrix3 * columnCopy_;
    00357 };
    00358 #ifdef THREAD
    00359 #include <pthread.h>
    00360 typedef struct {
    00361   double acceptablePivot;
    00362   const ClpSimplex * model;
    00363   double * spare;
    00364   int * spareIndex;
    00365   double * arrayTemp;
    00366   int * indexTemp;
    00367   int * numberInPtr;
    00368   double * bestPossiblePtr;
    00369   double * upperThetaPtr;
    00370   int * posFreePtr;
    00371   double * freePivotPtr;
    00372   int * numberOutPtr;
    00373   const unsigned short * count;
    00374   const double * pi;
    00375   const CoinBigIndex * rowStart;
    00376   const double * element;
    00377   const unsigned short * column;
    00378   int offset;
    00379   int numberInRowArray;
    00380   int numberLook;
    00381 } dualColumn0Struct;
    00382 #endif
    00383 class ClpPackedMatrix2 {
    00384
    00385 public:
    00391   void transposeTimes(const ClpSimplex * model,
    00392                       const CoinPackedMatrix * rowCopy,
    00393                       const CoinIndexedVector * x,
    00394                       CoinIndexedVector * spareArray,
    00395                       CoinIndexedVector * z) const;
    00397   inline bool usefulInfo() const
    00398   { return rowStart_!=NULL;}
    00400
    00401
    00405    ClpPackedMatrix2();
    00407    ClpPackedMatrix2(ClpSimplex * model,const CoinPackedMatrix * rowCopy);
    00409    virtual ~ClpPackedMatrix2();
    00411
    00415    ClpPackedMatrix2(const ClpPackedMatrix2&);
    00416    ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
    00418
    00419
    00420 protected:
    00424
    00425   int numberBlocks_;
    00427   int numberRows_;
    00429   int * offset_;
    00431   mutable unsigned short * count_;
    00433   mutable CoinBigIndex * rowStart_;
    00435   unsigned short * column_;
    00437   double * work_;
    00438 #ifdef THREAD
    00439   pthread_t * threadId_;
    00440   dualColumn0Struct * info_;
    00441 #endif
    00442
    00443 };
    00444 typedef struct {
    00445   CoinBigIndex startElements_; // point to data
    00446   int startIndices_; // point to column_
    00447   int numberInBlock_;
    00448   int numberPrice_; // at beginning
    00449   int numberElements_; // number elements per column
    00450 } blockStruct;
    00451 class ClpPackedMatrix3 {
    00452
    00453 public:
    00459   void transposeTimes(const ClpSimplex * model,
    00460                       const double * pi,
    00461                       CoinIndexedVector * output) const;
    00463   void transposeTimes2(const ClpSimplex * model,
    00464                        const double * pi, CoinIndexedVector * dj1,
    00465                        const double * piWeight,
    00466                        double referenceIn, double devex,
    00467                        // Array for exact devex to say what is in reference framework
    00468                        unsigned int * reference,
    00469                        double * weights, double scaleFactor);
    00471
    00472
    00476    ClpPackedMatrix3();
    00478    ClpPackedMatrix3(ClpSimplex * model,const CoinPackedMatrix * columnCopy);
    00480    virtual ~ClpPackedMatrix3();
    00482
    00486    ClpPackedMatrix3(const ClpPackedMatrix3&);
    00487    ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
    00489
    00492   void sortBlocks(const ClpSimplex * model);
    00494   void swapOne(const ClpSimplex * model,const ClpPackedMatrix * matrix,
    00495                 int iColumn);
    00497
    00498
    00499 protected:
    00503
    00504   int numberBlocks_;
    00506   int numberColumns_;
    00508   int * column_;
    00510   CoinBigIndex * start_;
    00512   int * row_;
    00514   double * element_;
    00516   blockStruct * block_;
    00518 };
    00519
    00520 #endif