AbcMatrix.hpp

Go to the documentation of this file.
00001 /* $Id: AbcMatrix.hpp 1910 2013-01-27 02:00:13Z stefan $ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others, Copyright (C) 2012, FasterCoin.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
00005 
00006 #ifndef AbcMatrix_H
00007 #define AbcMatrix_H
00008 
00009 #include "CoinPragma.hpp"
00010 
00011 #include "ClpMatrixBase.hpp"
00012 #include "AbcSimplex.hpp"
00013 #include "CoinAbcHelperFunctions.hpp"
00020 class AbcMatrix2;
00021 class AbcMatrix3;
00022 class AbcMatrix {
00023   
00024 public:
00027 
00028   inline CoinPackedMatrix * getPackedMatrix() const {
00029     return matrix_;
00030   }
00032   inline bool isColOrdered() const {
00033     return true;
00034   }
00036   inline CoinBigIndex getNumElements() const {
00037     return matrix_->getNumElements();
00038   }
00040   inline int getNumCols() const {
00041     assert(matrix_->getNumCols()==model_->numberColumns());return matrix_->getNumCols();
00042   }
00044   inline int getNumRows() const {
00045     assert(matrix_->getNumRows()==model_->numberRows());return matrix_->getNumRows();
00046   }
00048   void setModel(AbcSimplex * model);
00050   inline const double * getElements() const {
00051     return matrix_->getElements();
00052   }
00054   inline double * getMutableElements() const {
00055     return matrix_->getMutableElements();
00056   }
00058   inline const int * getIndices() const {
00059     return matrix_->getIndices();
00060   }
00062   inline int * getMutableIndices() const {
00063     return matrix_->getMutableIndices();
00064   }
00066   inline const CoinBigIndex * getVectorStarts() const {
00067     return matrix_->getVectorStarts();
00068   }
00069   inline  CoinBigIndex * getMutableVectorStarts() const {
00070     return matrix_->getMutableVectorStarts();
00071   }
00073   inline const int * getVectorLengths() const {
00074     return matrix_->getVectorLengths();
00075   }
00077   inline int * getMutableVectorLengths() const {
00078     return matrix_->getMutableVectorLengths();
00079   }
00081   CoinBigIndex * rowStart() const;
00083   CoinBigIndex * rowEnd() const;
00085   double * rowElements() const;
00087   CoinSimplexInt * rowColumns() const;
00089   CoinPackedMatrix * reverseOrderedCopy() const;
00091   CoinBigIndex countBasis(const int * whichColumn,
00092                           int & numberColumnBasic);
00094   void fillBasis(const int * whichColumn,
00095                  int & numberColumnBasic,
00096                  int * row, int * start,
00097                  int * rowCount, int * columnCount,
00098                  CoinSimplexDouble * element);
00100   void fillBasis(const int * whichColumn,
00101                  int & numberColumnBasic,
00102                  int * row, int * start,
00103                  int * rowCount, int * columnCount,
00104                  long double * element);
00107   void scale(int numberRowsAlreadyScaled);
00109   void createRowCopy();
00111   void takeOutOfUseful(int sequence,CoinIndexedVector & spare);
00113   void putIntofUseful(int sequence,CoinIndexedVector & spare);
00115   void inOutUseful(int sequenceIn,int sequenceOut);
00117   void makeAllUseful(CoinIndexedVector & spare);
00119   void sortUseful(CoinIndexedVector & spare);
00121   void moveLargestToStart();
00122   
00125   void unpack(CoinIndexedVector & rowArray,
00126               int column) const ;
00129   void add(CoinIndexedVector & rowArray, int column, double multiplier) const ;
00131   
00137   void timesModifyExcludingSlacks(double scalar,
00138              const double * x, double * y) const;
00142   void timesModifyIncludingSlacks(double scalar,
00143              const double * x, double * y) const;
00147   void timesIncludingSlacks(double scalar,
00148              const double * x, double * y) const;
00152   void transposeTimesNonBasic(double scalar,
00153                             const double * x, double * y) const;
00157   void transposeTimesAll(const double * x, double * y) const;
00161   void transposeTimesBasic(double scalar,
00162                             const double * x, double * y) const;
00173   int transposeTimesNonBasic(double scalar,
00174                       const CoinIndexedVector & x,
00175                       CoinIndexedVector & z) const;
00177   double dualColumn1(const CoinIndexedVector & update,
00178                      CoinPartitionedVector & tableauRow,
00179                      CoinPartitionedVector & candidateList) const;
00181   double dualColumn1Row(int iBlock, double upperThetaSlack, int & freeSequence,
00182                         const CoinIndexedVector & update,
00183                         CoinPartitionedVector & tableauRow,
00184                         CoinPartitionedVector & candidateList) const;
00186   double dualColumn1RowFew(int iBlock, double upperThetaSlack, int & freeSequence,
00187                          const CoinIndexedVector & update,
00188                          CoinPartitionedVector & tableauRow,
00189                          CoinPartitionedVector & candidateList) const;
00191   double dualColumn1Row2(double upperThetaSlack, int & freeSequence,
00192                          const CoinIndexedVector & update,
00193                          CoinPartitionedVector & tableauRow,
00194                          CoinPartitionedVector & candidateList) const;
00196   double dualColumn1Row1(double upperThetaSlack, int & freeSequence,
00197                          const CoinIndexedVector & update,
00198                          CoinPartitionedVector & tableauRow,
00199                          CoinPartitionedVector & candidateList) const;
00203   void dualColumn1Part(int iBlock,int & sequenceIn, double & upperTheta,
00204                          const CoinIndexedVector & update,
00205                          CoinPartitionedVector & tableauRow,
00206                          CoinPartitionedVector & candidateList) const;
00208   void rebalance() const;
00210   int pivotColumnDantzig(const CoinIndexedVector & updates,
00211                          CoinPartitionedVector & spare) const; 
00213   int pivotColumnDantzig(int iBlock,bool doByRow,const CoinIndexedVector & updates,
00214                          CoinPartitionedVector & spare,
00215                          double & bestValue) const; 
00217   int primalColumnRow(int iBlock,bool doByRow,const CoinIndexedVector & update,
00218                           CoinPartitionedVector & tableauRow) const;
00220   int primalColumnRowAndDjs(int iBlock,const CoinIndexedVector & updateTableau,
00221                           const CoinIndexedVector & updateDjs,
00222                             CoinPartitionedVector & tableauRow) const;
00225   int chooseBestDj(int iBlock,const CoinIndexedVector & infeasibilities, 
00226                    const double * weights) const;
00232   int primalColumnDouble(int iBlock,CoinPartitionedVector & updateForTableauRow,
00233                           CoinPartitionedVector & updateForDjs,
00234                           const CoinIndexedVector & updateForWeights,
00235                           CoinPartitionedVector & spareColumn1,
00236                           double * infeasibilities, 
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) const;
00246   int primalColumnSparseDouble(int iBlock,CoinPartitionedVector & updateForTableauRow,
00247                           CoinPartitionedVector & updateForDjs,
00248                           const CoinIndexedVector & updateForWeights,
00249                           CoinPartitionedVector & spareColumn1,
00250                           double * infeasibilities, 
00251                           double referenceIn, double devex,
00252                           // Array for exact devex to say what is in reference framework
00253                           unsigned int * reference,
00254                           double * weights, double scaleFactor) const;
00260   int primalColumnDouble(CoinPartitionedVector & updateForTableauRow,
00261                          CoinPartitionedVector & updateForDjs,
00262                          const CoinIndexedVector & updateForWeights,
00263                          CoinPartitionedVector & spareColumn1,
00264                          CoinIndexedVector & infeasible, 
00265                          double referenceIn, double devex,
00266                          // Array for exact devex to say what is in reference framework
00267                          unsigned int * reference,
00268                          double * weights, double scaleFactor) const;
00270   void primalColumnSubset(int iBlock,const CoinIndexedVector & update,
00271                           const CoinPartitionedVector & tableauRow,
00272                           CoinPartitionedVector & weights) const;
00274   void partialPricing(double startFraction, double endFraction,
00275                       int & bestSequence, int & numberWanted);
00279   void subsetTransposeTimes(const CoinIndexedVector & x,
00280                             CoinIndexedVector & z) const;
00282   void transposeTimes(const CoinIndexedVector & x,
00283                             CoinIndexedVector & z) const;
00285   
00288 
00289   inline CoinPackedMatrix * matrix() const {
00290     return matrix_;
00291   }
00294   inline int minimumObjectsScan() const {
00295     return minimumObjectsScan_;
00296   }
00297   inline void setMinimumObjectsScan(int value) {
00298     minimumObjectsScan_ = value;
00299   }
00301   inline int minimumGoodReducedCosts() const {
00302     return minimumGoodReducedCosts_;
00303   }
00304   inline void setMinimumGoodReducedCosts(int value) {
00305     minimumGoodReducedCosts_ = value;
00306   }
00308   inline double startFraction() const {
00309     return startFraction_;
00310   }
00311   inline void setStartFraction(double value) {
00312     startFraction_ = value;
00313   }
00315   inline double endFraction() const {
00316     return endFraction_;
00317   }
00318   inline void setEndFraction(double value) {
00319     endFraction_ = value;
00320   }
00322   inline double savedBestDj() const {
00323     return savedBestDj_;
00324   }
00325   inline void setSavedBestDj(double value) {
00326     savedBestDj_ = value;
00327   }
00329   inline int originalWanted() const {
00330     return originalWanted_;
00331   }
00332   inline void setOriginalWanted(int value) {
00333     originalWanted_ = value;
00334   }
00336   inline int currentWanted() const {
00337     return currentWanted_;
00338   }
00339   inline void setCurrentWanted(int value) {
00340     currentWanted_ = value;
00341   }
00343   inline int savedBestSequence() const {
00344     return savedBestSequence_;
00345   }
00346   inline void setSavedBestSequence(int value) {
00347     savedBestSequence_ = value;
00348   }
00350   inline int * startColumnBlock() const
00351   {return startColumnBlock_;}
00353   inline const int * blockStart() const
00354   { return blockStart_;}
00355   inline bool gotRowCopy() const
00356   { return rowStart_!=0;}
00358   inline int blockStart(int block) const
00359   { return blockStart_[block];}
00361   inline int numberColumnBlocks() const
00362   { return numberColumnBlocks_;}
00364   inline int numberRowBlocks() const
00365   { return numberRowBlocks_;}
00367   
00368   
00372   AbcMatrix();
00374   ~AbcMatrix();
00376   
00380   AbcMatrix(const AbcMatrix&);
00382   AbcMatrix(const CoinPackedMatrix&);
00385   AbcMatrix (const AbcMatrix & wholeModel,
00386              int numberRows, const int * whichRows,
00387              int numberColumns, const int * whichColumns);
00388   AbcMatrix (const CoinPackedMatrix & wholeModel,
00389              int numberRows, const int * whichRows,
00390              int numberColumns, const int * whichColumns);
00391   
00392   AbcMatrix& operator=(const AbcMatrix&);
00394   void copy(const AbcMatrix * from);
00396 private:
00397   
00398 protected:
00402 
00403   CoinPackedMatrix * matrix_;
00405   mutable AbcSimplex * model_;
00406 #if ABC_PARALLEL==0
00407 #define NUMBER_ROW_BLOCKS 1
00408 #define NUMBER_COLUMN_BLOCKS 1
00409 #elif ABC_PARALLEL==1
00410 #define NUMBER_ROW_BLOCKS 4
00411 #define NUMBER_COLUMN_BLOCKS 4
00412 #else
00413 #define NUMBER_ROW_BLOCKS 8
00414 #define NUMBER_COLUMN_BLOCKS 8
00415 #endif
00416 
00419   CoinBigIndex * rowStart_;
00421   double * element_;
00423   int * column_;
00425   mutable int startColumnBlock_[NUMBER_COLUMN_BLOCKS+1];
00427   int blockStart_[NUMBER_ROW_BLOCKS+1];
00429   mutable int numberColumnBlocks_;
00431   int numberRowBlocks_;
00432   //#define COUNT_COPY
00433 #ifdef COUNT_COPY
00434 #define MAX_COUNT 13
00436   CoinBigIndex countStart_[MAX_COUNT+1];
00438   int countFirst_[MAX_COUNT+1];
00439   // later int countEndUseful_[MAX_COUNT+1];
00440   int * countRealColumn_;
00441   // later int * countInverseRealColumn_;
00442   CoinBigIndex * countStartLarge_;
00443   int * countRow_;
00444   double * countElement_;
00445   int smallestCount_;
00446   int largestCount_;
00447 #endif 
00449   //AbcMatrix2 * rowCopy_;
00451   //AbcMatrix3 * columnCopy_;
00453   double startFraction_;
00455   double endFraction_;
00457   double savedBestDj_;
00459   int originalWanted_;
00461   int currentWanted_;
00463   int savedBestSequence_;
00465   int minimumObjectsScan_;
00467   int minimumGoodReducedCosts_;
00468 
00469 };
00470 #ifdef THREAD
00471 #include <pthread.h>
00472 typedef struct {
00473   double acceptablePivot;
00474   const AbcSimplex * model;
00475   double * spare;
00476   int * spareIndex;
00477   double * arrayTemp;
00478   int * indexTemp;
00479   int * numberInPtr;
00480   double * bestPossiblePtr;
00481   double * upperThetaPtr;
00482   int * posFreePtr;
00483   double * freePivotPtr;
00484   int * numberOutPtr;
00485   const unsigned short * count;
00486   const double * pi;
00487   const CoinBigIndex * rowStart;
00488   const double * element;
00489   const unsigned short * column;
00490   int offset;
00491   int numberInRowArray;
00492   int numberLook;
00493 } dualColumn0Struct;
00494 #endif
00495 class AbcMatrix2 {
00496   
00497 public:
00503   void transposeTimes(const AbcSimplex * model,
00504                       const CoinPackedMatrix * rowCopy,
00505                       const CoinIndexedVector & x,
00506                       CoinIndexedVector & spareArray,
00507                       CoinIndexedVector & z) const;
00509   inline bool usefulInfo() const {
00510     return rowStart_ != NULL;
00511   }
00513   
00514   
00518   AbcMatrix2();
00520   AbcMatrix2(AbcSimplex * model, const CoinPackedMatrix * rowCopy);
00522   ~AbcMatrix2();
00524   
00528   AbcMatrix2(const AbcMatrix2&);
00529   AbcMatrix2& operator=(const AbcMatrix2&);
00531   
00532   
00533 protected:
00537 
00538   int numberBlocks_;
00540   int numberRows_;
00542   int * offset_;
00544   mutable unsigned short * count_;
00546   mutable CoinBigIndex * rowStart_;
00548   unsigned short * column_;
00550   double * work_;
00551 #ifdef THREAD
00552   pthread_t * threadId_;
00553   dualColumn0Struct * info_;
00554 #endif
00555 
00556 };
00557 typedef struct {
00558   CoinBigIndex startElements_; // point to data
00559   int startIndices_; // point to column_
00560   int numberInBlock_;
00561   int numberPrice_; // at beginning
00562   int numberElements_; // number elements per column
00563 } blockStruct3;
00564 class AbcMatrix3 {
00565   
00566 public:
00572   void transposeTimes(const AbcSimplex * model,
00573                       const double * pi,
00574                       CoinIndexedVector & output) const;
00576   void transposeTimes2(const AbcSimplex * model,
00577                        const double * pi, CoinIndexedVector & dj1,
00578                        const double * piWeight,
00579                        double referenceIn, double devex,
00580                        // Array for exact devex to say what is in reference framework
00581                        unsigned int * reference,
00582                        double * weights, double scaleFactor);
00584   
00585   
00589   AbcMatrix3();
00591   AbcMatrix3(AbcSimplex * model, const CoinPackedMatrix * columnCopy);
00593   ~AbcMatrix3();
00595   
00599   AbcMatrix3(const AbcMatrix3&);
00600   AbcMatrix3& operator=(const AbcMatrix3&);
00602 
00605   void sortBlocks(const AbcSimplex * model);
00607   void swapOne(const AbcSimplex * model, const AbcMatrix * matrix,
00608                int iColumn);
00610   
00611   
00612 protected:
00616 
00617   int numberBlocks_;
00619   int numberColumns_;
00621   int * column_;
00623   CoinBigIndex * start_;
00625   int * row_;
00627   double * element_;
00629   blockStruct * block_;
00631 };
00632 
00633 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 17 Jul 2013 for Clp by  doxygen 1.6.1