/home/coin/SVN-release/OS-2.0.1/Bonmin/src/Interfaces/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 namespace Bonmin  {
00025 class TNLPSolver: public Ipopt::ReferencedObject{
00026  public:
00027 
00028   enum ReturnStatus {
00029     iterationLimit = -3,
00030     doesNotConverge = -8,
00031     computationError = -2,
00032     notEnoughFreedom = -1,
00033     illDefinedProblem = -4,
00034     illegalOption =-5,
00035     externalException =-6,
00036     exception =-7,
00037     solvedOptimal = 1,
00038     solvedOptimalTol =2,
00039     provenInfeasible =3,
00040     unbounded = 4,
00041     numReturnCodes
00042   };
00043 
00044 
00045 
00046 //#############################################################################
00047 
00050   class UnsolvedError
00051   {
00052   public:
00054     UnsolvedError(int errorNum = -10000, 
00055                   Ipopt::SmartPtr<TMINLP2TNLP> model = NULL,
00056                   std::string name="")
00057     :
00058      errorNum_(errorNum),
00059      model_(model),
00060      name_(name)
00061     {if(name_=="") 
00062 {
00063 #ifndef NDEBUG
00064         std::cerr<<"FIXME"<<std::endl;
00065 #endif
00066 }}
00068     void printError(std::ostream & os);
00070     virtual const std::string& errorName() const = 0;
00072     virtual const std::string& solverName() const = 0;
00074     int errorNum() const{
00075     return errorNum_;}
00077     virtual ~UnsolvedError(){}
00080     void writeDiffFiles(const std::string prefix=std::string()) const;
00081   private:
00083     int errorNum_;
00084 
00086     Ipopt::SmartPtr< TMINLP2TNLP > model_;
00087 
00089     std::string name_;
00090   }
00091   ;
00092 
00093   virtual UnsolvedError * newUnsolvedError(int num,
00094                                            Ipopt::SmartPtr<TMINLP2TNLP> problem,
00095                                            std::string name) = 0;
00096  
00097 
00098 
00100    TNLPSolver();
00101 
00103 TNLPSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00104            Ipopt::SmartPtr<Ipopt::OptionsList> options,
00105            Ipopt::SmartPtr<Ipopt::Journalist> journalist);
00106 
00108   virtual Ipopt::SmartPtr<TNLPSolver> clone() = 0;
00109 
00111    virtual ~TNLPSolver();
00112 
00115    virtual bool Initialize(std::string params_file) = 0;
00116 
00119    virtual bool Initialize(std::istream& is) = 0;
00120 
00123 
00124    virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
00125 
00127    virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
00128 
00130   virtual bool setWarmStart(const CoinWarmStart * warm, 
00131                             Ipopt::SmartPtr<TMINLP2TNLP> tnlp) = 0;
00132 
00134   virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
00135 
00137   virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
00138 
00139   virtual CoinWarmStart * getEmptyWarmStart() const = 0;
00140 
00142   virtual bool warmStartIsValid(const CoinWarmStart * ws) const = 0;  
00143 
00145   virtual void enableWarmStart() = 0;
00146 
00148   virtual void disableWarmStart() = 0;
00150 
00152   Ipopt::SmartPtr<Ipopt::Journalist> journalist(){
00153     return journalist_;}
00154 
00156    Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions(){
00157      return roptions_;}
00158 
00160    Ipopt::SmartPtr<const Ipopt::OptionsList> options() const {
00161      return ConstPtr(options_);}
00162 
00164    Ipopt::SmartPtr<Ipopt::OptionsList> options() {
00165      return options_;}
00166 
00168 static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){}
00169 
00171    virtual double CPUTime() = 0;
00172 
00174    virtual int IterationCount() = 0;
00175 
00176 
00178   virtual void turnOffOutput() = 0 ;
00180   virtual void turnOnOutput() = 0;
00182   virtual std::string & solverName() = 0;
00183 
00186   bool isRecoverable(ReturnStatus &r);
00187 
00189   bool isError(ReturnStatus &r){
00190     return r < 0;}
00192 virtual int errorCode() const = 0;
00193 protected:
00196    bool zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp, 
00197                      ReturnStatus &optimization_status);
00198 
00200    void initializeOptionsAndJournalist();
00201 
00203     Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
00204     
00206     Ipopt::SmartPtr<Ipopt::OptionsList> options_;
00207     
00209     Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
00210    
00211    private:
00213    TNLPSolver(TNLPSolver &other); 
00214 };
00215 }
00216 #endif
00217 
00218 

Generated on Thu Oct 8 03:02:55 2009 by  doxygen 1.4.7