Bonmin  1.7
BonIpoptSolver.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines (IBM) 2005, 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 #ifndef IpoptSolver_HPP
00011 #define IpoptSolver_HPP
00012 #include "BonTNLPSolver.hpp"
00013 #include "IpIpoptApplication.hpp"
00014 
00015 
00016 namespace Bonmin
00017 {
00018   class IpoptSolver: public TNLPSolver
00019   {
00020   public:
00021   class UnsolvedIpoptError: public TNLPSolver::UnsolvedError
00022     {
00023     public:
00024       UnsolvedIpoptError(int errorNum,
00025           Ipopt::SmartPtr<TMINLP2TNLP> problem,
00026           std::string name):
00027           TNLPSolver::UnsolvedError(errorNum, problem, name)
00028       {}
00029       virtual const std::string& errorName() const;
00030 
00031       virtual const std::string& solverName() const;
00032       virtual ~UnsolvedIpoptError()
00033       {}
00034     private:
00035       static std::string errorNames [17];
00036       static std::string solverName_;
00037     };
00038 
00039     virtual UnsolvedError * newUnsolvedError(int num,
00040         Ipopt::SmartPtr<TMINLP2TNLP> problem,
00041         std::string name)
00042     {
00043       return new UnsolvedIpoptError(num, problem, name);
00044     }
00045 
00046 
00047 
00049     IpoptSolver(bool createEmpty = false);
00050 
00052     IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00053         Ipopt::SmartPtr<Ipopt::OptionsList> options,
00054         Ipopt::SmartPtr<Ipopt::Journalist> journalist,
00055         const std::string & prefix);
00056 
00058     IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00059         Ipopt::SmartPtr<Ipopt::OptionsList> options,
00060         Ipopt::SmartPtr<Ipopt::Journalist> journalist);
00061 
00063     IpoptSolver(const IpoptSolver &other);
00064 
00066     virtual Ipopt::SmartPtr<TNLPSolver> clone();
00067 
00069     virtual ~IpoptSolver();
00070 
00073     virtual bool Initialize(std::string params_file);
00074 
00077     virtual bool Initialize(std::istream& is);
00078 
00081 
00082     virtual TNLPSolver::ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00083 
00085     virtual TNLPSolver::ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00086 
00088     virtual bool setWarmStart(const CoinWarmStart * warm,
00089         Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
00090 
00092    virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
00093 
00094 
00096     virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<Bonmin::TMINLP2TNLP> tnlp) const;
00097 
00098     virtual CoinWarmStart * getEmptyWarmStart() const;
00099 
00101     virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
00102 
00104     virtual void enableWarmStart();
00105 
00107     virtual void disableWarmStart();
00108 
00110 
00112     virtual double CPUTime();
00113 
00115     virtual int IterationCount();
00116 
00118     virtual void setOutputToDefault();
00120     virtual void forceSolverOutput(int log_level);
00121 
00123     virtual std::string & solverName()
00124     {
00125       return solverName_;
00126     }
00127 
00129     static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
00130     {
00131       Ipopt::IpoptApplication::RegisterAllIpoptOptions(GetRawPtr(roptions));
00132     }
00133 
00134 
00135 
00137     Ipopt::ApplicationReturnStatus getOptStatus() const
00138     {
00139       return optimizationStatus_;
00140     }
00141 
00142     Ipopt::IpoptApplication& getIpoptApp()
00143     {
00144       return *app_;
00145     }
00146 
00147     virtual int errorCode() const
00148     {
00149       return (int) optimizationStatus_;
00150     }
00151   private:
00153     void setMinlpDefaults(Ipopt::SmartPtr< Ipopt::OptionsList> Options);
00154 
00156     TNLPSolver::ReturnStatus solverReturnStatus(Ipopt::ApplicationReturnStatus optimization_status) const;
00157 
00159     Ipopt::SmartPtr<Ipopt::IpoptApplication> app_;
00161     Ipopt::ApplicationReturnStatus optimizationStatus_;
00163 
00164 
00166     bool problemHadZeroDimension_;
00167 
00175     int warmStartStrategy_;
00176 
00178     bool enable_warm_start_;
00179 
00182     bool optimized_before_;
00183     //name of solver (Ipopt)
00184     static std::string  solverName_;
00185   };
00186 }
00187 #endif
00188