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

- File List
- File Members

# /home/coin/SVN-release/Vol-1.2.0/CoinUtils/src/CoinModel.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinModel.hpp 1191 2009-07-25 08:38:12Z forrest $ */
    00002 // Copyright (C) 2005, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 #ifndef CoinModel_H
    00005 #define CoinModel_H
    00006
    00007 #include "CoinModelUseful.hpp"
    00008 #include "CoinPackedMatrix.hpp"
    00009 class CoinBaseModel {
    00010
    00011 public:
    00012
    00013
    00016
    00017   CoinBaseModel ();
    00018
    00020   CoinBaseModel ( const CoinBaseModel &rhs);
    00021
    00023   CoinBaseModel & operator=( const CoinBaseModel& rhs);
    00024
    00026   virtual CoinBaseModel * clone() const=0;
    00027
    00029   virtual ~CoinBaseModel () ;
    00031
    00034
    00035   inline int numberRows() const
    00036   { return numberRows_;}
    00038   inline int numberColumns() const
    00039   { return numberColumns_;}
    00041   virtual CoinBigIndex numberElements() const = 0;
    00045   inline double objectiveOffset() const
    00046   { return objectiveOffset_;}
    00048   inline void setObjectiveOffset(double value)
    00049   { objectiveOffset_=value;}
    00051   inline double optimizationDirection() const {
    00052     return  optimizationDirection_;
    00053   }
    00055   inline void setOptimizationDirection(double value)
    00056   { optimizationDirection_=value;}
    00058   inline int logLevel() const
    00059   { return logLevel_;}
    00061   void setLogLevel(int value);
    00063   inline const char * getProblemName() const
    00064   { return problemName_.c_str();}
    00066   void setProblemName(const char *name) ;
    00068   void setProblemName(const std::string &name) ;
    00070   inline const std::string & getRowBlock() const
    00071   { return rowBlockName_;}
    00073   inline void setRowBlock(const std::string &name)
    00074   { rowBlockName_ = name;}
    00076   inline const std::string & getColumnBlock() const
    00077   { return columnBlockName_;}
    00079   inline void setColumnBlock(const std::string &name)
    00080   { columnBlockName_ = name;}
    00082
    00083 protected:
    00086
    00087   int numberRows_;
    00089   int numberColumns_;
    00091   double optimizationDirection_;
    00093   double objectiveOffset_;
    00095   std::string problemName_;
    00097   std::string rowBlockName_;
    00099   std::string columnBlockName_;
    00107   int logLevel_;
    00109
    00110
    00111 };
    00112
    00149 class CoinModel : public CoinBaseModel {
    00150
    00151 public:
    00155    void addRow(int numberInRow, const int * columns,
    00156                const double * elements, double rowLower=-COIN_DBL_MAX,
    00157               double rowUpper=COIN_DBL_MAX, const char * name=NULL);
    00159    void addColumn(int numberInColumn, const int * rows,
    00160                   const double * elements,
    00161                   double columnLower=0.0,
    00162                   double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00163                   const char * name=NULL, bool isInteger=false);
    00165   inline void addCol(int numberInColumn, const int * rows,
    00166                      const double * elements,
    00167                      double columnLower=0.0,
    00168                      double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00169                      const char * name=NULL, bool isInteger=false)
    00170   { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
    00171               name,isInteger);}
    00173   inline void operator() (int i,int j,double value)
    00174   { setElement(i,j,value);}
    00176   void setElement(int i,int j,double value) ;
    00182   int getRow(int whichRow, int * column, double * element);
    00188   int getColumn(int whichColumn, int * column, double * element);
    00190   void setQuadraticElement(int i,int j,double value) ;
    00192   inline void operator() (int i,int j,const char * value)
    00193   { setElement(i,j,value);}
    00195   void setElement(int i,int j,const char * value) ;
    00197   int associateElement(const char * stringValue, double value);
    00201   void setRowLower(int whichRow,double rowLower);
    00205   void setRowUpper(int whichRow,double rowUpper);
    00209   void setRowBounds(int whichRow,double rowLower,double rowUpper);
    00213   void setRowName(int whichRow,const char * rowName);
    00217   void setColumnLower(int whichColumn,double columnLower);
    00221   void setColumnUpper(int whichColumn,double columnUpper);
    00225   void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
    00229   void setColumnObjective(int whichColumn,double columnObjective);
    00233   void setColumnName(int whichColumn,const char * columnName);
    00237   void setColumnIsInteger(int whichColumn,bool columnIsInteger);
    00241   inline void setObjective(int whichColumn,double columnObjective)
    00242   { setColumnObjective( whichColumn, columnObjective);}
    00246   inline void setIsInteger(int whichColumn,bool columnIsInteger)
    00247   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00251   inline void setInteger(int whichColumn)
    00252   { setColumnIsInteger( whichColumn, true);}
    00256   inline void setContinuous(int whichColumn)
    00257   { setColumnIsInteger( whichColumn, false);}
    00261   inline void setColLower(int whichColumn,double columnLower)
    00262   { setColumnLower( whichColumn, columnLower);}
    00266   inline void setColUpper(int whichColumn,double columnUpper)
    00267   { setColumnUpper( whichColumn, columnUpper);}
    00271   inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
    00272   { setColumnBounds( whichColumn, columnLower, columnUpper);}
    00276   inline void setColObjective(int whichColumn,double columnObjective)
    00277   { setColumnObjective( whichColumn, columnObjective);}
    00281   inline void setColName(int whichColumn,const char * columnName)
    00282   { setColumnName( whichColumn, columnName);}
    00286   inline void setColIsInteger(int whichColumn,bool columnIsInteger)
    00287   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00291   void setRowLower(int whichRow,const char * rowLower);
    00295   void setRowUpper(int whichRow,const char * rowUpper);
    00299   void setColumnLower(int whichColumn,const char * columnLower);
    00303   void setColumnUpper(int whichColumn,const char * columnUpper);
    00307   void setColumnObjective(int whichColumn,const char * columnObjective);
    00311   void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
    00315   inline void setObjective(int whichColumn,const char * columnObjective)
    00316   { setColumnObjective( whichColumn, columnObjective);}
    00320   inline void setIsInteger(int whichColumn,const char * columnIsInteger)
    00321   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00324   void deleteRow(int whichRow);
    00327   void deleteColumn(int whichColumn);
    00330   inline void deleteCol(int whichColumn)
    00331   { deleteColumn(whichColumn);}
    00333   int deleteElement(int row, int column);
    00335   void deleteThisElement(int row, int column,int position);
    00338   int packRows();
    00341   int packColumns();
    00344   inline int packCols()
    00345   { return packColumns();}
    00350   int pack();
    00351
    00354   void setObjective(int numberColumns,const double * objective) ;
    00357   void setColumnLower(int numberColumns,const double * columnLower);
    00360   inline void setColLower(int numberColumns,const double * columnLower)
    00361   { setColumnLower( numberColumns, columnLower);}
    00364   void setColumnUpper(int numberColumns,const double * columnUpper);
    00367   inline void setColUpper(int numberColumns,const double * columnUpper)
    00368   { setColumnUpper( numberColumns, columnUpper);}
    00371   void setRowLower(int numberRows,const double * rowLower);
    00374   void setRowUpper(int numberRows,const double * rowUpper);
    00375
    00401   int writeMps(const char *filename, int compression = 0,
    00402                int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
    00403
    00408   int differentModel(CoinModel & other, bool ignoreNames);
    00410
    00411
    00414
    00415   void passInMatrix(const CoinPackedMatrix & matrix);
    00418   int convertMatrix();
    00420   inline const CoinPackedMatrix * packedMatrix() const
    00421   { return packedMatrix_;}
    00423   inline const int * originalRows() const
    00424   { return rowType_;}
    00426   inline const int * originalColumns() const
    00427   { return columnType_;}
    00429
    00430
    00433
    00434   inline CoinBigIndex numberElements() const
    00435   { return numberElements_;}
    00437   inline const CoinModelTriple * elements() const
    00438   { return elements_;}
    00440   inline double operator() (int i,int j) const
    00441   { return getElement(i,j);}
    00443   double getElement(int i,int j) const;
    00445   inline double operator() (const char * rowName,const char * columnName) const
    00446   { return getElement(rowName,columnName);}
    00448   double getElement(const char * rowName,const char * columnName) const;
    00450   double getQuadraticElement(int i,int j) const;
    00455   const char * getElementAsString(int i,int j) const;
    00459   double * pointer (int i,int j) const;
    00463   int position (int i,int j) const;
    00464
    00465
    00469   CoinModelLink firstInRow(int whichRow) const ;
    00473   CoinModelLink lastInRow(int whichRow) const ;
    00477   CoinModelLink firstInColumn(int whichColumn) const ;
    00481   CoinModelLink lastInColumn(int whichColumn) const ;
    00486   CoinModelLink next(CoinModelLink & current) const ;
    00492   CoinModelLink previous(CoinModelLink & current) const ;
    00497   CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
    00501   CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
    00504   double  getRowLower(int whichRow) const ;
    00507   double  getRowUpper(int whichRow) const ;
    00510   const char * getRowName(int whichRow) const ;
    00511   inline double  rowLower(int whichRow) const
    00512   { return getRowLower(whichRow);}
    00515   inline double  rowUpper(int whichRow) const
    00516   { return getRowUpper(whichRow) ;}
    00519   inline const char * rowName(int whichRow) const
    00520   { return getRowName(whichRow);}
    00523   double  getColumnLower(int whichColumn) const ;
    00526   double  getColumnUpper(int whichColumn) const ;
    00529   double  getColumnObjective(int whichColumn) const ;
    00532   const char * getColumnName(int whichColumn) const ;
    00535   bool getColumnIsInteger(int whichColumn) const ;
    00538   inline double  columnLower(int whichColumn) const
    00539   { return getColumnLower(whichColumn);}
    00542   inline double  columnUpper(int whichColumn) const
    00543   { return getColumnUpper(whichColumn) ;}
    00546   inline double  columnObjective(int whichColumn) const
    00547   { return getColumnObjective(whichColumn);}
    00550   inline double  objective(int whichColumn) const
    00551   { return getColumnObjective(whichColumn);}
    00554   inline const char * columnName(int whichColumn) const
    00555   { return getColumnName(whichColumn);}
    00558   inline bool columnIsInteger(int whichColumn) const
    00559   { return getColumnIsInteger(whichColumn);}
    00562   inline bool isInteger(int whichColumn) const
    00563   { return getColumnIsInteger(whichColumn);}
    00566   inline double  getColLower(int whichColumn) const
    00567   { return getColumnLower(whichColumn);}
    00570   inline double  getColUpper(int whichColumn) const
    00571   { return getColumnUpper(whichColumn) ;}
    00574   inline double  getColObjective(int whichColumn) const
    00575   { return getColumnObjective(whichColumn);}
    00578   inline const char * getColName(int whichColumn) const
    00579   { return getColumnName(whichColumn);}
    00582   inline bool getColIsInteger(int whichColumn) const
    00583   { return getColumnIsInteger(whichColumn);}
    00586   const char *  getRowLowerAsString(int whichRow) const ;
    00589   const char *  getRowUpperAsString(int whichRow) const ;
    00590   inline const char *  rowLowerAsString(int whichRow) const
    00591   { return getRowLowerAsString(whichRow);}
    00594   inline const char *  rowUpperAsString(int whichRow) const
    00595   { return getRowUpperAsString(whichRow) ;}
    00598   const char *  getColumnLowerAsString(int whichColumn) const ;
    00601   const char *  getColumnUpperAsString(int whichColumn) const ;
    00604   const char *  getColumnObjectiveAsString(int whichColumn) const ;
    00607   const char * getColumnIsIntegerAsString(int whichColumn) const ;
    00610   inline const char *  columnLowerAsString(int whichColumn) const
    00611   { return getColumnLowerAsString(whichColumn);}
    00614   inline const char *  columnUpperAsString(int whichColumn) const
    00615   { return getColumnUpperAsString(whichColumn) ;}
    00618   inline const char *  columnObjectiveAsString(int whichColumn) const
    00619   { return getColumnObjectiveAsString(whichColumn);}
    00622   inline const char *  objectiveAsString(int whichColumn) const
    00623   { return getColumnObjectiveAsString(whichColumn);}
    00626   inline const char * columnIsIntegerAsString(int whichColumn) const
    00627   { return getColumnIsIntegerAsString(whichColumn);}
    00630   inline const char * isIntegerAsString(int whichColumn) const
    00631   { return getColumnIsIntegerAsString(whichColumn);}
    00633   int row(const char * rowName) const;
    00635   int column(const char * columnName) const;
    00637   inline int type() const
    00638   { return type_;}
    00640   inline double unsetValue() const
    00641   { return -1.23456787654321e-97;}
    00643   int createPackedMatrix(CoinPackedMatrix & matrix,
    00644                          const double * associated);
    00650   int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00651                         const double * associated);
    00654   void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00655                          int * indices,
    00656                          const double * associated);
    00658   int createArrays(double * & rowLower, double * &  rowUpper,
    00659                    double * & columnLower, double * & columnUpper,
    00660                    double * & objective, int * & integerType,
    00661                    double * & associated);
    00663   inline bool stringsExist() const
    00664   { return string_.numberItems()!=0;}
    00666   inline const CoinModelHash * stringArray() const
    00667   { return &string_;}
    00669   inline double * associatedArray() const
    00670   { return associated_;}
    00672   inline double * rowLowerArray() const
    00673   { return rowLower_;}
    00675   inline double * rowUpperArray() const
    00676   { return rowUpper_;}
    00678   inline double * columnLowerArray() const
    00679   { return columnLower_;}
    00681   inline double * columnUpperArray() const
    00682   { return columnUpper_;}
    00684   inline double * objectiveArray() const
    00685   { return objective_;}
    00687   inline int * integerTypeArray() const
    00688   { return integerType_;}
    00690   inline const CoinModelHash * rowNames() const
    00691   { return &rowName_;}
    00693   inline const CoinModelHash * columnNames() const
    00694   { return &columnName_;}
    00696   inline const int * cutMarker() const
    00697   { return cut_;}
    00699   inline double optimizationDirection() const {
    00700     return  optimizationDirection_;
    00701   }
    00703   inline void setOptimizationDirection(double value)
    00704   { optimizationDirection_=value;}
    00706   inline void * moreInfo() const
    00707   { return moreInfo_;}
    00709   inline void setMoreInfo(void * info)
    00710   { moreInfo_ = info;}
    00719   int whatIsSet() const;
    00721
    00739   void loadBlock (const CoinPackedMatrix& matrix,
    00740                   const double* collb, const double* colub,
    00741                   const double* obj,
    00742                   const double* rowlb, const double* rowub) ;
    00759   void loadBlock (const CoinPackedMatrix& matrix,
    00760                   const double* collb, const double* colub,
    00761                   const double* obj,
    00762                   const char* rowsen, const double* rowrhs,
    00763                   const double* rowrng) ;
    00764
    00777   void loadBlock (const int numcols, const int numrows,
    00778                   const CoinBigIndex * start, const int* index,
    00779                   const double* value,
    00780                   const double* collb, const double* colub,
    00781                   const double* obj,
    00782                   const double* rowlb, const double* rowub) ;
    00783
    00796   void loadBlock (const int numcols, const int numrows,
    00797                   const CoinBigIndex * start, const int* index,
    00798                   const double* value,
    00799                   const double* collb, const double* colub,
    00800                   const double* obj,
    00801                   const char* rowsen, const double* rowrhs,
    00802                   const double* rowrng) ;
    00803
    00805
    00809    CoinModel();
    00812     CoinModel(const char *fileName, int allowStrings=0);
    00816     CoinModel( int nonLinear, const char * fileName,const void * info);
    00818   CoinModel(int numberRows, int numberColumns,
    00819             const CoinPackedMatrix * matrix,
    00820             const double * rowLower, const double * rowUpper,
    00821             const double * columnLower, const double * columnUpper,
    00822             const double * objective);
    00824   virtual CoinBaseModel * clone() const;
    00825
    00827    virtual ~CoinModel();
    00829
    00833    CoinModel(const CoinModel&);
    00835    CoinModel& operator=(const CoinModel&);
    00837
    00840
    00841   void validateLinks() const;
    00843 private:
    00845   void resize(int maximumRows, int maximumColumns, int maximumElements);
    00847   void fillRows(int which,bool forceCreation,bool fromAddRow=false);
    00849   void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
    00852   void fillList(int which, CoinModelLinkedList & list,int type) const ;
    00856   void createList(int type) const;
    00858   int addString(const char * string);
    00862   double getDoubleFromString(CoinYacc & info, const char * string);
    00864   void freeStringMemory(CoinYacc & info);
    00865 public:
    00867   int computeAssociated(double * associated);
    00873   CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
    00874                                   int & numberBad) const;
    00876   void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
    00881   CoinModel * reorder(const char * mark) const;
    00892   int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
    00893                      int * buildRow, double * buildElement,int reConstruct=-1) const;
    00895   void setCutMarker(int size,const int * marker);
    00897   void setPriorities(int size,const int * priorities);
    00899   inline const int * priorities() const
    00900   { return priority_;}
    00902   void setOriginalIndices(const int * row, const int * column);
    00903
    00904 private:
    00908   void gdb( int nonLinear, const char * fileName, const void * info);
    00910   int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
    00912   void badType() const;
    00915
    00916   int maximumRows_;
    00918   int maximumColumns_;
    00920   int numberElements_;
    00922   int maximumElements_;
    00924   int numberQuadraticElements_;
    00926   int maximumQuadraticElements_;
    00928   double * rowLower_;
    00930   double * rowUpper_;
    00932   CoinModelHash rowName_;
    00940   int * rowType_;
    00942   double * objective_;
    00944   double * columnLower_;
    00946   double * columnUpper_;
    00948   CoinModelHash columnName_;
    00950   int * integerType_;
    00952   CoinModelHash string_;
    00962   int * columnType_;
    00964   int * start_;
    00966   CoinModelTriple * elements_;
    00968   CoinPackedMatrix * packedMatrix_;
    00970   mutable CoinModelHash2 hashElements_;
    00972   mutable CoinModelLinkedList rowList_;
    00974   mutable CoinModelLinkedList columnList_;
    00976   CoinModelTriple * quadraticElements_;
    00978   mutable CoinModelHash2 hashQuadraticElements_;
    00980   int * sortIndices_;
    00982   double * sortElements_;
    00984   int sortSize_;
    00986   mutable CoinModelLinkedList quadraticRowList_;
    00988   mutable CoinModelLinkedList quadraticColumnList_;
    00990   int sizeAssociated_;
    00992   double * associated_;
    00994   int numberSOS_;
    00996   int * startSOS_;
    00998   int * memberSOS_;
    01000   int * typeSOS_;
    01002   int * prioritySOS_;
    01004   double * referenceSOS_;
    01006   int * priority_;
    01008   int * cut_;
    01010   void * moreInfo_;
    01018   mutable int type_;
    01025   mutable int links_;
    01027 };
    01029 double getFunctionValueFromString(const char * string, const char * x, double xValue);
    01031 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
    01032 #endif