/home/coin/CoinUtils-2.0.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 void * moreInfo() const
00576   { return moreInfo_;};
00578   inline void setMoreInfo(void * info)
00579   { moreInfo_ = info;};
00581 
00585    CoinModel();
00588     CoinModel(const char *fileName, int allowStrings=0);
00592     CoinModel( int nonLinear, const char * fileName,const void * info);
00594    ~CoinModel();
00596 
00600    CoinModel(const CoinModel&);
00602    CoinModel& operator=(const CoinModel&);
00604 
00607 
00608   void validateLinks() const;
00610 private:
00612   void resize(int maximumRows, int maximumColumns, int maximumElements);
00614   void fillRows(int which,bool forceCreation,bool fromAddRow=false);
00616   void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
00619   void fillList(int which, CoinModelLinkedList & list,int type) const ;
00623   void createList(int type) const;
00625   int addString(const char * string);
00629   double getDoubleFromString(CoinYacc & info, const char * string);
00631   void freeStringMemory(CoinYacc & info);
00632 public:
00634   int computeAssociated(double * associated);
00640   CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
00641                                   int & numberBad) const;
00643   void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
00648   CoinModel * reorder(const char * mark) const;
00659   int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
00660                      int * buildRow, double * buildElement,int reConstruct=-1) const;
00662   void setCutMarker(int size,const int * marker);
00664   void setPriorities(int size,const int * priorities);
00666   inline const int * priorities() const
00667   { return priority_;};
00668   
00669 private:
00673   void gdb( int nonLinear, const char * fileName, const void * info);
00675   int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
00678 
00679   int numberRows_;
00681   int maximumRows_;
00683   int numberColumns_;
00685   int maximumColumns_;
00687   int numberElements_;
00689   int maximumElements_;
00691   int numberQuadraticElements_;
00693   int maximumQuadraticElements_;
00695   double optimizationDirection_;
00697   double objectiveOffset_;
00699   char * problemName_;
00701   double * rowLower_;
00703   double * rowUpper_;
00705   CoinModelHash rowName_;
00711   int * rowType_;
00713   double * objective_;
00715   double * columnLower_;
00717   double * columnUpper_;
00719   CoinModelHash columnName_;
00721   int * integerType_;
00723   CoinModelHash string_;
00731   int * columnType_;
00733   int * start_;
00735   CoinModelTriple * elements_;
00737   mutable CoinModelHash2 hashElements_;
00739   mutable CoinModelLinkedList rowList_;
00741   mutable CoinModelLinkedList columnList_;
00743   CoinModelTriple * quadraticElements_;
00745   mutable CoinModelHash2 hashQuadraticElements_;
00747   int * sortIndices_;
00749   double * sortElements_;
00751   int sortSize_;
00753   mutable CoinModelLinkedList quadraticRowList_;
00755   mutable CoinModelLinkedList quadraticColumnList_;
00757   int sizeAssociated_;
00759   double * associated_;
00761   int numberSOS_;
00763   int * startSOS_;
00765   int * memberSOS_;
00767   int * typeSOS_;
00769   int * prioritySOS_;
00771   double * referenceSOS_;
00773   int * priority_;
00775   int * cut_;
00777   void * moreInfo_;
00785   int logLevel_;
00792   mutable int type_;
00799   mutable int links_;
00801 };
00803 double getFunctionValueFromString(const char * string, const char * x, double xValue);
00805 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
00806 #endif

Generated on Wed Aug 22 05:59:10 2007 by  doxygen 1.4.7