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

- File List
- File Members

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

Go to the documentation of this file.

    00001 /* $Id: ClpPackedMatrix.hpp 2078 2015-01-05 12:39:49Z forrest $ */
    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
    00019 class ClpPackedMatrix2;
    00020 class ClpPackedMatrix3;
    00021 class ClpPackedMatrix : public ClpMatrixBase {
    00022
    00023 public:
    00026
    00027      virtual CoinPackedMatrix * getPackedMatrix() const {
    00028           return matrix_;
    00029      }
    00031      virtual bool isColOrdered() const {
    00032           return matrix_->isColOrdered();
    00033      }
    00035      virtual  CoinBigIndex getNumElements() const {
    00036           return matrix_->getNumElements();
    00037      }
    00039      virtual int getNumCols() const {
    00040           return matrix_->getNumCols();
    00041      }
    00043      virtual int getNumRows() const {
    00044           return matrix_->getNumRows();
    00045      }
    00046
    00051      virtual const double * getElements() const {
    00052           return matrix_->getElements();
    00053      }
    00055      inline double * getMutableElements() const {
    00056           return matrix_->getMutableElements();
    00057      }
    00063      virtual const int * getIndices() const {
    00064           return matrix_->getIndices();
    00065      }
    00066
    00067      virtual const CoinBigIndex * getVectorStarts() const {
    00068           return matrix_->getVectorStarts();
    00069      }
    00071      virtual const int * getVectorLengths() const {
    00072           return matrix_->getVectorLengths();
    00073      }
    00075      virtual int getVectorLength(int index) const {
    00076           return matrix_->getVectorSize(index);
    00077      }
    00078
    00080      virtual void deleteCols(const int numDel, const int * indDel);
    00082      virtual void deleteRows(const int numDel, const int * indDel);
    00083 #ifndef CLP_NO_VECTOR
    00085      virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
    00087      virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
    00088 #endif
    00089
    00093      virtual int appendMatrix(int number, int type,
    00094                               const CoinBigIndex * starts, const int * index,
    00095                               const double * element, int numberOther = -1);
    00100      virtual void replaceVector(const int index,
    00101                                 const int numReplace, const double * newElements) {
    00102           matrix_->replaceVector(index, numReplace, newElements);
    00103      }
    00107      virtual void modifyCoefficient(int row, int column, double newElement,
    00108                                     bool keepZero = false) {
    00109           matrix_->modifyCoefficient(row, column, newElement, keepZero);
    00110      }
    00112      virtual ClpMatrixBase * reverseOrderedCopy() const;
    00114      virtual CoinBigIndex countBasis(const int * whichColumn,
    00115                                      int & numberColumnBasic);
    00117      virtual void fillBasis(ClpSimplex * model,
    00118                             const int * whichColumn,
    00119                             int & numberColumnBasic,
    00120                             int * row, int * start,
    00121                             int * rowCount, int * columnCount,
    00122                             CoinFactorizationDouble * element);
    00125      virtual int scale(ClpModel * model, const ClpSimplex * baseModel = NULL) const ;
    00128      virtual void scaleRowCopy(ClpModel * model) const ;
    00130      void createScaledMatrix(ClpSimplex * model) const;
    00134      virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
    00145      virtual bool allElementsInRange(ClpModel * model,
    00146                                      double smallest, double largest,
    00147                                      int check = 15);
    00151      virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
    00152                                   double & smallestPositive, double & largestPositive);
    00153
    00156      virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
    00157                          int column) const ;
    00162      virtual void unpackPacked(ClpSimplex * model,
    00163                                CoinIndexedVector * rowArray,
    00164                                int column) const;
    00167      virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
    00168                       int column, double multiplier) const ;
    00170      virtual void add(const ClpSimplex * model, double * array,
    00171                       int column, double multiplier) const;
    00173      virtual void releasePackedMatrix() const { }
    00178      virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
    00180      virtual bool canDoPartialPricing() const;
    00182      virtual void partialPricing(ClpSimplex * model, double start, double end,
    00183                                  int & bestSequence, int & numberWanted);
    00185      virtual int refresh(ClpSimplex * model);
    00186      // Really scale matrix
    00187      virtual void reallyScale(const double * rowScale, const double * columnScale);
    00193      virtual void setDimensions(int numrows, int numcols);
    00195
    00201      virtual void times(double scalar,
    00202                         const double * x, double * y) const;
    00204      virtual void times(double scalar,
    00205                         const double * x, double * y,
    00206                         const double * rowScale,
    00207                         const double * columnScale) const;
    00211      virtual void transposeTimes(double scalar,
    00212                                  const double * x, double * y) const;
    00214      virtual void transposeTimes(double scalar,
    00215                                  const double * x, double * y,
    00216                                  const double * rowScale,
    00217                                  const double * columnScale,
    00218                                  double * spare = NULL) const;
    00223      void transposeTimesSubset( int number,
    00224                                 const int * which,
    00225                                 const double * pi, double * y,
    00226                                 const double * rowScale,
    00227                                 const double * columnScale,
    00228                                 double * spare = NULL) const;
    00233      virtual void transposeTimes(const ClpSimplex * model, double scalar,
    00234                                  const CoinIndexedVector * x,
    00235                                  CoinIndexedVector * y,
    00236                                  CoinIndexedVector * z) const;
    00241      void transposeTimesByColumn(const ClpSimplex * model, double scalar,
    00242                                  const CoinIndexedVector * x,
    00243                                  CoinIndexedVector * y,
    00244                                  CoinIndexedVector * z) const;
    00250      virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
    00251                                       const CoinIndexedVector * x,
    00252                                       CoinIndexedVector * y,
    00253                                       CoinIndexedVector * z) const;
    00257      virtual void subsetTransposeTimes(const ClpSimplex * model,
    00258                                        const CoinIndexedVector * x,
    00259                                        const CoinIndexedVector * y,
    00260                                        CoinIndexedVector * z) const;
    00263      virtual bool canCombine(const ClpSimplex * model,
    00264                              const CoinIndexedVector * pi) const;
    00266      virtual void transposeTimes2(const ClpSimplex * model,
    00267                                   const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
    00268                                   const CoinIndexedVector * pi2,
    00269                                   CoinIndexedVector * spare,
    00270                                   double referenceIn, double devex,
    00271                                   // Array for exact devex to say what is in reference framework
    00272                                   unsigned int * reference,
    00273                                   double * weights, double scaleFactor);
    00275      virtual void subsetTimes2(const ClpSimplex * model,
    00276                                CoinIndexedVector * dj1,
    00277                                const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
    00278                                double referenceIn, double devex,
    00279                                // Array for exact devex to say what is in reference framework
    00280                                unsigned int * reference,
    00281                                double * weights, double scaleFactor);
    00283      void useEffectiveRhs(ClpSimplex * model);
    00284 #if COIN_LONG_WORK
    00285      // For long double versions
    00286      virtual void times(CoinWorkDouble scalar,
    00287                         const CoinWorkDouble * x, CoinWorkDouble * y) const ;
    00288      virtual void transposeTimes(CoinWorkDouble scalar,
    00289                                  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
    00290 #endif
    00291
    00292
    00295
    00296      inline CoinPackedMatrix * matrix() const {
    00297           return matrix_;
    00298      }
    00302      inline void setMatrixNull() {
    00303           matrix_ = NULL;
    00304      }
    00306      inline void makeSpecialColumnCopy() {
    00307           flags_ |= 16;
    00308      }
    00310      void releaseSpecialColumnCopy();
    00312      inline bool zeros() const {
    00313           return ((flags_ & 1) != 0);
    00314      }
    00316      inline bool wantsSpecialColumnCopy() const {
    00317           return ((flags_ & 16) != 0);
    00318      }
    00320      inline int flags() const {
    00321           return flags_;
    00322      }
    00324      inline void checkGaps() {
    00325           flags_ = (matrix_->hasGaps()) ? (flags_ | 2) : (flags_ & (~2));
    00326      }
    00328      inline int numberActiveColumns() const
    00329      { return numberActiveColumns_;}
    00331      inline void setNumberActiveColumns(int value)
    00332      { numberActiveColumns_ = value;}
    00334
    00335
    00339      ClpPackedMatrix();
    00341      virtual ~ClpPackedMatrix();
    00343
    00347      ClpPackedMatrix(const ClpPackedMatrix&);
    00349      ClpPackedMatrix(const CoinPackedMatrix&);
    00352      ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
    00353                       int numberRows, const int * whichRows,
    00354                       int numberColumns, const int * whichColumns);
    00355      ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
    00356                       int numberRows, const int * whichRows,
    00357                       int numberColumns, const int * whichColumns);
    00358
    00360      ClpPackedMatrix(CoinPackedMatrix * matrix);
    00361
    00362      ClpPackedMatrix& operator=(const ClpPackedMatrix&);
    00364      virtual ClpMatrixBase * clone() const ;
    00366      virtual void copy(const ClpPackedMatrix * from);
    00369      virtual ClpMatrixBase * subsetClone (
    00370           int numberRows, const int * whichRows,
    00371           int numberColumns, const int * whichColumns) const ;
    00373      void specialRowCopy(ClpSimplex * model, const ClpMatrixBase * rowCopy);
    00375      void specialColumnCopy(ClpSimplex * model);
    00377      virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
    00379 private:
    00381      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00382                                       int * COIN_RESTRICT index,
    00383                                       double * COIN_RESTRICT array,
    00384                                       const double tolerance) const;
    00386      int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
    00387                                     const double * COIN_RESTRICT columnScale,
    00388                                     int * COIN_RESTRICT index,
    00389                                     double * COIN_RESTRICT array,
    00390                                     const double tolerance) const;
    00392      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00393                                       int * COIN_RESTRICT index,
    00394                                       double * COIN_RESTRICT array,
    00395                                       const unsigned char * status,
    00396                                       const double tolerance) const;
    00399      int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
    00400                                       int * COIN_RESTRICT index,
    00401                                       double * COIN_RESTRICT array,
    00402                                       const unsigned char * status,
    00403                                       int * COIN_RESTRICT spareIndex,
    00404                                       double * COIN_RESTRICT spareArray,
    00405                                       const double * COIN_RESTRICT reducedCost,
    00406                                       double & upperTheta,
    00407                                       double & bestPossible,
    00408                                       double acceptablePivot,
    00409                                       double dualTolerance,
    00410                                       int & numberRemaining,
    00411                                       const double zeroTolerance) const;
    00413      int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
    00414                                     const double * COIN_RESTRICT columnScale,
    00415                                     int * COIN_RESTRICT index,
    00416                                     double * COIN_RESTRICT array,
    00417                                     const unsigned char * status,
    00418                                     const double tolerance) const;
    00420      int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
    00421                                       int * COIN_RESTRICT index,
    00422                                       double * COIN_RESTRICT output,
    00423                                       int numberColumns,
    00424                                       const double tolerance,
    00425                                       const double scalar) const;
    00427      int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
    00428                                       int * COIN_RESTRICT index,
    00429                                       double * COIN_RESTRICT output,
    00430                                       double * COIN_RESTRICT array2,
    00431                                       const double tolerance,
    00432                                       const double scalar) const;
    00434      int gutsOfTransposeTimesByRowGE3a(const CoinIndexedVector * COIN_RESTRICT piVector,
    00435                                       int * COIN_RESTRICT index,
    00436                                       double * COIN_RESTRICT output,
    00437                                       int * COIN_RESTRICT lookup,
    00438                                       char * COIN_RESTRICT marked,
    00439                                       const double tolerance,
    00440                                       const double scalar) const;
    00442      void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00443                                        CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
    00445      void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
    00446                                        const double tolerance, const double scalar) const;
    00448      void clearCopies();
    00449
    00450
    00451 protected:
    00453      void checkFlags(int type) const;
    00457
    00458      CoinPackedMatrix * matrix_;
    00460      int numberActiveColumns_;
    00468      mutable int flags_;
    00470      ClpPackedMatrix2 * rowCopy_;
    00472      ClpPackedMatrix3 * columnCopy_;
    00474 };
    00475 #ifdef THREAD
    00476 #include <pthread.h>
    00477 typedef struct {
    00478      double acceptablePivot;
    00479      const ClpSimplex * model;
    00480      double * spare;
    00481      int * spareIndex;
    00482      double * arrayTemp;
    00483      int * indexTemp;
    00484      int * numberInPtr;
    00485      double * bestPossiblePtr;
    00486      double * upperThetaPtr;
    00487      int * posFreePtr;
    00488      double * freePivotPtr;
    00489      int * numberOutPtr;
    00490      const unsigned short * count;
    00491      const double * pi;
    00492      const CoinBigIndex * rowStart;
    00493      const double * element;
    00494      const unsigned short * column;
    00495      int offset;
    00496      int numberInRowArray;
    00497      int numberLook;
    00498 } dualColumn0Struct;
    00499 #endif
    00500 class ClpPackedMatrix2 {
    00501
    00502 public:
    00508      void transposeTimes(const ClpSimplex * model,
    00509                          const CoinPackedMatrix * rowCopy,
    00510                          const CoinIndexedVector * x,
    00511                          CoinIndexedVector * spareArray,
    00512                          CoinIndexedVector * z) const;
    00514      inline bool usefulInfo() const {
    00515           return rowStart_ != NULL;
    00516      }
    00518
    00519
    00523      ClpPackedMatrix2();
    00525      ClpPackedMatrix2(ClpSimplex * model, const CoinPackedMatrix * rowCopy);
    00527      virtual ~ClpPackedMatrix2();
    00529
    00533      ClpPackedMatrix2(const ClpPackedMatrix2&);
    00534      ClpPackedMatrix2& operator=(const ClpPackedMatrix2&);
    00536
    00537
    00538 protected:
    00542
    00543      int numberBlocks_;
    00545      int numberRows_;
    00547      int * offset_;
    00549      mutable unsigned short * count_;
    00551      mutable CoinBigIndex * rowStart_;
    00553      unsigned short * column_;
    00555      double * work_;
    00556 #ifdef THREAD
    00557      pthread_t * threadId_;
    00558      dualColumn0Struct * info_;
    00559 #endif
    00560
    00561 };
    00562 typedef struct {
    00563      CoinBigIndex startElements_; // point to data
    00564      int startIndices_; // point to column_
    00565      int numberInBlock_;
    00566      int numberPrice_; // at beginning
    00567      int numberElements_; // number elements per column
    00568 } blockStruct;
    00569 class ClpPackedMatrix3 {
    00570
    00571 public:
    00577      void transposeTimes(const ClpSimplex * model,
    00578                          const double * pi,
    00579                          CoinIndexedVector * output) const;
    00581      void transposeTimes2(const ClpSimplex * model,
    00582                           const double * pi, CoinIndexedVector * dj1,
    00583                           const double * piWeight,
    00584                           double referenceIn, double devex,
    00585                           // Array for exact devex to say what is in reference framework
    00586                           unsigned int * reference,
    00587                           double * weights, double scaleFactor);
    00589
    00590
    00594      ClpPackedMatrix3();
    00596      ClpPackedMatrix3(ClpSimplex * model, const CoinPackedMatrix * columnCopy);
    00598      virtual ~ClpPackedMatrix3();
    00600
    00604      ClpPackedMatrix3(const ClpPackedMatrix3&);
    00605      ClpPackedMatrix3& operator=(const ClpPackedMatrix3&);
    00607
    00610      void sortBlocks(const ClpSimplex * model);
    00612      void swapOne(const ClpSimplex * model, const ClpPackedMatrix * matrix,
    00613                   int iColumn);
    00615
    00616
    00617 protected:
    00621
    00622      int numberBlocks_;
    00624      int numberColumns_;
    00626      int * column_;
    00628      CoinBigIndex * start_;
    00630      int * row_;
    00632      double * element_;
    00634      blockStruct * block_;
    00636 };
    00637
    00638 #endif