Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

/files2/home/rwaltz/Software/COIN/Clp/include/ClpModel.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef ClpModel_H
00004 #define ClpModel_H
00005 
00006 #include <iostream>
00007 #include <cassert>
00008 #include <cmath>
00009 #include <vector>
00010 #include <string>
00011 
00012 #include "ClpMatrixBase.hpp"
00013 #include "CoinMessageHandler.hpp"
00014 #include "ClpParameters.hpp"
00015 #include "ClpObjective.hpp"
00016 class ClpEventHandler;
00017 
00018 // Plus infinity
00019 #ifndef COIN_DBL_MAX
00020 #define COIN_DBL_MAX DBL_MAX
00021 #endif
00022 
00033 class ClpModel {
00034 
00035 public:
00036 
00042 
00043     ClpModel (  );
00044 
00049     ClpModel(const ClpModel & rhs, int scalingMode=-1);
00051     ClpModel & operator=(const ClpModel & rhs);
00056     ClpModel (const ClpModel * wholeModel,
00057       int numberRows, const int * whichRows,
00058       int numberColumns, const int * whichColumns,
00059               bool dropNames=true, bool dropIntegers=true);
00061     ~ClpModel (  );
00063 
00077   void loadProblem (  const ClpMatrixBase& matrix,
00078                      const double* collb, const double* colub,   
00079                      const double* obj,
00080                      const double* rowlb, const double* rowub,
00081                       const double * rowObjective=NULL);
00082   void loadProblem (  const CoinPackedMatrix& matrix,
00083                      const double* collb, const double* colub,   
00084                      const double* obj,
00085                      const double* rowlb, const double* rowub,
00086                       const double * rowObjective=NULL);
00087 
00090   void loadProblem (  const int numcols, const int numrows,
00091                      const CoinBigIndex* start, const int* index,
00092                      const double* value,
00093                      const double* collb, const double* colub,   
00094                      const double* obj,
00095                       const double* rowlb, const double* rowub,
00096                       const double * rowObjective=NULL);
00098   void loadProblem (  const int numcols, const int numrows,
00099                      const CoinBigIndex* start, const int* index,
00100                       const double* value,const int * length,
00101                      const double* collb, const double* colub,   
00102                      const double* obj,
00103                       const double* rowlb, const double* rowub,
00104                       const double * rowObjective=NULL);
00106   void loadQuadraticObjective(const int numberColumns, 
00107                               const CoinBigIndex * start,
00108                               const int * column, const double * element);
00109   void loadQuadraticObjective (  const CoinPackedMatrix& matrix);
00111   void deleteQuadraticObjective();
00113   void setRowObjective(const double * rowObjective);
00115   int readMps(const char *filename,
00116               bool keepNames=false,
00117               bool ignoreErrors = false);
00119   void copyInIntegerInformation(const char * information);
00121   void deleteIntegerInformation();
00123   void resize (int newNumberRows, int newNumberColumns);
00125   void deleteRows(int number, const int * which);
00127   void addRows(int number, const double * rowLower, 
00128                const double * rowUpper,
00129                const int * rowStarts, const int * columns,
00130                const double * elements);
00132   void addRows(int number, const double * rowLower, 
00133                const double * rowUpper,
00134                const int * rowStarts, const int * rowLengths,
00135                const int * columns,
00136                const double * elements);
00137   void addRows(int number, const double * rowLower, 
00138                const double * rowUpper,
00139                const CoinPackedVectorBase * const * rows);
00140 
00142   void deleteColumns(int number, const int * which);
00144   void addColumns(int number, const double * columnLower, 
00145                   const double * columnUpper,
00146                   const double * objective,
00147                   const int * columnStarts, const int * rows,
00148                   const double * elements);
00149   void addColumns(int number, const double * columnLower, 
00150                   const double * columnUpper,
00151                   const double * objective,
00152                   const int * columnStarts, const int * columnLengths,
00153                   const int * rows,
00154                   const double * elements);
00155   void addColumns(int number, const double * columnLower, 
00156                const double * columnUpper,
00157                   const double * objective,
00158                const CoinPackedVectorBase * const * columns);
00162   void borrowModel(ClpModel & otherModel);
00165   void returnModel(ClpModel & otherModel);
00166 
00168   void createEmptyMatrix();
00170   void dropNames();
00172   void copyNames(std::vector<std::string> & rowNames,
00173                  std::vector<std::string> & columnNames);
00174   
00187     int writeMps(const char *filename, 
00188                   int formatType=0,int numberAcross=2,
00189                  double objSense=0.0) const ;
00191 
00193 
00194    inline int numberRows() const {
00195       return numberRows_;
00196    }
00197    inline int getNumRows() const {
00198       return numberRows_;
00199    }
00201    inline int getNumCols() const {
00202       return numberColumns_;
00203    }
00204    inline int numberColumns() const {
00205       return numberColumns_;
00206    }
00208    inline double primalTolerance() const {
00209       return dblParam_[ClpPrimalTolerance];
00210    }
00211    void setPrimalTolerance( double value) ;
00213    inline double dualTolerance() const  { return dblParam_[ClpDualTolerance]; }
00214    void setDualTolerance( double value) ;
00216   inline double dualObjectiveLimit() const { return dblParam_[ClpDualObjectiveLimit];}
00217   void setDualObjectiveLimit(double value);
00219   inline double objectiveOffset() const { return dblParam_[ClpObjOffset];}
00220   void setObjectiveOffset(double value);
00221   inline std::string problemName() const { return strParam_[ClpProbName]; };
00223    inline int numberIterations() const  { return numberIterations_; }
00224    inline int getIterationCount() const { return numberIterations_; }
00225   inline void setNumberIterations(int numberIterations)
00226   { numberIterations_ = numberIterations;};
00228   inline int solveType() const
00229   { return solveType_;};
00230   inline void setSolveType(int type)
00231   { solveType_=type;};
00233    inline int maximumIterations() const { return intParam_[ClpMaxNumIteration]; }
00234    void setMaximumIterations(int value);
00236    inline double maximumSeconds() const { return dblParam_[ClpMaxSeconds]; }
00237    void setMaximumSeconds(double value);
00239   bool hitMaximumIterations() const;
00248    inline int status() const            { return problemStatus_; }
00250   inline void setProblemStatus(int problemStatus)
00251   { problemStatus_ = problemStatus;};
00260    inline int secondaryStatus() const            { return secondaryStatus_; }
00261   inline void setSecondaryStatus(int status)
00262   { secondaryStatus_ = status;};
00264    bool isAbandoned() const             { return problemStatus_==4; }
00266    bool isProvenOptimal() const         { return problemStatus_==0; }
00268    bool isProvenPrimalInfeasible() const { return problemStatus_==1; }
00270    bool isProvenDualInfeasible() const  { return problemStatus_==2; }
00272    bool isPrimalObjectiveLimitReached() const ;
00274    bool isDualObjectiveLimitReached() const ;
00276    bool isIterationLimitReached() const { return problemStatus_==3; }
00278    inline double optimizationDirection() const {
00279       return  optimizationDirection_;
00280    }
00281    inline double getObjSense() const    { return optimizationDirection_; }
00282    void setOptimizationDirection(double value);
00284    inline double * primalRowSolution() const    { return rowActivity_; }
00285    inline const double * getRowActivity() const { return rowActivity_; }
00287    inline double * primalColumnSolution() const { return columnActivity_; }
00288    inline const double * getColSolution() const { return columnActivity_; }
00289    inline void setColSolution(const double * input)
00290    { memcpy(columnActivity_,input,numberColumns_*sizeof(double));};
00292    inline double * dualRowSolution() const      { return dual_; }
00293    inline const double * getRowPrice() const    { return dual_; }
00295    inline double * dualColumnSolution() const   { return reducedCost_; }
00296    inline const double * getReducedCost() const { return reducedCost_; }
00298    inline double* rowLower() const              { return rowLower_; }
00299    inline const double* getRowLower() const     { return rowLower_; }
00301    inline double* rowUpper() const              { return rowUpper_; }
00302    inline const double* getRowUpper() const     { return rowUpper_; }
00304    inline const double * rowScale() const {return rowScale_;};
00305    inline const double * columnScale() const {return columnScale_;};
00306    inline void setRowScale(double * scale) { delete [] (double *) rowScale_; rowScale_ = scale;};
00307    inline void setColumnScale(double * scale) { delete [] (double *) columnScale_; columnScale_ = scale;};
00309   inline double objectiveScale() const 
00310           { return objectiveScale_;} ;
00311   inline void setObjectiveScale(double value)
00312           { objectiveScale_ = value;} ;
00314   inline double rhsScale() const 
00315           { return rhsScale_;} ;
00316   inline void setRhsScale(double value)
00317           { rhsScale_ = value;} ;
00319    void scaling(int mode=1);
00322   void unscale();
00324    inline int scalingFlag() const {return scalingFlag_;};
00326    inline double * objective() const            
00327   {
00328     if (objective_) {
00329       double offset; 
00330       return objective_->gradient(NULL,NULL,offset,false);
00331     } else {
00332       return NULL;
00333     }
00334   }
00335    inline double * objective(const double * solution, double & offset,bool refresh=true) const            
00336   {
00337     offset=0.0;
00338     if (objective_) {
00339       return objective_->gradient(NULL,solution,offset,refresh);
00340     } else {
00341       return NULL;
00342     }
00343   }
00344    inline const double * getObjCoefficients() const 
00345   { 
00346     if (objective_) {
00347       double offset; 
00348       return objective_->gradient(NULL,NULL,offset,false);
00349     } else {
00350       return NULL;
00351     }
00352   }
00354    inline double * rowObjective() const         { return rowObjective_; }
00355    inline const double * getRowObjCoefficients() const {
00356       return rowObjective_;
00357    }
00359    inline double * columnLower() const          { return columnLower_; }
00360    inline const double * getColLower() const    { return columnLower_; }
00362    inline double * columnUpper() const          { return columnUpper_; }
00363    inline const double * getColUpper() const    { return columnUpper_; }
00365    inline CoinPackedMatrix * matrix() const {
00366      if ( matrix_ == NULL ) return NULL;
00367      else return matrix_->getPackedMatrix();
00368    }
00370    inline int getNumElements() const 
00371      { return matrix_->getNumElements();};
00374    inline double getSmallElementValue() const
00375   { return smallElement_;}; 
00376   inline void setSmallElementValue(double value)
00377   { smallElement_=value;}; 
00379    inline ClpMatrixBase * rowCopy() const       { return rowCopy_; }
00381    inline ClpMatrixBase * clpMatrix() const     { return matrix_; }
00385    void replaceMatrix(ClpMatrixBase * matrix);
00387    inline double objectiveValue() const {
00388       return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
00389    }
00390    inline double getObjValue() const {
00391       return objectiveValue_*optimizationDirection_ - dblParam_[ClpObjOffset];
00392    }
00394    inline char * integerInformation() const     { return integerType_; }
00397    double * infeasibilityRay() const;
00398    double * unboundedRay() const;
00400   inline bool statusExists() const
00401   { return (status_!=NULL);};
00403   inline unsigned char *  statusArray() const
00404   { return status_;};
00407   unsigned char *  statusCopy() const;
00409   void copyinStatus(const unsigned char * statusArray);
00410 
00412   inline void setUserPointer (void * pointer)
00413   { userPointer_=pointer;};
00414   inline void * getUserPointer () const
00415   { return userPointer_;};
00417 
00419 
00420    void passInMessageHandler(CoinMessageHandler * handler);
00422   CoinMessageHandler * pushMessageHandler(CoinMessageHandler * handler,
00423                                           bool & oldDefault);
00425   void popMessageHandler(CoinMessageHandler * oldHandler,bool oldDefault);
00427    void newLanguage(CoinMessages::Language language);
00428    void setLanguage(CoinMessages::Language language) { newLanguage(language); }
00430    CoinMessageHandler * messageHandler() const       { return handler_; }
00432    CoinMessages messages() const                     { return messages_; }
00434    CoinMessages * messagesPointer()                  { return & messages_; }
00443    void setLogLevel(int value)    { handler_->setLogLevel(value); }
00444    int logLevel() const           { return handler_->logLevel(); }
00446    void passInEventHandler(const ClpEventHandler * eventHandler);
00448    inline int lengthNames() const { return lengthNames_; }
00450    const std::vector<std::string> * rowNames() const {
00451       return &rowNames_;
00452    }
00453    const std::string& rowName(int iRow) const {
00454       return rowNames_[iRow];
00455    }
00457    const std::vector<std::string> * columnNames() const {
00458       return &columnNames_;
00459    }
00460    const std::string& columnName(int iColumn) const {
00461       return columnNames_[iColumn];
00462    }
00464   inline ClpObjective * objectiveAsObject() const
00465   { return objective_;};
00466   void setObjective(ClpObjective * objective);
00467   void setObjectivePointer(ClpObjective * objective)
00468   { objective_ = objective;};
00471   int emptyProblem(int * infeasNumber=NULL, double * infeasSum=NULL,bool printMessage=true);
00472   
00474 
00483    void times(double scalar,
00484                        const double * x, double * y) const;
00488     void transposeTimes(double scalar,
00489                                 const double * x, double * y) const ;
00491 
00492 
00493   //---------------------------------------------------------------------------
00511 
00512     bool setIntParam(ClpIntParam key, int value) ;
00514     bool setDblParam(ClpDblParam key, double value) ;
00516     bool setStrParam(ClpStrParam key, const std::string & value);
00517     // Get an integer parameter
00518     inline bool getIntParam(ClpIntParam key, int& value) const {
00519       if (key!=ClpLastIntParam) {
00520         value = intParam_[key];
00521         return true;
00522       } else {
00523         return false;
00524       }
00525     }
00526     // Get an double parameter
00527     inline bool getDblParam(ClpDblParam key, double& value) const {
00528       if (key!=ClpLastDblParam) {
00529         value = dblParam_[key];
00530         return true;
00531       } else {
00532         return false;
00533       }
00534     }
00535     // Get a string parameter
00536     inline bool getStrParam(ClpStrParam key, std::string& value) const {
00537       if (key!=ClpLastStrParam) {
00538         value = strParam_[key];
00539         return true;
00540       } else {
00541         return false;
00542       }
00543     }
00545 
00548 protected:
00550   void gutsOfDelete();
00553   void gutsOfCopy(const ClpModel & rhs, bool trueCopy=true);
00555   void getRowBound(int iRow, double& lower, double& upper) const;
00557   void gutsOfLoadModel ( int numberRows, int numberColumns,
00558                      const double* collb, const double* colub,   
00559                      const double* obj,
00560                      const double* rowlb, const double* rowub,
00561                       const double * rowObjective=NULL);
00563   void gutsOfScaling();
00565 
00566 
00568 protected:
00569 
00572 
00573   double optimizationDirection_;
00575   double dblParam_[ClpLastDblParam];
00577   double objectiveValue_;
00579   double smallElement_;
00581   double objectiveScale_;
00583   double rhsScale_;
00585   int numberRows_;
00587   int numberColumns_;
00589   double * rowActivity_;
00591   double * columnActivity_;
00593   double * dual_;
00595   double * reducedCost_;
00597   double* rowLower_;
00599   double* rowUpper_;
00601   ClpObjective * objective_;
00603   double * rowObjective_;
00605   double * columnLower_;
00607   double * columnUpper_;
00609   ClpMatrixBase * matrix_;
00611   ClpMatrixBase * rowCopy_;
00613   double * ray_;
00615   double * rowScale_;
00617   double * columnScale_;
00619   int scalingFlag_;
00627   unsigned char * status_;
00629   char * integerType_;
00631   void * userPointer_;
00633   int intParam_[ClpLastIntParam];
00635   int numberIterations_;
00637   int solveType_;
00639   int problemStatus_;
00641   int secondaryStatus_;
00643   int lengthNames_;
00645   CoinMessageHandler * handler_;
00647   bool defaultHandler_;
00649   ClpEventHandler * eventHandler_;
00651   std::vector<std::string> rowNames_;
00653   std::vector<std::string> columnNames_;
00655   CoinMessages messages_;
00657   std::string strParam_[ClpLastStrParam];
00659 };
00661 class ClpDataSave {
00662 
00663 public:
00667 
00668     ClpDataSave (  );
00669 
00671     ClpDataSave(const ClpDataSave &);
00673     ClpDataSave & operator=(const ClpDataSave & rhs);
00675     ~ClpDataSave (  );
00676 
00678 
00680 public:
00681 
00684   double dualBound_;
00685   double infeasibilityCost_;
00686   int sparseThreshold_;
00687   int perturbation_;
00688 
00690 };
00691 
00692 #endif

Generated on Fri Aug 6 11:42:58 2004 by doxygen 1.3.5