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

- File List
- File Members

# /home/coin/SVN-release/Bcps-0.91.0/CoinUtils/src/CoinModel.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2005, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef CoinModel_H
    00004 #define CoinModel_H
    00005
    00006 #include "CoinModelUseful.hpp"
    00007 #include "CoinPackedMatrix.hpp"
    00008 class CoinBaseModel {
    00009
    00010 public:
    00011
    00012
    00015
    00016   CoinBaseModel ();
    00017
    00019   CoinBaseModel ( const CoinBaseModel &rhs);
    00020
    00022   CoinBaseModel & operator=( const CoinBaseModel& rhs);
    00023
    00025   virtual CoinBaseModel * clone() const=0;
    00026
    00028   virtual ~CoinBaseModel () ;
    00030
    00033
    00034   inline int numberRows() const
    00035   { return numberRows_;}
    00037   inline int numberColumns() const
    00038   { return numberColumns_;}
    00040   virtual CoinBigIndex numberElements() const = 0;
    00044   inline double objectiveOffset() const
    00045   { return objectiveOffset_;}
    00047   inline void setObjectiveOffset(double value)
    00048   { objectiveOffset_=value;}
    00050   inline double optimizationDirection() const {
    00051     return  optimizationDirection_;
    00052   }
    00054   inline void setOptimizationDirection(double value)
    00055   { optimizationDirection_=value;}
    00057   inline int logLevel() const
    00058   { return logLevel_;}
    00060   void setLogLevel(int value);
    00062   inline const char * getProblemName() const
    00063   { return problemName_.c_str();}
    00065   void setProblemName(const char *name) ;
    00067   void setProblemName(const std::string &name) ;
    00069   inline const std::string & getRowBlock() const
    00070   { return rowBlockName_;}
    00072   inline void setRowBlock(const std::string &name)
    00073   { rowBlockName_ = name;}
    00075   inline const std::string & getColumnBlock() const
    00076   { return columnBlockName_;}
    00078   inline void setColumnBlock(const std::string &name)
    00079   { columnBlockName_ = name;}
    00081
    00082 protected:
    00085
    00086   int numberRows_;
    00088   int numberColumns_;
    00090   double optimizationDirection_;
    00092   double objectiveOffset_;
    00094   std::string problemName_;
    00096   std::string rowBlockName_;
    00098   std::string columnBlockName_;
    00106   int logLevel_;
    00108
    00109
    00110 };
    00111
    00148 class CoinModel : public CoinBaseModel {
    00149
    00150 public:
    00154    void addRow(int numberInRow, const int * columns,
    00155                const double * elements, double rowLower=-COIN_DBL_MAX,
    00156               double rowUpper=COIN_DBL_MAX, const char * name=NULL);
    00158    void addColumn(int numberInColumn, const int * rows,
    00159                   const double * elements,
    00160                   double columnLower=0.0,
    00161                   double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00162                   const char * name=NULL, bool isInteger=false);
    00164   inline void addCol(int numberInColumn, const int * rows,
    00165                      const double * elements,
    00166                      double columnLower=0.0,
    00167                      double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00168                      const char * name=NULL, bool isInteger=false)
    00169   { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
    00170               name,isInteger);}
    00172   inline void operator() (int i,int j,double value)
    00173   { setElement(i,j,value);}
    00175   void setElement(int i,int j,double value) ;
    00181   int getRow(int whichRow, int * column, double * element);
    00187   int getColumn(int whichColumn, int * column, double * element);
    00189   void setQuadraticElement(int i,int j,double value) ;
    00191   inline void operator() (int i,int j,const char * value)
    00192   { setElement(i,j,value);}
    00194   void setElement(int i,int j,const char * value) ;
    00196   int associateElement(const char * stringValue, double value);
    00200   void setRowLower(int whichRow,double rowLower);
    00204   void setRowUpper(int whichRow,double rowUpper);
    00208   void setRowBounds(int whichRow,double rowLower,double rowUpper);
    00212   void setRowName(int whichRow,const char * rowName);
    00216   void setColumnLower(int whichColumn,double columnLower);
    00220   void setColumnUpper(int whichColumn,double columnUpper);
    00224   void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
    00228   void setColumnObjective(int whichColumn,double columnObjective);
    00232   void setColumnName(int whichColumn,const char * columnName);
    00236   void setColumnIsInteger(int whichColumn,bool columnIsInteger);
    00240   inline void setObjective(int whichColumn,double columnObjective)
    00241   { setColumnObjective( whichColumn, columnObjective);}
    00245   inline void setIsInteger(int whichColumn,bool columnIsInteger)
    00246   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00250   inline void setInteger(int whichColumn)
    00251   { setColumnIsInteger( whichColumn, true);}
    00255   inline void setContinuous(int whichColumn)
    00256   { setColumnIsInteger( whichColumn, false);}
    00260   inline void setColLower(int whichColumn,double columnLower)
    00261   { setColumnLower( whichColumn, columnLower);}
    00265   inline void setColUpper(int whichColumn,double columnUpper)
    00266   { setColumnUpper( whichColumn, columnUpper);}
    00270   inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
    00271   { setColumnBounds( whichColumn, columnLower, columnUpper);}
    00275   inline void setColObjective(int whichColumn,double columnObjective)
    00276   { setColumnObjective( whichColumn, columnObjective);}
    00280   inline void setColName(int whichColumn,const char * columnName)
    00281   { setColumnName( whichColumn, columnName);}
    00285   inline void setColIsInteger(int whichColumn,bool columnIsInteger)
    00286   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00290   void setRowLower(int whichRow,const char * rowLower);
    00294   void setRowUpper(int whichRow,const char * rowUpper);
    00298   void setColumnLower(int whichColumn,const char * columnLower);
    00302   void setColumnUpper(int whichColumn,const char * columnUpper);
    00306   void setColumnObjective(int whichColumn,const char * columnObjective);
    00310   void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
    00314   inline void setObjective(int whichColumn,const char * columnObjective)
    00315   { setColumnObjective( whichColumn, columnObjective);}
    00319   inline void setIsInteger(int whichColumn,const char * columnIsInteger)
    00320   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00323   void deleteRow(int whichRow);
    00326   void deleteColumn(int whichColumn);
    00329   inline void deleteCol(int whichColumn)
    00330   { deleteColumn(whichColumn);}
    00332   int deleteElement(int row, int column);
    00334   void deleteThisElement(int row, int column,int position);
    00337   int packRows();
    00340   int packColumns();
    00343   inline int packCols()
    00344   { return packColumns();}
    00349   int pack();
    00350
    00353   void setObjective(int numberColumns,const double * objective) ;
    00356   void setColumnLower(int numberColumns,const double * columnLower);
    00359   inline void setColLower(int numberColumns,const double * columnLower)
    00360   { setColumnLower( numberColumns, columnLower);}
    00363   void setColumnUpper(int numberColumns,const double * columnUpper);
    00366   inline void setColUpper(int numberColumns,const double * columnUpper)
    00367   { setColumnUpper( numberColumns, columnUpper);}
    00370   void setRowLower(int numberRows,const double * rowLower);
    00373   void setRowUpper(int numberRows,const double * rowUpper);
    00374
    00400   int writeMps(const char *filename, int compression = 0,
    00401                int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
    00402
    00407   int differentModel(CoinModel & other, bool ignoreNames);
    00409
    00410
    00413
    00414   void passInMatrix(const CoinPackedMatrix & matrix);
    00417   int convertMatrix();
    00419   inline const CoinPackedMatrix * packedMatrix() const
    00420   { return packedMatrix_;}
    00422   inline const int * originalRows() const
    00423   { return rowType_;}
    00425   inline const int * originalColumns() const
    00426   { return columnType_;}
    00428
    00429
    00432
    00433   inline CoinBigIndex numberElements() const
    00434   { return numberElements_;}
    00436   inline const CoinModelTriple * elements() const
    00437   { return elements_;}
    00439   inline double operator() (int i,int j) const
    00440   { return getElement(i,j);}
    00442   double getElement(int i,int j) const;
    00444   inline double operator() (const char * rowName,const char * columnName) const
    00445   { return getElement(rowName,columnName);}
    00447   double getElement(const char * rowName,const char * columnName) const;
    00449   double getQuadraticElement(int i,int j) const;
    00454   const char * getElementAsString(int i,int j) const;
    00458   double * pointer (int i,int j) const;
    00462   int position (int i,int j) const;
    00463
    00464
    00468   CoinModelLink firstInRow(int whichRow) const ;
    00472   CoinModelLink lastInRow(int whichRow) const ;
    00476   CoinModelLink firstInColumn(int whichColumn) const ;
    00480   CoinModelLink lastInColumn(int whichColumn) const ;
    00485   CoinModelLink next(CoinModelLink & current) const ;
    00491   CoinModelLink previous(CoinModelLink & current) const ;
    00496   CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
    00500   CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
    00503   double  getRowLower(int whichRow) const ;
    00506   double  getRowUpper(int whichRow) const ;
    00509   const char * getRowName(int whichRow) const ;
    00510   inline double  rowLower(int whichRow) const
    00511   { return getRowLower(whichRow);}
    00514   inline double  rowUpper(int whichRow) const
    00515   { return getRowUpper(whichRow) ;}
    00518   inline const char * rowName(int whichRow) const
    00519   { return getRowName(whichRow);}
    00522   double  getColumnLower(int whichColumn) const ;
    00525   double  getColumnUpper(int whichColumn) const ;
    00528   double  getColumnObjective(int whichColumn) const ;
    00531   const char * getColumnName(int whichColumn) const ;
    00534   bool getColumnIsInteger(int whichColumn) const ;
    00537   inline double  columnLower(int whichColumn) const
    00538   { return getColumnLower(whichColumn);}
    00541   inline double  columnUpper(int whichColumn) const
    00542   { return getColumnUpper(whichColumn) ;}
    00545   inline double  columnObjective(int whichColumn) const
    00546   { return getColumnObjective(whichColumn);}
    00549   inline double  objective(int whichColumn) const
    00550   { return getColumnObjective(whichColumn);}
    00553   inline const char * columnName(int whichColumn) const
    00554   { return getColumnName(whichColumn);}
    00557   inline bool columnIsInteger(int whichColumn) const
    00558   { return getColumnIsInteger(whichColumn);}
    00561   inline bool isInteger(int whichColumn) const
    00562   { return getColumnIsInteger(whichColumn);}
    00565   inline double  getColLower(int whichColumn) const
    00566   { return getColumnLower(whichColumn);}
    00569   inline double  getColUpper(int whichColumn) const
    00570   { return getColumnUpper(whichColumn) ;}
    00573   inline double  getColObjective(int whichColumn) const
    00574   { return getColumnObjective(whichColumn);}
    00577   inline const char * getColName(int whichColumn) const
    00578   { return getColumnName(whichColumn);}
    00581   inline bool getColIsInteger(int whichColumn) const
    00582   { return getColumnIsInteger(whichColumn);}
    00585   const char *  getRowLowerAsString(int whichRow) const ;
    00588   const char *  getRowUpperAsString(int whichRow) const ;
    00589   inline const char *  rowLowerAsString(int whichRow) const
    00590   { return getRowLowerAsString(whichRow);}
    00593   inline const char *  rowUpperAsString(int whichRow) const
    00594   { return getRowUpperAsString(whichRow) ;}
    00597   const char *  getColumnLowerAsString(int whichColumn) const ;
    00600   const char *  getColumnUpperAsString(int whichColumn) const ;
    00603   const char *  getColumnObjectiveAsString(int whichColumn) const ;
    00606   const char * getColumnIsIntegerAsString(int whichColumn) const ;
    00609   inline const char *  columnLowerAsString(int whichColumn) const
    00610   { return getColumnLowerAsString(whichColumn);}
    00613   inline const char *  columnUpperAsString(int whichColumn) const
    00614   { return getColumnUpperAsString(whichColumn) ;}
    00617   inline const char *  columnObjectiveAsString(int whichColumn) const
    00618   { return getColumnObjectiveAsString(whichColumn);}
    00621   inline const char *  objectiveAsString(int whichColumn) const
    00622   { return getColumnObjectiveAsString(whichColumn);}
    00625   inline const char * columnIsIntegerAsString(int whichColumn) const
    00626   { return getColumnIsIntegerAsString(whichColumn);}
    00629   inline const char * isIntegerAsString(int whichColumn) const
    00630   { return getColumnIsIntegerAsString(whichColumn);}
    00632   int row(const char * rowName) const;
    00634   int column(const char * columnName) const;
    00636   inline int type() const
    00637   { return type_;}
    00639   inline double unsetValue() const
    00640   { return -1.23456787654321e-97;}
    00642   int createPackedMatrix(CoinPackedMatrix & matrix,
    00643                          const double * associated);
    00649   int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00650                         const double * associated);
    00653   void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00654                          int * indices,
    00655                          const double * associated);
    00657   int createArrays(double * & rowLower, double * &  rowUpper,
    00658                    double * & columnLower, double * & columnUpper,
    00659                    double * & objective, int * & integerType,
    00660                    double * & associated);
    00662   inline bool stringsExist() const
    00663   { return string_.numberItems()!=0;}
    00665   inline const CoinModelHash * stringArray() const
    00666   { return &string_;}
    00668   inline double * associatedArray() const
    00669   { return associated_;}
    00671   inline double * rowLowerArray() const
    00672   { return rowLower_;}
    00674   inline double * rowUpperArray() const
    00675   { return rowUpper_;}
    00677   inline double * columnLowerArray() const
    00678   { return columnLower_;}
    00680   inline double * columnUpperArray() const
    00681   { return columnUpper_;}
    00683   inline double * objectiveArray() const
    00684   { return objective_;}
    00686   inline int * integerTypeArray() const
    00687   { return integerType_;}
    00689   inline const CoinModelHash * rowNames() const
    00690   { return &rowName_;}
    00692   inline const CoinModelHash * columnNames() const
    00693   { return &columnName_;}
    00695   inline const int * cutMarker() const
    00696   { return cut_;}
    00698   inline double optimizationDirection() const {
    00699     return  optimizationDirection_;
    00700   }
    00702   inline void setOptimizationDirection(double value)
    00703   { optimizationDirection_=value;}
    00705   inline void * moreInfo() const
    00706   { return moreInfo_;}
    00708   inline void setMoreInfo(void * info)
    00709   { moreInfo_ = info;}
    00718   int whatIsSet() const;
    00720
    00738   void loadBlock (const CoinPackedMatrix& matrix,
    00739                   const double* collb, const double* colub,
    00740                   const double* obj,
    00741                   const double* rowlb, const double* rowub) ;
    00758   void loadBlock (const CoinPackedMatrix& matrix,
    00759                   const double* collb, const double* colub,
    00760                   const double* obj,
    00761                   const char* rowsen, const double* rowrhs,
    00762                   const double* rowrng) ;
    00763
    00776   void loadBlock (const int numcols, const int numrows,
    00777                   const CoinBigIndex * start, const int* index,
    00778                   const double* value,
    00779                   const double* collb, const double* colub,
    00780                   const double* obj,
    00781                   const double* rowlb, const double* rowub) ;
    00782
    00795   void loadBlock (const int numcols, const int numrows,
    00796                   const CoinBigIndex * start, const int* index,
    00797                   const double* value,
    00798                   const double* collb, const double* colub,
    00799                   const double* obj,
    00800                   const char* rowsen, const double* rowrhs,
    00801                   const double* rowrng) ;
    00802
    00804
    00808    CoinModel();
    00811     CoinModel(const char *fileName, int allowStrings=0);
    00815     CoinModel( int nonLinear, const char * fileName,const void * info);
    00817   CoinModel(int numberRows, int numberColumns,
    00818             const CoinPackedMatrix * matrix,
    00819             const double * rowLower, const double * rowUpper,
    00820             const double * columnLower, const double * columnUpper,
    00821             const double * objective);
    00823   virtual CoinBaseModel * clone() const;
    00824
    00826    virtual ~CoinModel();
    00828
    00832    CoinModel(const CoinModel&);
    00834    CoinModel& operator=(const CoinModel&);
    00836
    00839
    00840   void validateLinks() const;
    00842 private:
    00844   void resize(int maximumRows, int maximumColumns, int maximumElements);
    00846   void fillRows(int which,bool forceCreation,bool fromAddRow=false);
    00848   void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
    00851   void fillList(int which, CoinModelLinkedList & list,int type) const ;
    00855   void createList(int type) const;
    00857   int addString(const char * string);
    00861   double getDoubleFromString(CoinYacc & info, const char * string);
    00863   void freeStringMemory(CoinYacc & info);
    00864 public:
    00866   int computeAssociated(double * associated);
    00872   CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
    00873                                   int & numberBad) const;
    00875   void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
    00880   CoinModel * reorder(const char * mark) const;
    00891   int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
    00892                      int * buildRow, double * buildElement,int reConstruct=-1) const;
    00894   void setCutMarker(int size,const int * marker);
    00896   void setPriorities(int size,const int * priorities);
    00898   inline const int * priorities() const
    00899   { return priority_;}
    00901   void setOriginalIndices(const int * row, const int * column);
    00902
    00903 private:
    00907   void gdb( int nonLinear, const char * fileName, const void * info);
    00909   int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
    00911   void badType() const;
    00914
    00915   int maximumRows_;
    00917   int maximumColumns_;
    00919   int numberElements_;
    00921   int maximumElements_;
    00923   int numberQuadraticElements_;
    00925   int maximumQuadraticElements_;
    00927   double * rowLower_;
    00929   double * rowUpper_;
    00931   CoinModelHash rowName_;
    00939   int * rowType_;
    00941   double * objective_;
    00943   double * columnLower_;
    00945   double * columnUpper_;
    00947   CoinModelHash columnName_;
    00949   int * integerType_;
    00951   CoinModelHash string_;
    00961   int * columnType_;
    00963   int * start_;
    00965   CoinModelTriple * elements_;
    00967   CoinPackedMatrix * packedMatrix_;
    00969   mutable CoinModelHash2 hashElements_;
    00971   mutable CoinModelLinkedList rowList_;
    00973   mutable CoinModelLinkedList columnList_;
    00975   CoinModelTriple * quadraticElements_;
    00977   mutable CoinModelHash2 hashQuadraticElements_;
    00979   int * sortIndices_;
    00981   double * sortElements_;
    00983   int sortSize_;
    00985   mutable CoinModelLinkedList quadraticRowList_;
    00987   mutable CoinModelLinkedList quadraticColumnList_;
    00989   int sizeAssociated_;
    00991   double * associated_;
    00993   int numberSOS_;
    00995   int * startSOS_;
    00997   int * memberSOS_;
    00999   int * typeSOS_;
    01001   int * prioritySOS_;
    01003   double * referenceSOS_;
    01005   int * priority_;
    01007   int * cut_;
    01009   void * moreInfo_;
    01017   mutable int type_;
    01024   mutable int links_;
    01026 };
    01028 double getFunctionValueFromString(const char * string, const char * x, double xValue);
    01030 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
    01031 #endif