Bonmin  1.7
BonTNLPSolver.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines (IBM) 2006, 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, IBM
00007 //
00008 // Date : 26/09/2006
00009 
00010 
00011 #ifndef TNLPSolver_H
00012 #define TNLPSolver_H
00013 #include "IpTNLP.hpp"
00014 #include "BonTMINLP2TNLP.hpp"
00015 
00016 //Some declarations
00017 #include "IpOptionsList.hpp"
00018 #include "CoinWarmStart.hpp"
00019 #include "BonRegisteredOptions.hpp"
00020 #include "CoinTime.hpp"
00021 namespace Bonmin  {
00026 class TNLPSolver: public Ipopt::ReferencedObject{
00027  public:
00028 
00029   enum ReturnStatus {
00030     iterationLimit = -3,
00031     timeLimit = 5,
00032     doesNotConverge = -8,
00033     computationError = -2,
00034     notEnoughFreedom = -1,
00035     illDefinedProblem = -4,
00036     illegalOption =-5,
00037     externalException =-6,
00038     exception =-7,
00039     solvedOptimal = 1,
00040     solvedOptimalTol =2,
00041     provenInfeasible =3,
00042     unbounded = 4,
00043     numReturnCodes
00044   };
00045 
00046 
00047 
00048 //#############################################################################
00049 
00052   class UnsolvedError
00053   {
00054   public:
00056     UnsolvedError(int errorNum = -10000, 
00057                   Ipopt::SmartPtr<TMINLP2TNLP> model = NULL,
00058                   std::string name="")
00059     :
00060      errorNum_(errorNum),
00061      model_(model),
00062      name_(name)
00063     {if(name_=="") 
00064 {
00065 #ifndef NDEBUG
00066         std::cerr<<"FIXME"<<std::endl;
00067 #endif
00068 }}
00070     void printError(std::ostream & os);
00072     virtual const std::string& errorName() const = 0;
00074     virtual const std::string& solverName() const = 0;
00076     int errorNum() const{
00077     return errorNum_;}
00079     virtual ~UnsolvedError(){}
00082     void writeDiffFiles(const std::string prefix=std::string()) const;
00083   private:
00085     int errorNum_;
00086 
00088     Ipopt::SmartPtr< TMINLP2TNLP > model_;
00089 
00091     std::string name_;
00092   }
00093   ;
00094 
00095   virtual UnsolvedError * newUnsolvedError(int num,
00096                                            Ipopt::SmartPtr<TMINLP2TNLP> problem,
00097                                            std::string name) = 0;
00098  
00099 
00100 
00102    TNLPSolver();
00103 
00105 TNLPSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00106            Ipopt::SmartPtr<Ipopt::OptionsList> options,
00107            Ipopt::SmartPtr<Ipopt::Journalist> journalist,
00108            const std::string & prefix);
00109 
00111   virtual Ipopt::SmartPtr<TNLPSolver> clone() = 0;
00112 
00114    virtual ~TNLPSolver();
00115 
00118    virtual bool Initialize(std::string params_file) = 0;
00119 
00122    virtual bool Initialize(std::istream& is) = 0;
00123 
00126 
00127    virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
00128 
00130    virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
00131 
00133   virtual bool setWarmStart(const CoinWarmStart * warm, 
00134                             Ipopt::SmartPtr<TMINLP2TNLP> tnlp) = 0;
00135 
00137   virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
00138 
00140   virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
00141 
00142   virtual CoinWarmStart * getEmptyWarmStart() const = 0;
00143 
00145   virtual bool warmStartIsValid(const CoinWarmStart * ws) const = 0;  
00146 
00148   virtual void enableWarmStart() = 0;
00149 
00151   virtual void disableWarmStart() = 0;
00153 
00155   Ipopt::SmartPtr<Ipopt::Journalist> journalist(){
00156     return journalist_;}
00157 
00159    Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions(){
00160      return roptions_;}
00161 
00163    Ipopt::SmartPtr<const Ipopt::OptionsList> options() const {
00164      return ConstPtr(options_);}
00165 
00167    Ipopt::SmartPtr<Ipopt::OptionsList> options() {
00168      return options_;}
00169 
00171   const char * prefix(){
00172     return prefix_.c_str();
00173   }
00175 static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){}
00176 
00178    virtual double CPUTime() = 0;
00179 
00181    virtual int IterationCount() = 0;
00182 
00183 
00185   virtual void setOutputToDefault() = 0 ;
00187   virtual void forceSolverOutput(int log_level) = 0;
00189   virtual std::string & solverName() = 0;
00190 
00193   bool isRecoverable(ReturnStatus &r);
00194 
00196   void setup_global_time_limit(double time_limit){
00197     time_limit_ = time_limit + 5;
00198     start_time_ = CoinCpuTime();
00199   }
00200 
00202   bool isError(ReturnStatus &r){
00203     return r < 0;}
00205 virtual int errorCode() const = 0;
00206 protected:
00209    bool zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp, 
00210                      ReturnStatus &optimization_status);
00211 
00213    void initializeOptionsAndJournalist();
00214 
00216     Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
00217     
00219     Ipopt::SmartPtr<Ipopt::OptionsList> options_;
00220     
00222     Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
00223    
00225    std::string prefix_;
00227    double start_time_;
00228 
00230    double time_limit_;
00231 
00233    int default_log_level_;
00235   TNLPSolver(const TNLPSolver & other);
00236 
00237 };
00238 }
00239 #endif
00240 
00241