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

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.52.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
    00045 class CoinModel {
    00046
    00047 public:
    00051    void addRow(int numberInRow, const int * columns,
    00052                const double * elements, double rowLower=-COIN_DBL_MAX,
    00053               double rowUpper=COIN_DBL_MAX, const char * name=NULL);
    00055    void addColumn(int numberInColumn, const int * rows,
    00056                   const double * elements,
    00057                   double columnLower=0.0,
    00058                   double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00059                   const char * name=NULL, bool isInteger=false);
    00061   inline void addCol(int numberInColumn, const int * rows,
    00062                      const double * elements,
    00063                      double columnLower=0.0,
    00064                      double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
    00065                      const char * name=NULL, bool isInteger=false)
    00066   { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
    00067               name,isInteger);}
    00069   inline void operator() (int i,int j,double value)
    00070   { setElement(i,j,value);}
    00072   void setElement(int i,int j,double value) ;
    00078   int getRow(int whichRow, int * column, double * element);
    00084   int getColumn(int whichColumn, int * column, double * element);
    00086   void setQuadraticElement(int i,int j,double value) ;
    00088   inline void operator() (int i,int j,const char * value)
    00089   { setElement(i,j,value);}
    00091   void setElement(int i,int j,const char * value) ;
    00093   int associateElement(const char * stringValue, double value);
    00097   void setRowLower(int whichRow,double rowLower);
    00101   void setRowUpper(int whichRow,double rowUpper);
    00105   void setRowBounds(int whichRow,double rowLower,double rowUpper);
    00109   void setRowName(int whichRow,const char * rowName);
    00113   void setColumnLower(int whichColumn,double columnLower);
    00117   void setColumnUpper(int whichColumn,double columnUpper);
    00121   void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
    00125   void setColumnObjective(int whichColumn,double columnObjective);
    00129   void setColumnName(int whichColumn,const char * columnName);
    00133   void setColumnIsInteger(int whichColumn,bool columnIsInteger);
    00137   inline void setObjective(int whichColumn,double columnObjective)
    00138   { setColumnObjective( whichColumn, columnObjective);}
    00142   inline void setIsInteger(int whichColumn,bool columnIsInteger)
    00143   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00147   inline void setInteger(int whichColumn)
    00148   { setColumnIsInteger( whichColumn, true);}
    00152   inline void setContinuous(int whichColumn)
    00153   { setColumnIsInteger( whichColumn, false);}
    00157   inline void setColLower(int whichColumn,double columnLower)
    00158   { setColumnLower( whichColumn, columnLower);}
    00162   inline void setColUpper(int whichColumn,double columnUpper)
    00163   { setColumnUpper( whichColumn, columnUpper);}
    00167   inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
    00168   { setColumnBounds( whichColumn, columnLower, columnUpper);}
    00172   inline void setColObjective(int whichColumn,double columnObjective)
    00173   { setColumnObjective( whichColumn, columnObjective);}
    00177   inline void setColName(int whichColumn,const char * columnName)
    00178   { setColumnName( whichColumn, columnName);}
    00182   inline void setColIsInteger(int whichColumn,bool columnIsInteger)
    00183   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00187   void setRowLower(int whichRow,const char * rowLower);
    00191   void setRowUpper(int whichRow,const char * rowUpper);
    00195   void setColumnLower(int whichColumn,const char * columnLower);
    00199   void setColumnUpper(int whichColumn,const char * columnUpper);
    00203   void setColumnObjective(int whichColumn,const char * columnObjective);
    00207   void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
    00211   inline void setObjective(int whichColumn,const char * columnObjective)
    00212   { setColumnObjective( whichColumn, columnObjective);}
    00216   inline void setIsInteger(int whichColumn,const char * columnIsInteger)
    00217   { setColumnIsInteger( whichColumn, columnIsInteger);}
    00220   void deleteRow(int whichRow);
    00223   void deleteColumn(int whichColumn);
    00226   inline void deleteCol(int whichColumn)
    00227   { deleteColumn(whichColumn);}
    00229   int deleteElement(int row, int column);
    00231   void deleteThisElement(int row, int column,int position);
    00234   int packRows();
    00237   int packColumns();
    00240   inline int packCols()
    00241   { return packColumns();}
    00246   int pack();
    00247
    00273   int writeMps(const char *filename, int compression = 0,
    00274                int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
    00275
    00280   int differentModel(CoinModel & other, bool ignoreNames);
    00282
    00283
    00286
    00287   inline int numberRows() const
    00288   { return numberRows_;}
    00290   inline int numberColumns() const
    00291   { return numberColumns_;}
    00293   inline CoinBigIndex numberElements() const
    00294   { return numberElements_;}
    00296   inline const CoinModelTriple * elements() const
    00297   { return elements_;}
    00299   inline double operator() (int i,int j) const
    00300   { return getElement(i,j);}
    00302   double getElement(int i,int j) const;
    00304   inline double operator() (const char * rowName,const char * columnName) const
    00305   { return getElement(rowName,columnName);}
    00307   double getElement(const char * rowName,const char * columnName) const;
    00309   double getQuadraticElement(int i,int j) const;
    00314   const char * getElementAsString(int i,int j) const;
    00318   double * pointer (int i,int j) const;
    00322   int position (int i,int j) const;
    00323
    00324
    00328   CoinModelLink firstInRow(int whichRow) const ;
    00332   CoinModelLink lastInRow(int whichRow) const ;
    00336   CoinModelLink firstInColumn(int whichColumn) const ;
    00340   CoinModelLink lastInColumn(int whichColumn) const ;
    00345   CoinModelLink next(CoinModelLink & current) const ;
    00351   CoinModelLink previous(CoinModelLink & current) const ;
    00356   CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
    00360   CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
    00363   double  getRowLower(int whichRow) const ;
    00366   double  getRowUpper(int whichRow) const ;
    00369   const char * getRowName(int whichRow) const ;
    00370   inline double  rowLower(int whichRow) const
    00371   { return getRowLower(whichRow);}
    00374   inline double  rowUpper(int whichRow) const
    00375   { return getRowUpper(whichRow) ;}
    00378   inline const char * rowName(int whichRow) const
    00379   { return getRowName(whichRow);}
    00382   double  getColumnLower(int whichColumn) const ;
    00385   double  getColumnUpper(int whichColumn) const ;
    00388   double  getColumnObjective(int whichColumn) const ;
    00391   const char * getColumnName(int whichColumn) const ;
    00394   bool getColumnIsInteger(int whichColumn) const ;
    00397   inline double  columnLower(int whichColumn) const
    00398   { return getColumnLower(whichColumn);}
    00401   inline double  columnUpper(int whichColumn) const
    00402   { return getColumnUpper(whichColumn) ;}
    00405   inline double  columnObjective(int whichColumn) const
    00406   { return getColumnObjective(whichColumn);}
    00409   inline double  objective(int whichColumn) const
    00410   { return getColumnObjective(whichColumn);}
    00413   inline const char * columnName(int whichColumn) const
    00414   { return getColumnName(whichColumn);}
    00417   inline bool columnIsInteger(int whichColumn) const
    00418   { return getColumnIsInteger(whichColumn);}
    00421   inline bool isInteger(int whichColumn) const
    00422   { return getColumnIsInteger(whichColumn);}
    00425   inline double  getColLower(int whichColumn) const
    00426   { return getColumnLower(whichColumn);}
    00429   inline double  getColUpper(int whichColumn) const
    00430   { return getColumnUpper(whichColumn) ;}
    00433   inline double  getColObjective(int whichColumn) const
    00434   { return getColumnObjective(whichColumn);}
    00437   inline const char * getColName(int whichColumn) const
    00438   { return getColumnName(whichColumn);}
    00441   inline bool getColIsInteger(int whichColumn) const
    00442   { return getColumnIsInteger(whichColumn);}
    00445   const char *  getRowLowerAsString(int whichRow) const ;
    00448   const char *  getRowUpperAsString(int whichRow) const ;
    00449   inline const char *  rowLowerAsString(int whichRow) const
    00450   { return getRowLowerAsString(whichRow);}
    00453   inline const char *  rowUpperAsString(int whichRow) const
    00454   { return getRowUpperAsString(whichRow) ;}
    00457   const char *  getColumnLowerAsString(int whichColumn) const ;
    00460   const char *  getColumnUpperAsString(int whichColumn) const ;
    00463   const char *  getColumnObjectiveAsString(int whichColumn) const ;
    00466   const char * getColumnIsIntegerAsString(int whichColumn) const ;
    00469   inline const char *  columnLowerAsString(int whichColumn) const
    00470   { return getColumnLowerAsString(whichColumn);}
    00473   inline const char *  columnUpperAsString(int whichColumn) const
    00474   { return getColumnUpperAsString(whichColumn) ;}
    00477   inline const char *  columnObjectiveAsString(int whichColumn) const
    00478   { return getColumnObjectiveAsString(whichColumn);}
    00481   inline const char *  objectiveAsString(int whichColumn) const
    00482   { return getColumnObjectiveAsString(whichColumn);}
    00485   inline const char * columnIsIntegerAsString(int whichColumn) const
    00486   { return getColumnIsIntegerAsString(whichColumn);}
    00489   inline const char * isIntegerAsString(int whichColumn) const
    00490   { return getColumnIsIntegerAsString(whichColumn);}
    00492   int row(const char * rowName) const;
    00494   int column(const char * columnName) const;
    00498   inline double objectiveOffset() const
    00499   { return objectiveOffset_;}
    00501   inline void setObjectiveOffset(double value)
    00502   { objectiveOffset_=value;}
    00504   inline int logLevel() const
    00505   { return logLevel_;}
    00507   void setLogLevel(int value);
    00509   inline const char * getProblemName() const
    00510   { return problemName_;}
    00512   void setProblemName(const char *name) ;
    00514   inline int type() const
    00515   { return type_;}
    00517   inline double unsetValue() const
    00518   { return -1.23456787654321e-97;}
    00520   int createPackedMatrix(CoinPackedMatrix & matrix, const double * associated);
    00526   int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00527                         const double * associated);
    00530   void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
    00531                          int * indices,
    00532                          const double * associated);
    00534   int createArrays(double * & rowLower, double * &  rowUpper,
    00535                    double * & columnLower, double * & columnUpper,
    00536                    double * & objective, int * & integerType,
    00537                    double * & associated);
    00539   inline bool stringsExist() const
    00540   { return string_.numberItems()!=0;}
    00542   inline const CoinModelHash * stringArray() const
    00543   { return &string_;}
    00545   inline double * associatedArray() const
    00546   { return associated_;}
    00548   inline double * rowLowerArray() const
    00549   { return rowLower_;}
    00551   inline double * rowUpperArray() const
    00552   { return rowUpper_;}
    00554   inline double * columnLowerArray() const
    00555   { return columnLower_;}
    00557   inline double * columnUpperArray() const
    00558   { return columnUpper_;}
    00560   inline double * objectiveArray() const
    00561   { return objective_;}
    00563   inline int * integerTypeArray() const
    00564   { return integerType_;}
    00566   inline const CoinModelHash * rowNames() const
    00567   { return &rowName_;}
    00569   inline const CoinModelHash * columnNames() const
    00570   { return &columnName_;}
    00572   inline const int * cutMarker() const
    00573   { return cut_;}
    00575   inline double optimizationDirection() const {
    00576     return  optimizationDirection_;
    00577   }
    00579   inline void setOptimizationDirection(double value)
    00580   { optimizationDirection_=value;}
    00582   inline void * moreInfo() const
    00583   { return moreInfo_;}
    00585   inline void setMoreInfo(void * info)
    00586   { moreInfo_ = info;}
    00588
    00592    CoinModel();
    00595     CoinModel(const char *fileName, int allowStrings=0);
    00599     CoinModel( int nonLinear, const char * fileName,const void * info);
    00601    ~CoinModel();
    00603
    00607    CoinModel(const CoinModel&);
    00609    CoinModel& operator=(const CoinModel&);
    00611
    00614
    00615   void validateLinks() const;
    00617 private:
    00619   void resize(int maximumRows, int maximumColumns, int maximumElements);
    00621   void fillRows(int which,bool forceCreation,bool fromAddRow=false);
    00623   void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
    00626   void fillList(int which, CoinModelLinkedList & list,int type) const ;
    00630   void createList(int type) const;
    00632   int addString(const char * string);
    00636   double getDoubleFromString(CoinYacc & info, const char * string);
    00638   void freeStringMemory(CoinYacc & info);
    00639 public:
    00641   int computeAssociated(double * associated);
    00647   CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
    00648                                   int & numberBad) const;
    00650   void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
    00655   CoinModel * reorder(const char * mark) const;
    00666   int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
    00667                      int * buildRow, double * buildElement,int reConstruct=-1) const;
    00669   void setCutMarker(int size,const int * marker);
    00671   void setPriorities(int size,const int * priorities);
    00673   inline const int * priorities() const
    00674   { return priority_;}
    00675
    00676 private:
    00680   void gdb( int nonLinear, const char * fileName, const void * info);
    00682   int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
    00685
    00686   int numberRows_;
    00688   int maximumRows_;
    00690   int numberColumns_;
    00692   int maximumColumns_;
    00694   int numberElements_;
    00696   int maximumElements_;
    00698   int numberQuadraticElements_;
    00700   int maximumQuadraticElements_;
    00702   double optimizationDirection_;
    00704   double objectiveOffset_;
    00706   char * problemName_;
    00708   double * rowLower_;
    00710   double * rowUpper_;
    00712   CoinModelHash rowName_;
    00718   int * rowType_;
    00720   double * objective_;
    00722   double * columnLower_;
    00724   double * columnUpper_;
    00726   CoinModelHash columnName_;
    00728   int * integerType_;
    00730   CoinModelHash string_;
    00738   int * columnType_;
    00740   int * start_;
    00742   CoinModelTriple * elements_;
    00744   mutable CoinModelHash2 hashElements_;
    00746   mutable CoinModelLinkedList rowList_;
    00748   mutable CoinModelLinkedList columnList_;
    00750   CoinModelTriple * quadraticElements_;
    00752   mutable CoinModelHash2 hashQuadraticElements_;
    00754   int * sortIndices_;
    00756   double * sortElements_;
    00758   int sortSize_;
    00760   mutable CoinModelLinkedList quadraticRowList_;
    00762   mutable CoinModelLinkedList quadraticColumnList_;
    00764   int sizeAssociated_;
    00766   double * associated_;
    00768   int numberSOS_;
    00770   int * startSOS_;
    00772   int * memberSOS_;
    00774   int * typeSOS_;
    00776   int * prioritySOS_;
    00778   double * referenceSOS_;
    00780   int * priority_;
    00782   int * cut_;
    00784   void * moreInfo_;
    00792   int logLevel_;
    00799   mutable int type_;
    00806   mutable int links_;
    00808 };
    00810 double getFunctionValueFromString(const char * string, const char * x, double xValue);
    00812 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
    00813 #endif