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

- File List
- File Members

# /home/coin/svn-release/Alps-1.4.6/Clp/src/ClpPackedMatrix.hpp

Go to the documentation of this file.

    00001 /* $Id: ClpPackedMatrix.hpp 1836 2011-12-15 20:22:39Z lou $ */
    00002 // Copyright (C) 2002, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00005
    00006 #ifndef ClpPackedMatrix_H
    00007 #define ClpPackedMatrix_H
    00008
    00009 #include "CoinPragma.hpp"
    00010
    00011 #include "ClpMatrixBase.hpp"
    00012
    00013 // Compilers can produce better code if they know about __restrict
    00014 #ifndef COIN_RESTRICT
    00015 #ifdef COIN_USE_RESTRICT
    00016 #define COIN_RESTRICT __restrict
    00017 #else
    00018 #define COIN_RESTRICT
    00019 #endif
    00020 #endif
    00021
    00028 class ClpPackedMatrix2;
    00029 class ClpPackedMatrix3;
    00030 class ClpPackedMatrix : public ClpMatrixBase {
    00031
    00032 public:
    00035
    00036      virtual CoinPackedMatrix * getPackedMatrix() const {
    00037           return matrix_;
    00038      }
    00040      virtual bool isColOrdered() const {
    00041           return matrix_->isColOrdered();
    00042      }
    00044      virtual  CoinBigIndex getNumElements() const {
    00045           return matrix_->getNumElements();
    00046      }
    00048      virtual int getNumCols() const {
    00049           return matrix_->getNumCols();
    00050      }
    00052      virtual int getNumRows() const {
    00053           return matrix_->getNumRows();
    00054      }
    00055
    00060      virtual const double * getElements() const {
    00061           return matrix_->getElements();
    00062      }
    00064      inline double * getMutableElements() const {
    00065           return matrix_->getMutableElements();
    00066      }
    00072      virtual const int * getIndices() const {
    00073           return matrix_->getIndices();
    00074      }
    00075
    00076      virtual const CoinBigIndex * getVectorStarts() const {
    00077           return matrix_->getVectorStarts();
    00078      }
    00080      virtual const int * getVectorLengths() const {
    00081           return matrix_->getVectorLengths();
    00082      }
    00084      virtual int getVectorLength(int index) const {
    00085           return matrix_->getVectorSize(index);
    00086      }
    00087
    00089      virtual void deleteCols(const int numDel, const int * indDel);
    00091      virtual void deleteRows(const int numDel, const int * indDel);
    00092 #ifndef CLP_NO_VECTOR
    00094      virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
    00096      virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
    00097 #endif
    00098
    00102      virtual int appendMatrix(int number, int type,
    00103                               const CoinBigIndex * starts, const int * index,
    00104                               const double * element, int numberOther = -1);
    00109      virtual void replaceVector(const int index,
    00110                                 const int numReplace, const double * newElements) {
    00111           matrix_->replaceVector(index, numReplace, newElements);
    00112      }
    00116      virtual void modifyCoefficient(int row, int column, double newElement,
    00117                                     bool keepZero = false) {
    00118           matrix_->modifyCoefficient(row, column, newElement, keepZero);
    00119      }
    00121      virtual ClpMatrixBase * reverseOrderedCopy() const;
    00123      virtual CoinBigIndex countBasis(const int * whichColumn,
    00124                                      int & numberColumnBasic);
    00126      virtual void fillBasis(ClpSimplex * model,
    00127                             const int * whichColumn,
    00128                             int & numberColumnBasic,
    00129                             int * row, int * start,
    00130                             int * rowCount, int * columnCount,
    00131                             CoinFactorizationDouble * element);
    00134      virtual int scale(ClpModel * model, const ClpSimplex * baseModel = NULL) const ;
    00137      virtual void scaleRowCopy(ClpModel * model) const ;
    00139      void createScaledMatrix(ClpSimplex * model) const;
    00143      virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
    00154      virtual bool allElementsInRange(ClpModel * model,
    00155                                      double smallest, double largest,
    00156                                      int check = 15);
    00160      virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
    00161                                   double & smallestPositive, double & largestPositive);
    00162
    00165      virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
    00166                          int column) const ;
    00171      virtual void unpackPacked(ClpSimplex * model,
    00172                                CoinIndexedVector * rowArray,
    00173                                int column) const;
    00176      virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
    00177                       int column, double multiplier) const ;
    00179      virtual void add(const ClpSimplex * model, double * array,
    00180                       int column, double multiplier) const;
    00182      virtual void releasePackedMatrix() const { }
    00187      virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
    00189      virtual bool canDoPartialPricing() const;
    00191      virtual void partialPricing(ClpSimplex * model, double start, double end,
    00192                                  int & bestSequence, int & numberWanted);
    00194      virtual int refresh(ClpSimplex * model);
    00195      // Really scale matrix
    00196      virtual void reallyScale(const double * rowScale, const double * columnScale);
    00202      virtual void setDimensions(int numrows, int numcols);
    00204
    00210      virtual void times(double scalar,
    00211                         const double * x, double * y) const;
    00213      virtual void times(double scalar,
    00214                         const double * x, double * y,
    00215                         const double * rowScale,
    00216                         const double * columnScale) const;
    00220      virtual void transposeTimes(double scalar,
    00221                                  const double * x, double * y) const;
    00223      virtual void transposeTimes(double scalar,
    00224                                  const double * x, double * y,
    00225                                  const double * rowScale,
    00226                                  const double * columnScale,
    00227                                  double * spare = NULL) const;
    00232      void transposeTimesSubset( int number,
    00233                                 const int * which,
    00234                                 const double * pi, double * y,
    00235                                 const double * rowScale,
    00236                                 const double * columnScale,
    00237                                 double * spare = NULL) const;
    00242      virtual void transposeTimes(const ClpSimplex * model, double scalar,
    00243                                  const CoinIndexedVector * x,
    00244                                  CoinIndexedVector * y,
    00245                                  CoinIndexedVector * z) const;
    00250      void transposeTimesByColumn(const ClpSimplex * model, double scalar,
    00251                                  const CoinIndexedVector * x,
    00252                                  CoinIndexedVector * y,
    00253                                  CoinIndexedVector * z) const;
    00259      virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
    00260                                       const CoinIndexedVector * x,
    00261                                       CoinIndexedVector * y,
    00262                                       CoinIndexedVector * z) const;
    00266      virtual void subsetTransposeTimes(const ClpSimplex * model,
    00267                                        const CoinIndexedVector * x,
    00268                                        const CoinIndexedVector * y,
    00269                                        CoinIndexedVector * z) const;
    00272      virtual bool canCombine(const ClpSimplex * model,
    00273                              const CoinIndexedVector * pi) const;
    00275      virtual void transposeTimes2(const ClpSimplex * model,
    00276                                   const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
    00277                                   const CoinIndexedVector * pi2,
    00278                                   CoinIndexedVector * spare,
    00279                                   double referenceIn, double devex,
    00280                                   // Array for exact devex to say what is in reference framework
    00281                                   unsigned int * reference,
    00282                                   double * weights, double scaleFactor);
    00284      virtual void subsetTimes2(const ClpSimplex * model,
    00285                                CoinIndexedVector * dj1,
    00286                                const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
    00287                                double referenceIn, double devex,
    00288                                // Array for exact devex to say what is in reference framework
    00289                                unsigned int * reference,
    00290                                double * weights, double scaleFactor);
    00292      void useEffectiveRhs(ClpSimplex * model);
    00293 #if COIN_LONG_WORK
    00294      // For long double versions
    00295      virtual void times(CoinWorkDouble scalar,
    00296                         const CoinWorkDouble * x, CoinWorkDouble * y) const ;
    00297      virtual void transposeTimes(CoinWorkDouble scalar,
    00298                                  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
    00299 #endif
    00300
    00301
    00304
    00305      inline CoinPackedMatrix * matrix() const {
    00306           return matrix_;
    00307      }
    00311      inline void setMatrixNull() {
    00312           matrix_ = NULL;
    00313      }
    00315      inline void makeSpecialColumnCopy() {
    00316           flags_ |= 16;
    00317      }
    00319      void releaseSpecialColumnCopy();
    00321      inline bool zeros() const {
    00322           return ((flags_ & 1) != 0);
    00323      }
    00325      inline bool wantsSpecialColumnCopy() const {
    00326           return ((flags_ & 16) != 0);
    00327      }
    00329      inline int flags() const {
    00330           return flags_;
    00331      }
    00333      inline void checkGaps() {
    00334           flags_ = (matrix_->hasGaps()) ? (flags_ | 2) : (flags_ & (~2));
    00335      }
    00337      inline int numberActiveColumns() const
    00338      { return numberActiveColumns_;}
    00340      inline void setNumberActiveColumns(int value)
    00341      { numberActiveColumns_ = value;}
    00343
    00344
    00348      ClpPackedMatrix();
    00350      virtual ~ClpPackedMatrix();
    00352
    00356      ClpPackedMatrix(const ClpPackedMatrix&);
    00358      ClpPackedMatrix(const CoinPackedMatrix&);
    00361      ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
    00362                       int numberRows, const int * whichRows,
    00363                       int numberColumns, const int * whichColumns);
    00364      ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
    00365                       int numberRows, const int * whichRows,
    00366                       int numberColumns, const int * whichColumns);
    00367
    00369      ClpPackedMatrix(CoinPackedMatrix * matrix);
    00370
    00371      ClpPackedMatrix& operator=(const ClpPackedMatrix&);
    00373      virtual ClpMatrixBase * clone() const ;
    00375      virtual void copy(const ClpPackedMatrix * from);
    00378      virtual ClpMatrixBase * subsetClone (
    00379           int numberRows, const int * whichRows,
    00380           int numberColumns, const int * whichColumns) const ;
    00382      void specialRowCopy(ClpSimplex * model, const ClpMatrixBase * rowCopy);
    00384      void specialColumnCopy(ClpSimplex * model);
    00386      virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
    00388 private:
    00390      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00391                                       int * COIN_RESTRICT index,
    00392                                       double * COIN_RESTRICT array,
    00393                                       const double tolerance) const;
    00395      int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
    00396                                     const double * COIN_RESTRICT columnScale,
    00397                                     int * COIN_RESTRICT index,
    00398                                     double * COIN_RESTRICT array,
    00399                                     const double tolerance) const;
    00401      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00402                                       int * COIN_RESTRICT index,
    00403                                       double * COIN_RESTRICT array,
    00404                                       const unsigned char * status,
    00405                                       const double tolerance) const;
    00408      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00409                                       int * COIN_RESTRICT index,
    00410                                       double * COIN_RESTRICT array,
    00411                                       const unsigned char * status,
    00412                                       int * COIN_RESTRICT spareIndex,
    00413                                       double * COIN_RESTRICT spareArray,
    00414                                       const double * COIN_RESTRICT reducedCost,
    00415                                       double & upperTheta,
    00416                                       double & bestPossible,
    00417                                       double acceptablePivot,
    00418                                       double dualTolerance,
    00419                                       int & numberRemaining,
    00420                                       const double zeroTolerance) const;
    00422      int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
    00423                                     const double * COIN_RESTRICT columnScale,
    00424                                     int * COIN_RESTRICT index,
    00425                                     double * COIN_RESTRICT array,
    00426                                     const unsigned char * status,
    00427                                     const double tolerance) const;
    00429      int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
    00430                                       int * COIN_RESTRICT index,
    00431                                       double * COIN_RESTRICT output,
    00432                                       int numberColumns,
    00433                                       const double tolerance,
    00434                                       const double scalar) const;
    00436      int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
    00437                                       int * COIN_RESTRICT index,
    00438                                       double * COIN_RESTRICT output,
    00439                                       double * COIN_RESTRICT array2,
    00440                                       const double tolerance,
    00441                                       const double scalar) const;
    00443      int gutsOfTransposeTimesByRowGE3a(const CoinIndexedVector * COIN_RESTRICT piVector,
    00444                                       int * COIN_RESTRICT index,
    00445                                       double * COIN_RESTRICT output,
    00446                                       int * COIN_RESTRICT lookup,
    00447                                       char * COIN_RESTRICT marked,
    00448                                       const double tolerance,
    00449                                       const double scalar) const;
    00451      void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00452                                        CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
    00454      void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00455                                        const double tolerance, const double scalar) const;
    00457      void clearCopies();
    00458
    00459
    00460 protected:
    00462      void checkFlags(int type) const;
    00466
    00467      CoinPackedMatrix * matrix_;
    00469      int numberActiveColumns_;
    00477      mutable int flags_;
    00479      ClpPackedMatrix2 * rowCopy_;
    00481      ClpPackedMatrix3 * columnCopy_;
    00483 };
    00484 #ifdef THREAD
    00485 #include <pthread.h>
    00486 typedef struct {
    00487      double acceptablePivot;
    00488      const ClpSimplex * model;
    00489      double * spare;
    00490      int * spareIndex;
    00491      double * arrayTemp;
    00492      int * indexTemp;
    00493      int * numberInPtr;
    00494      double * bestPossiblePtr;
    00495      double * upperThetaPtr;
    00496      int * posFreePtr;
    00497      double * freePivotPtr;
    00498      int * numberOutPtr;
    00499      const unsigned short * count;
    00500      const double * pi;
    00501      const CoinBigIndex * rowStart;
    00502      const double * element;
    00503      const unsigned short * column;
    00504      int offset;
    00505      int numberInRowArray;
    00506      int numberLook;
    00507 } dualColumn0Struct;
    00508 #endif
    00509 class ClpPackedMatrix2 {
    00510
    00511 public:
    00517      void transposeTimes(const ClpSimplex * model,
    00518                          const CoinPackedMatrix * rowCopy,
    00519                          const CoinIndexedVector * x,
    00520                          CoinIndexedVector * spareArray,
    00521                          CoinIndexedVector * z) const;
    00523      inline bool usefulInfo() const {
    00524           return rowStart_ != NULL;
    00525      }
    00527
    00528
    00532      ClpPackedMatrix2();
    00534      ClpPackedMatrix2(ClpSimplex * model, const CoinPackedMatrix * rowCopy);
    00536      virtual ~ClpPackedMatrix2();
    00538
    00542      ClpPackedMatrix2(const ClpPackedMatrix2&);
    00543      ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
    00545
    00546
    00547 protected:
    00551
    00552      int numberBlocks_;
    00554      int numberRows_;
    00556      int * offset_;
    00558      mutable unsigned short * count_;
    00560      mutable CoinBigIndex * rowStart_;
    00562      unsigned short * column_;
    00564      double * work_;
    00565 #ifdef THREAD
    00566      pthread_t * threadId_;
    00567      dualColumn0Struct * info_;
    00568 #endif
    00569
    00570 };
    00571 typedef struct {
    00572      CoinBigIndex startElements_; // point to data
    00573      int startIndices_; // point to column_
    00574      int numberInBlock_;
    00575      int numberPrice_; // at beginning
    00576      int numberElements_; // number elements per column
    00577 } blockStruct;
    00578 class ClpPackedMatrix3 {
    00579
    00580 public:
    00586      void transposeTimes(const ClpSimplex * model,
    00587                          const double * pi,
    00588                          CoinIndexedVector * output) const;
    00590      void transposeTimes2(const ClpSimplex * model,
    00591                           const double * pi, CoinIndexedVector * dj1,
    00592                           const double * piWeight,
    00593                           double referenceIn, double devex,
    00594                           // Array for exact devex to say what is in reference framework
    00595                           unsigned int * reference,
    00596                           double * weights, double scaleFactor);
    00598
    00599
    00603      ClpPackedMatrix3();
    00605      ClpPackedMatrix3(ClpSimplex * model, const CoinPackedMatrix * columnCopy);
    00607      virtual ~ClpPackedMatrix3();
    00609
    00613      ClpPackedMatrix3(const ClpPackedMatrix3&);
    00614      ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
    00616
    00619      void sortBlocks(const ClpSimplex * model);
    00621      void swapOne(const ClpSimplex * model, const ClpPackedMatrix * matrix,
    00622                   int iColumn);
    00624
    00625
    00626 protected:
    00630
    00631      int numberBlocks_;
    00633      int numberColumns_;
    00635      int * column_;
    00637      CoinBigIndex * start_;
    00639      int * row_;
    00641      double * element_;
    00643      blockStruct * block_;
    00645 };
    00646
    00647 #endif