/home/coin/SVN-release/Bcp-1.2.1/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();}
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   // Really scale matrix
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                                // Array for exact devex to say what is in reference framework
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                                // Array for exact devex to say what is in reference framework
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   inline int flags() const
00280   { return flags_;}
00282 
00283 
00287    ClpPackedMatrix();
00289    virtual ~ClpPackedMatrix();
00291 
00295    ClpPackedMatrix(const ClpPackedMatrix&);
00297    ClpPackedMatrix(const CoinPackedMatrix&);
00300   ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
00301                     int numberRows, const int * whichRows,
00302                     int numberColumns, const int * whichColumns);
00303   ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
00304                     int numberRows, const int * whichRows,
00305                     int numberColumns, const int * whichColumns);
00306 
00308    ClpPackedMatrix(CoinPackedMatrix * matrix);
00309 
00310    ClpPackedMatrix& operator=(const ClpPackedMatrix&);
00312   virtual ClpMatrixBase * clone() const ;
00314   virtual void copy(const ClpPackedMatrix * from);
00317   virtual ClpMatrixBase * subsetClone (
00318                     int numberRows, const int * whichRows,
00319                     int numberColumns, const int * whichColumns) const ;
00321   void specialRowCopy(ClpSimplex * model,const ClpMatrixBase * rowCopy); 
00323   void specialColumnCopy(ClpSimplex * model); 
00325   virtual void correctSequence(const ClpSimplex * model,int & sequenceIn, int & sequenceOut) ;
00327 private:
00329   int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
00330                                     int * COIN_RESTRICT index, 
00331                                     double * COIN_RESTRICT array,
00332                                     const double tolerance) const;
00334   int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
00335                                  const double * COIN_RESTRICT columnScale,
00336                                  int * COIN_RESTRICT index, 
00337                                  double * COIN_RESTRICT array,
00338                                  const double tolerance) const;
00340   int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector, 
00341                                    int * COIN_RESTRICT index, 
00342                                    double * COIN_RESTRICT output,
00343                                    int * COIN_RESTRICT lookup,
00344                                    char * COIN_RESTRICT marked,
00345                                    const double tolerance, 
00346                                    const double scalar) const;
00348   void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00349                                    CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
00351   void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
00352                                    const double tolerance, const double scalar) const;
00354   void clearCopies();
00355    
00356     
00357 protected:
00359   void checkFlags(int type) const;
00363 
00364   CoinPackedMatrix * matrix_;
00366   int numberActiveColumns_;
00373   int flags_;
00375   ClpPackedMatrix2 * rowCopy_;
00377   ClpPackedMatrix3 * columnCopy_;
00379 };
00380 #ifdef THREAD
00381 #include <pthread.h>
00382 typedef struct {
00383   double acceptablePivot;
00384   const ClpSimplex * model;
00385   double * spare;
00386   int * spareIndex;
00387   double * arrayTemp;
00388   int * indexTemp;
00389   int * numberInPtr;
00390   double * bestPossiblePtr;
00391   double * upperThetaPtr;
00392   int * posFreePtr;
00393   double * freePivotPtr;
00394   int * numberOutPtr;
00395   const unsigned short * count;
00396   const double * pi;
00397   const CoinBigIndex * rowStart;
00398   const double * element;
00399   const unsigned short * column;
00400   int offset;
00401   int numberInRowArray;
00402   int numberLook;
00403 } dualColumn0Struct;
00404 #endif
00405 class ClpPackedMatrix2 {
00406   
00407 public:
00413   void transposeTimes(const ClpSimplex * model,
00414                       const CoinPackedMatrix * rowCopy,
00415                       const CoinIndexedVector * x,
00416                       CoinIndexedVector * spareArray,
00417                       CoinIndexedVector * z) const;
00419   inline bool usefulInfo() const
00420   { return rowStart_!=NULL;}
00422 
00423 
00427    ClpPackedMatrix2();
00429    ClpPackedMatrix2(ClpSimplex * model,const CoinPackedMatrix * rowCopy);
00431    virtual ~ClpPackedMatrix2();
00433 
00437    ClpPackedMatrix2(const ClpPackedMatrix2&);
00438    ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
00440    
00441     
00442 protected:
00446 
00447   int numberBlocks_;
00449   int numberRows_;
00451   int * offset_;
00453   mutable unsigned short * count_;
00455   mutable CoinBigIndex * rowStart_;
00457   unsigned short * column_;
00459   double * work_;
00460 #ifdef THREAD
00461   pthread_t * threadId_;
00462   dualColumn0Struct * info_;
00463 #endif
00464 
00465 };
00466 typedef struct {
00467   CoinBigIndex startElements_; // point to data
00468   int startIndices_; // point to column_
00469   int numberInBlock_; 
00470   int numberPrice_; // at beginning
00471   int numberElements_; // number elements per column
00472 } blockStruct;
00473 class ClpPackedMatrix3 {
00474   
00475 public:
00481   void transposeTimes(const ClpSimplex * model,
00482                       const double * pi,
00483                       CoinIndexedVector * output) const;
00485   void transposeTimes2(const ClpSimplex * model,
00486                        const double * pi, CoinIndexedVector * dj1,
00487                        const double * piWeight,
00488                        double referenceIn, double devex,
00489                        // Array for exact devex to say what is in reference framework
00490                        unsigned int * reference,
00491                        double * weights, double scaleFactor);
00493 
00494 
00498    ClpPackedMatrix3();
00500    ClpPackedMatrix3(ClpSimplex * model,const CoinPackedMatrix * columnCopy);
00502    virtual ~ClpPackedMatrix3();
00504 
00508    ClpPackedMatrix3(const ClpPackedMatrix3&);
00509    ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
00511 
00514   void sortBlocks(const ClpSimplex * model);
00516   void swapOne(const ClpSimplex * model,const ClpPackedMatrix * matrix,
00517                 int iColumn);
00519    
00520     
00521 protected:
00525 
00526   int numberBlocks_;
00528   int numberColumns_;
00530   int * column_;
00532   CoinBigIndex * start_;
00534   int * row_;
00536   double * element_;
00538   blockStruct * block_;
00540 };
00541 
00542 #endif

Generated on Thu Jan 15 03:01:00 2009 for coin-Bcp by  doxygen 1.4.7