Bonmin  1.7
BonBqpdSolver.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation, 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Andreas Waechter, International Business Machines Corporation
00007 //                    based on BonFilterSolver.cpp
00008 //
00009 // Date : 07/09/2007
00010 
00011 #ifndef BonBqpdSolver_H
00012 #define BonBqpdSolver_H
00013 
00014 #include "BonTNLPSolver.hpp"
00015 #include "BonBranchingTQP.hpp"
00016 
00017 //#define TIME_BQPD
00018 namespace Bonmin
00019 {
00020   class BqpdSolver : public TNLPSolver
00021   {
00022   public:
00023     friend class FilterSolver;
00024 
00025 
00026   class UnsolvedBqpdError: public TNLPSolver::UnsolvedError
00027     {
00028     public:
00029       UnsolvedBqpdError(int errorNum,
00030           Ipopt::SmartPtr<TMINLP2TNLP> model,
00031           const std::string &name):
00032           TNLPSolver::UnsolvedError(errorNum, model, name)
00033       {}
00034       virtual const std::string& errorName() const;
00035 
00036       virtual const std::string& solverName() const;
00037       virtual ~UnsolvedBqpdError()
00038       {}
00039 
00040     private:
00041       static std::string errorNames_[1];
00042       static std::string solverName_;
00043     };
00044 
00046     typedef ipfint fint;
00048     typedef double real;
00049 
00050     virtual UnsolvedError*
00051     newUnsolvedError(int num,
00052         Ipopt::SmartPtr<TMINLP2TNLP> problem,
00053         std::string name)
00054     {
00055       return new UnsolvedBqpdError(num, problem, name);
00056     }
00057 
00059     BqpdSolver(bool createEmpty = false);
00060 
00062     BqpdSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00063         Ipopt::SmartPtr<Ipopt::OptionsList> options,
00064         Ipopt::SmartPtr<Ipopt::Journalist> journalist,
00065         const std::string & prefix
00066               );
00067 
00069     virtual ~BqpdSolver();
00070 
00073     virtual bool Initialize(std::string params_file);
00074 
00077     virtual bool Initialize(std::istream& is);
00078 
00081 
00082     virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00083 
00085     virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00086 
00088     virtual bool setWarmStart(const CoinWarmStart * warm,
00089         Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
00090 
00094     virtual bool markHotStart(){return cached_->markHotStart();}
00095 
00097     virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const{
00098       throw CoinError(__PRETTY_FUNCTION__,"","Not implemented");
00099     }
00100 
00102     virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
00103 
00104     virtual CoinWarmStart * getEmptyWarmStart() const;
00105 
00107     virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
00108 
00109     virtual void enableWarmStart()
00110     {//No options to be set
00111     }
00112     virtual void disableWarmStart()
00113     {//No options to be set
00114     }
00116 
00118     virtual Ipopt::SmartPtr<TNLPSolver> clone();
00119 
00121     virtual double CPUTime()
00122     {
00123       return (Ipopt::IsValid(cached_)) ? cached_->cpuTime_: 0.;
00124     }
00125 
00127     virtual int IterationCount()
00128     {
00129       return 0;
00130     }
00131 
00132 
00133     // turn off all output from the solver
00134     virtual void setOutputToDefault()
00135     {
00136       if (Ipopt::IsValid(cached_)) cached_->iprint = default_log_level_;
00137     }
00139     virtual void forceSolverOutput(int log_level)
00140     {
00141       if (Ipopt::IsValid(cached_)) cached_->iprint = log_level;
00142     }
00143     
00145     virtual std::string & solverName()
00146     {
00147       return solverName_;
00148     }
00149 
00151     void registerOptions()
00152     {
00153       registerOptions(roptions_);
00154     }
00155 
00157     virtual int errorCode() const
00158     {
00159       return -1;
00160     }
00161 #ifdef TIME_BQPD
00162   struct Times {
00163     int numsolve;
00164     double create;
00165     double solve;
00166     double resolve;
00167     double warm_start;
00168     int pivots;
00169     Times(): numsolve(0), create(0), solve(0), resolve(0), warm_start(0), pivots(0){
00170     }
00171 
00172     Times & operator +=(Times &rhs){
00173       numsolve += rhs.numsolve;
00174       create += rhs.create;
00175       solve += rhs.solve;
00176       resolve += rhs.resolve;
00177       warm_start += rhs.warm_start;
00178       pivots += rhs.pivots;
00179       return *this;
00180     }
00181   };
00182 #endif
00183 
00185     static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00186   private:
00190     TNLPSolver::ReturnStatus callOptimizer();
00196     double fillin_factor_;
00197     int kmax_ipt_;
00198     int mlp_ipt_;
00200     static int m0de_;
00202     static int reinit_freq_;
00204 
00206   struct cachedInfo : public Ipopt::ReferencedObject
00207     {
00208 #ifdef TIME_BQPD
00209   Times times_;
00210 #endif
00211 
00212       fint n;
00213       fint m;
00214       fint k;
00215       fint kmax;
00216       real* a;
00217       fint* la;
00218       real* x;
00219       real* bl;
00220       real* bu;
00221       real f;
00222       real* g;
00223       real* r;
00224       real* w;
00225       real* e;
00226       fint* ls;
00227       real* alp;
00228       fint* lp;
00229       fint mlp;
00230       fint peq;
00231       real* ws;
00232       fint* lws;
00233       fint m0de;
00234       fint ifail;
00235       fint info[1];
00236       fint iprint;
00237       fint nout;
00238 
00240       fint kk,ll,mxws,mxlws;
00241 
00243       bool haveHotStart_;
00247 
00248       fint irh1,na,na1,nb,nb1,ka1,kb1,kc1,irg1,lu1,lv,lv1,ll1;
00250       real eps,tol,emin;
00252       real vstep;
00254       real sgnf;
00255       fint nrep,npiv,nres;
00257       fint nup,nfreq;
00259       real alpha;
00261       fint ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,lc;
00262       fint lc1,li,li1,lm,lm1,lp_,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1;
00264       fint m1,m2,mp,mq,lastr,irow;
00266       fint mxm1;
00268       real c;
00270       fint kHot;
00271       real* xHot;
00272       real fHot;
00273       real* gHot;
00274       real* rHot;
00275       real* wHot;
00276       real* eHot;
00277       fint* lsHot;
00278       real* alpHot;
00279       fint* lpHot;
00280       fint peqHot;
00281       real* wsHot;
00282       fint* lwsHot;
00283       fint infoHot[1];
00284       fint kkkHot;
00285       fint lllHot;
00286       fint kkHot;
00287       fint llHot;
00288 
00289       Ipopt::SmartPtr<BranchingTQP> tqp_;
00291       double cpuTime_;
00294       bool use_warm_start_in_cache_;
00295       bool bad_warm_start_info_;
00296 
00298       int amax_;
00299 
00303       double* fillin_factor_;
00305 
00307       int next_reinit_;
00309       int pivots_;
00311       cachedInfo()
00312           :
00313           a(NULL),
00314           la(NULL),
00315           x(NULL),
00316           bl(NULL),
00317           bu(NULL),
00318           g(NULL),
00319           r(NULL),
00320           w(NULL),
00321           e(NULL),
00322           ls(NULL),
00323           alp(NULL),
00324           lp(NULL),
00325           ws(NULL),
00326           lws(NULL),
00327           haveHotStart_(false),
00328           xHot(NULL),
00329           gHot(NULL),
00330           rHot(NULL),
00331           wHot(NULL),
00332           eHot(NULL),
00333           lsHot(NULL),
00334           alpHot(NULL),
00335           lpHot(NULL),
00336           wsHot(NULL),
00337           lwsHot(NULL),
00338           cpuTime_(0),
00339           use_warm_start_in_cache_(false),
00340           bad_warm_start_info_(false),
00341           next_reinit_(0),
00342           pivots_(0)
00343       {}
00344 
00345       cachedInfo(const Ipopt::SmartPtr<BranchingTQP> &tqp,
00346                  Ipopt::SmartPtr<Ipopt::OptionsList>& options,
00347                  int kmax_ipt, int mlp_ipt, double* fillin_factor):
00348           a(NULL),
00349           la(NULL),
00350           x(NULL),
00351           bl(NULL),
00352           bu(NULL),
00353           g(NULL),
00354           r(NULL),
00355           w(NULL),
00356           e(NULL),
00357           ls(NULL),
00358           alp(NULL),
00359           lp(NULL),
00360           ws(NULL),
00361           lws(NULL),
00362           haveHotStart_(false),
00363           xHot(NULL),
00364           gHot(NULL),
00365           rHot(NULL),
00366           wHot(NULL),
00367           eHot(NULL),
00368           lsHot(NULL),
00369           alpHot(NULL),
00370           lpHot(NULL),
00371           wsHot(NULL),
00372           lwsHot(NULL),
00373           tqp_(tqp),
00374           cpuTime_(0),
00375           use_warm_start_in_cache_(false),
00376           bad_warm_start_info_(false),
00377           next_reinit_(0),
00378           pivots_(0)
00379       {
00380         initialize(tqp, options, kmax_ipt, mlp_ipt, fillin_factor);
00381       }
00382 
00384       void initialize(const Ipopt::SmartPtr<BranchingTQP> &tqp,
00385                       Ipopt::SmartPtr<Ipopt::OptionsList>& options,
00386                       int kmax_ipt, int mlp_ipt, double* fillin_factor);
00387 
00388       void re_initialize();
00390       void optimize();
00391 
00393       bool markHotStart();
00394 
00396       void unmarkHotStart();
00397 
00399       void copyFromHotStart();
00400 
00402       ~cachedInfo();
00403     };
00404 
00406     Ipopt::SmartPtr<cachedInfo> cached_;
00407 
00409     static std::string  solverName_;
00410 
00412      int default_log_level_;
00413 
00414     public:
00415 
00416 #ifdef TIME_BQPD
00417     Times &times(){ return cached_->times_;}
00418 #endif
00419 
00420   };
00421 
00422 }// end namespace Bonmin
00423 #endif