00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef BonBqpdSolver_H
00012 #define BonBqpdSolver_H
00013
00014 #include "BonTNLPSolver.hpp"
00015 #include "BonBranchingTQP.hpp"
00016
00017 namespace Bonmin
00018 {
00019 class BqpdSolver : public TNLPSolver
00020 {
00021 public:
00022 friend class FilterSolver;
00023
00024 class UnsolvedBqpdError: public TNLPSolver::UnsolvedError
00025 {
00026 public:
00027 UnsolvedBqpdError(int errorNum,
00028 Ipopt::SmartPtr<TMINLP2TNLP> model,
00029 const std::string &name):
00030 TNLPSolver::UnsolvedError(errorNum, model, name)
00031 {}
00032 virtual const std::string& errorName() const;
00033
00034 virtual const std::string& solverName() const;
00035 virtual ~UnsolvedBqpdError()
00036 {}
00037
00038 private:
00039 static std::string errorNames_[1];
00040 static std::string solverName_;
00041 };
00042
00044 typedef ipfint fint;
00046 typedef double real;
00047
00048 virtual UnsolvedError*
00049 newUnsolvedError(int num,
00050 Ipopt::SmartPtr<TMINLP2TNLP> problem,
00051 std::string name)
00052 {
00053 return new UnsolvedBqpdError(num, problem, name);
00054 }
00055
00057 BqpdSolver(bool createEmpty = false);
00058
00060 BqpdSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00061 Ipopt::SmartPtr<Ipopt::OptionsList> options,
00062 Ipopt::SmartPtr<Ipopt::Journalist> journalist
00063 );
00064
00066 virtual ~BqpdSolver();
00067
00070 virtual bool Initialize(std::string params_file);
00071
00074 virtual bool Initialize(std::istream& is);
00075
00078
00079 virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00080
00082 virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
00083
00085 virtual bool setWarmStart(const CoinWarmStart * warm,
00086 Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
00087
00091 virtual bool markHotStart(){return cached_->markHotStart();}
00092
00094 virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const{
00095 throw CoinError(__PRETTY_FUNCTION__,"","Not implemented");
00096 }
00097
00099 virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
00100
00101 virtual CoinWarmStart * getEmptyWarmStart() const;
00102
00104 virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
00105
00106 virtual void enableWarmStart()
00107 {
00108 }
00109 virtual void disableWarmStart()
00110 {
00111 }
00113
00115 virtual SmartPtr<TNLPSolver> clone();
00116
00118 virtual double CPUTime()
00119 {
00120 return (Ipopt::IsValid(cached_)) ? cached_->cpuTime_: 0.;
00121 }
00122
00124 virtual int IterationCount()
00125 {
00126 return 0;
00127 }
00128
00130 virtual void turnOffOutput()
00131 {
00132 if (Ipopt::IsValid(cached_)) cached_->iprint = 0;
00133 }
00135 virtual void turnOnOutput()
00136 {
00137 if (Ipopt::IsValid(cached_)) cached_->iprint = 3;
00138 }
00139
00141 virtual std::string & solverName()
00142 {
00143 return solverName_;
00144 }
00145
00147 void registerOptions()
00148 {
00149 registerOptions(roptions_);
00150 }
00151
00153 virtual int errorCode() const
00154 {
00155 return -1;
00156 }
00158 static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00159 private:
00163 TNLPSolver::ReturnStatus callOptimizer();
00169 double fillin_factor_;
00170 int kmax_ipt_;
00171 int mlp_ipt_;
00173
00175 struct cachedInfo : public Ipopt::ReferencedObject
00176 {
00177 fint n;
00178 fint m;
00179 fint k;
00180 fint kmax;
00181 real* a;
00182 fint* la;
00183 real* x;
00184 real* bl;
00185 real* bu;
00186 real f;
00187 real* g;
00188 real* r;
00189 real* w;
00190 real* e;
00191 fint* ls;
00192 real* alp;
00193 fint* lp;
00194 fint mlp;
00195 fint peq;
00196 real* ws;
00197 fint* lws;
00198 fint m0de;
00199 fint ifail;
00200 fint info[1];
00201 fint iprint;
00202 fint nout;
00203
00205 fint kk,ll,mxws,mxlws;
00206
00208 bool haveHotStart_;
00212
00213 fint irh1,na,na1,nb,nb1,ka1,kb1,kc1,irg1,lu1,lv,lv1,ll1;
00215 real eps,tol,emin;
00217 real vstep;
00219 real sgnf;
00220 fint nrep,npiv,nres;
00222 fint nup,nfreq;
00224 real alpha;
00226 fint ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,lc;
00227 fint lc1,li,li1,lm,lm1,lp_,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1;
00229 fint m1,m2,mp,mq,lastr,irow;
00231 fint mxm1;
00233 real c;
00235 fint kHot;
00236 real* xHot;
00237 real fHot;
00238 real* gHot;
00239 real* rHot;
00240 real* wHot;
00241 real* eHot;
00242 fint* lsHot;
00243 real* alpHot;
00244 fint* lpHot;
00245 fint peqHot;
00246 real* wsHot;
00247 fint* lwsHot;
00248 fint infoHot[1];
00249 fint kkkHot;
00250 fint lllHot;
00251
00252 Ipopt::SmartPtr<BranchingTQP> tqp_;
00254 double cpuTime_;
00257 bool use_warm_start_in_cache_;
00258 bool bad_warm_start_info_;
00259
00261 int amax_;
00262
00266 double* fillin_factor_;
00268
00270 cachedInfo()
00271 :
00272 a(NULL),
00273 la(NULL),
00274 x(NULL),
00275 bl(NULL),
00276 bu(NULL),
00277 g(NULL),
00278 r(NULL),
00279 w(NULL),
00280 e(NULL),
00281 ls(NULL),
00282 alp(NULL),
00283 lp(NULL),
00284 ws(NULL),
00285 lws(NULL),
00286 haveHotStart_(false),
00287 xHot(NULL),
00288 gHot(NULL),
00289 rHot(NULL),
00290 wHot(NULL),
00291 eHot(NULL),
00292 lsHot(NULL),
00293 alpHot(NULL),
00294 lpHot(NULL),
00295 wsHot(NULL),
00296 lwsHot(NULL),
00297 cpuTime_(0),
00298 use_warm_start_in_cache_(false),
00299 bad_warm_start_info_(false)
00300 {}
00301
00302 cachedInfo(const Ipopt::SmartPtr<BranchingTQP> &tqp,
00303 Ipopt::SmartPtr<Ipopt::OptionsList>& options,
00304 int kmax_ipt, int mlp_ipt, double* fillin_factor):
00305 a(NULL),
00306 la(NULL),
00307 x(NULL),
00308 bl(NULL),
00309 bu(NULL),
00310 g(NULL),
00311 r(NULL),
00312 w(NULL),
00313 e(NULL),
00314 ls(NULL),
00315 alp(NULL),
00316 lp(NULL),
00317 ws(NULL),
00318 lws(NULL),
00319 haveHotStart_(false),
00320 xHot(NULL),
00321 gHot(NULL),
00322 rHot(NULL),
00323 wHot(NULL),
00324 eHot(NULL),
00325 lsHot(NULL),
00326 alpHot(NULL),
00327 lpHot(NULL),
00328 wsHot(NULL),
00329 lwsHot(NULL),
00330 tqp_(tqp),
00331 cpuTime_(0),
00332 use_warm_start_in_cache_(false),
00333 bad_warm_start_info_(false)
00334 {
00335 initialize(tqp, options, kmax_ipt, mlp_ipt, fillin_factor);
00336 }
00337
00339 void initialize(const Ipopt::SmartPtr<BranchingTQP> &tqp,
00340 Ipopt::SmartPtr<Ipopt::OptionsList>& options,
00341 int kmax_ipt, int mlp_ipt, double* fillin_factor);
00342
00344 void optimize();
00345
00347 bool markHotStart();
00348
00350 void unmarkHotStart();
00351
00353 void copyFromHotStart();
00354
00356 ~cachedInfo();
00357 };
00358
00360 Ipopt::SmartPtr<cachedInfo> cached_;
00361
00362
00363 static std::string solverName_;
00364 };
00365
00366 }
00367 #endif