Bonmin  1.8.8
BonBqpdSolver.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Andreas Waechter, International Business Machines Corporation
7 // based on BonFilterSolver.cpp
8 //
9 // Date : 07/09/2007
10 
11 #ifndef BonBqpdSolver_H
12 #define BonBqpdSolver_H
13 
14 #include "BonTNLPSolver.hpp"
15 #include "BonBranchingTQP.hpp"
16 
17 //#define TIME_BQPD
18 namespace Bonmin
19 {
20  class BqpdSolver : public TNLPSolver
21  {
22  public:
23  friend class FilterSolver;
24 
25 
27  {
28  public:
31  const std::string &name):
32  TNLPSolver::UnsolvedError(errorNum, model, name)
33  {}
34  virtual const std::string& errorName() const;
35 
36  virtual const std::string& solverName() const;
38  {}
39 
40  private:
41  static std::string errorNames_[1];
42  static std::string solverName_;
43  };
44 
46  typedef ipfint fint;
48  typedef double real;
49 
50  virtual UnsolvedError*
53  std::string name)
54  {
55  return new UnsolvedBqpdError(num, problem, name);
56  }
57 
59  BqpdSolver(bool createEmpty = false);
60 
65  const std::string & prefix
66  );
67 
69  virtual ~BqpdSolver();
70 
73  virtual bool Initialize(std::string params_file);
74 
77  virtual bool Initialize(std::istream& is);
78 
83 
86 
88  virtual bool setWarmStart(const CoinWarmStart * warm,
90 
94  virtual bool markHotStart(){return cached_->markHotStart();}
95 
98  throw CoinError(__PRETTY_FUNCTION__,"","Not implemented");
99  }
100 
103 
104  virtual CoinWarmStart * getEmptyWarmStart() const;
105 
107  virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
108 
109  virtual void enableWarmStart()
110  {//No options to be set
111  }
112  virtual void disableWarmStart()
113  {//No options to be set
114  }
116 
119 
121  virtual double CPUTime()
122  {
123  return (Ipopt::IsValid(cached_)) ? cached_->cpuTime_: 0.;
124  }
125 
127  virtual int IterationCount()
128  {
129  return 0;
130  }
131 
132 
133  // turn off all output from the solver
134  virtual void setOutputToDefault()
135  {
136  if (Ipopt::IsValid(cached_)) cached_->iprint = default_log_level_;
137  }
139  virtual void forceSolverOutput(int log_level)
140  {
141  if (Ipopt::IsValid(cached_)) cached_->iprint = log_level;
142  }
143 
145  virtual std::string & solverName()
146  {
147  return solverName_;
148  }
149 
152  {
154  }
155 
157  virtual int errorCode() const
158  {
159  return -1;
160  }
161 #ifdef TIME_BQPD
162  struct Times {
163  int numsolve;
164  double create;
165  double solve;
166  double resolve;
167  double warm_start;
168  int pivots;
169  Times(): numsolve(0), create(0), solve(0), resolve(0), warm_start(0), pivots(0){
170  }
171 
172  Times & operator +=(Times &rhs){
173  numsolve += rhs.numsolve;
174  create += rhs.create;
175  solve += rhs.solve;
176  resolve += rhs.resolve;
177  warm_start += rhs.warm_start;
178  pivots += rhs.pivots;
179  return *this;
180  }
181  };
182 #endif
183 
186  private:
190  TNLPSolver::ReturnStatus callOptimizer();
196  double fillin_factor_;
197  int kmax_ipt_;
198  int mlp_ipt_;
200  static int m0de_;
202  static int reinit_freq_;
204 
206  struct cachedInfo : public Ipopt::ReferencedObject
207  {
208 #ifdef TIME_BQPD
209  Times times_;
210 #endif
211 
212  fint n;
213  fint m;
214  fint k;
215  fint kmax;
216  real* a;
217  fint* la;
218  real* x;
219  real* bl;
220  real* bu;
221  real f;
222  real* g;
223  real* r;
224  real* w;
225  real* e;
226  fint* ls;
227  real* alp;
228  fint* lp;
229  fint mlp;
230  fint peq;
231  real* ws;
232  fint* lws;
233  fint m0de;
234  fint ifail;
235  fint info[1];
236  fint iprint;
237  fint nout;
238 
240  fint kk,ll,mxws,mxlws;
241 
243  bool haveHotStart_;
247  fint irh1,na,na1,nb,nb1,ka1,kb1,kc1,irg1,lu1,lv,lv1,ll1;
250  real eps,tol,emin;
252  real vstep;
254  real sgnf;
255  fint nrep,npiv,nres;
257  fint nup,nfreq;
259  real alpha;
261  fint ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,lc;
262  fint lc1,li,li1,lm,lm1,lp_,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1;
264  fint m1,m2,mp,mq,lastr,irow;
266  fint mxm1;
268  real c;
270  fint kHot;
271  real* xHot;
272  real fHot;
273  real* gHot;
274  real* rHot;
275  real* wHot;
276  real* eHot;
277  fint* lsHot;
278  real* alpHot;
279  fint* lpHot;
280  fint peqHot;
281  real* wsHot;
282  fint* lwsHot;
283  fint infoHot[1];
284  fint kkkHot;
285  fint lllHot;
286  fint kkHot;
287  fint llHot;
288 
291  double cpuTime_;
294  bool use_warm_start_in_cache_;
295  bool bad_warm_start_info_;
296 
298  int amax_;
299 
303  double* fillin_factor_;
305 
307  int next_reinit_;
309  int pivots_;
311  cachedInfo()
312  :
313  a(NULL),
314  la(NULL),
315  x(NULL),
316  bl(NULL),
317  bu(NULL),
318  g(NULL),
319  r(NULL),
320  w(NULL),
321  e(NULL),
322  ls(NULL),
323  alp(NULL),
324  lp(NULL),
325  ws(NULL),
326  lws(NULL),
327  haveHotStart_(false),
328  xHot(NULL),
329  gHot(NULL),
330  rHot(NULL),
331  wHot(NULL),
332  eHot(NULL),
333  lsHot(NULL),
334  alpHot(NULL),
335  lpHot(NULL),
336  wsHot(NULL),
337  lwsHot(NULL),
338  cpuTime_(0),
339  use_warm_start_in_cache_(false),
340  bad_warm_start_info_(false),
341  next_reinit_(0),
342  pivots_(0)
343  {}
344 
345  cachedInfo(const Ipopt::SmartPtr<BranchingTQP> &tqp,
347  int kmax_ipt, int mlp_ipt, double* fillin_factor):
348  a(NULL),
349  la(NULL),
350  x(NULL),
351  bl(NULL),
352  bu(NULL),
353  g(NULL),
354  r(NULL),
355  w(NULL),
356  e(NULL),
357  ls(NULL),
358  alp(NULL),
359  lp(NULL),
360  ws(NULL),
361  lws(NULL),
362  haveHotStart_(false),
363  xHot(NULL),
364  gHot(NULL),
365  rHot(NULL),
366  wHot(NULL),
367  eHot(NULL),
368  lsHot(NULL),
369  alpHot(NULL),
370  lpHot(NULL),
371  wsHot(NULL),
372  lwsHot(NULL),
373  tqp_(tqp),
374  cpuTime_(0),
375  use_warm_start_in_cache_(false),
376  bad_warm_start_info_(false),
377  next_reinit_(0),
378  pivots_(0)
379  {
380  initialize(tqp, options, kmax_ipt, mlp_ipt, fillin_factor);
381  }
382 
384  void initialize(const Ipopt::SmartPtr<BranchingTQP> &tqp,
386  int kmax_ipt, int mlp_ipt, double* fillin_factor);
387 
388  void re_initialize();
390  void optimize();
391 
393  bool markHotStart();
394 
396  void unmarkHotStart();
397 
399  void copyFromHotStart();
400 
402  ~cachedInfo();
403  };
404 
407 
409  static std::string solverName_;
410 
412  int default_log_level_;
413 
414  public:
415 
416 #ifdef TIME_BQPD
417  Times &times(){ return cached_->times_;}
418 #endif
419 
420  };
421 
422 }// end namespace Bonmin
423 #endif
Bonmin::TNLPSolver::ReturnStatus
ReturnStatus
Standard return statuses for a solver.
Definition: BonTNLPSolver.hpp:29
Bonmin::BqpdSolver::markHotStart
virtual bool markHotStart()
Safe the current state (after most recent solve that must have been successful) as hot start informat...
Definition: BonBqpdSolver.hpp:94
Bonmin::BqpdSolver::setOutputToDefault
virtual void setOutputToDefault()
turn off all output from the solver
Definition: BonBqpdSolver.hpp:134
Bonmin
(C) Copyright International Business Machines Corporation 2007
Definition: BonAmplSetup.hpp:15
Bonmin::TNLPSolver::options
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
Definition: BonTNLPSolver.hpp:163
Bonmin::BqpdSolver::enableWarmStart
virtual void enableWarmStart()
Enable the warm start options in the solver.
Definition: BonBqpdSolver.hpp:109
Bonmin::BqpdSolver::~BqpdSolver
virtual ~BqpdSolver()
destructor
Bonmin::TNLPSolver::UnsolvedError
We will throw this error when a problem is not solved.
Definition: BonTNLPSolver.hpp:52
Bonmin::BqpdSolver::forceSolverOutput
virtual void forceSolverOutput(int log_level)
turn on all output from the solver
Definition: BonBqpdSolver.hpp:139
Bonmin::BqpdSolver::IterationCount
virtual int IterationCount()
Get the iteration count of the last optimization.
Definition: BonBqpdSolver.hpp:127
Bonmin::BqpdSolver::solverName
virtual std::string & solverName()
Get the solver name.
Definition: BonBqpdSolver.hpp:145
Bonmin::BqpdSolver::warmStartIsValid
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
Bonmin::TNLPSolver::UnsolvedError::errorNum
int errorNum() const
Return error number.
Definition: BonTNLPSolver.hpp:76
Bonmin::BqpdSolver::getEmptyWarmStart
virtual CoinWarmStart * getEmptyWarmStart() const
Bonmin::TNLPSolver
This is a generic class for calling an NLP solver to solve a TNLP.
Definition: BonTNLPSolver.hpp:26
Bonmin::BqpdSolver::getUsedWarmStart
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get warm start used in last optimization.
Definition: BonBqpdSolver.hpp:97
Bonmin::BqpdSolver::Initialize
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
Bonmin::TNLPSolver::journalist
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
Definition: BonTNLPSolver.hpp:155
Ipopt::SmartPtr
Bonmin::TNLPSolver::roptions_
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
Definition: BonTNLPSolver.hpp:222
ipfint
FORTRAN_INTEGER_TYPE ipfint
Bonmin::FilterSolver
Definition: BonFilterSolver.hpp:20
BonBranchingTQP.hpp
Bonmin::BqpdSolver
Definition: BonBqpdSolver.hpp:20
Bonmin::BqpdSolver::disableWarmStart
virtual void disableWarmStart()
Disable the warm start options in the solver.
Definition: BonBqpdSolver.hpp:112
Bonmin::BqpdSolver::fint
ipfint fint
Fortran type for integer used in filter.
Definition: BonBqpdSolver.hpp:46
Bonmin::BqpdSolver::BqpdSolver
BqpdSolver(bool createEmpty=false)
Default constructor.
Bonmin::BqpdSolver::UnsolvedBqpdError::errorName
virtual const std::string & errorName() const
Get the string corresponding to error.
Bonmin::BqpdSolver::setWarmStart
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
Bonmin::BqpdSolver::real
double real
Fortran type for double.used in filter.
Definition: BonBqpdSolver.hpp:48
Bonmin::BqpdSolver::CPUTime
virtual double CPUTime()
Get the CpuTime of the last optimization.
Definition: BonBqpdSolver.hpp:121
BonTNLPSolver.hpp
Ipopt::IsValid
bool IsValid(const SmartPtr< U > &smart_ptr)
CoinError
CoinWarmStart
Bonmin::BqpdSolver::UnsolvedBqpdError::~UnsolvedBqpdError
virtual ~UnsolvedBqpdError()
Definition: BonBqpdSolver.hpp:37
Bonmin::BqpdSolver::ReOptimizeTNLP
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
Bonmin::BqpdSolver::registerOptions
void registerOptions()
Register this solver options into passed roptions.
Definition: BonBqpdSolver.hpp:151
Bonmin::BqpdSolver::newUnsolvedError
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
Definition: BonBqpdSolver.hpp:51
Bonmin::TNLPSolver::prefix
const char * prefix()
Get the prefix.
Definition: BonTNLPSolver.hpp:171
Bonmin::BqpdSolver::getWarmStart
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
Bonmin::BqpdSolver::UnsolvedBqpdError::UnsolvedBqpdError
UnsolvedBqpdError(int errorNum, Ipopt::SmartPtr< TMINLP2TNLP > model, const std::string &name)
Definition: BonBqpdSolver.hpp:29
Bonmin::BqpdSolver::OptimizeTNLP
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
Bonmin::BqpdSolver::clone
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
Bonmin::BqpdSolver::UnsolvedBqpdError::solverName
virtual const std::string & solverName() const
Return the name of the solver.
Ipopt::ReferencedObject
Bonmin::TNLPSolver::roptions
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
Definition: BonTNLPSolver.hpp:159
Bonmin::BqpdSolver::UnsolvedBqpdError
Definition: BonBqpdSolver.hpp:26
Bonmin::BqpdSolver::errorCode
virtual int errorCode() const
Error code (solver specific).
Definition: BonBqpdSolver.hpp:157