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:
30  Ipopt::SmartPtr<TMINLP2TNLP> model,
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*
52  Ipopt::SmartPtr<TMINLP2TNLP> problem,
53  std::string name)
54  {
55  return new UnsolvedBqpdError(num, problem, name);
56  }
57 
59  BqpdSolver(bool createEmpty = false);
60 
62  BqpdSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
63  Ipopt::SmartPtr<Ipopt::OptionsList> options,
64  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
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 
81  virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
83 
85  virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
86 
88  virtual bool setWarmStart(const CoinWarmStart * warm,
89  Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
90 
94  virtual bool markHotStart(){return cached_->markHotStart();}
95 
97  virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const{
98  throw CoinError(__PRETTY_FUNCTION__,"","Not implemented");
99  }
100 
102  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
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 
118  virtual Ipopt::SmartPtr<TNLPSolver> clone();
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 
185  static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
186  private:
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 
216  real* a;
218  real* x;
222  real* g;
223  real* r;
224  real* w;
225  real* e;
235  fint info[1];
238 
241 
288 
289  Ipopt::SmartPtr<BranchingTQP> tqp_;
291  double cpuTime_;
296 
298  int amax_;
299 
303  double* fillin_factor_;
305 
309  int pivots_;
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),
340  bad_warm_start_info_(false),
341  next_reinit_(0),
342  pivots_(0)
343  {}
344 
345  cachedInfo(const Ipopt::SmartPtr<BranchingTQP> &tqp,
346  Ipopt::SmartPtr<Ipopt::OptionsList>& options,
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),
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,
385  Ipopt::SmartPtr<Ipopt::OptionsList>& options,
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 
406  Ipopt::SmartPtr<cachedInfo> cached_;
407 
409  static std::string solverName_;
410 
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
fint lm
bqpdc common block
fint m2
bqpdc common block
fint ns1
bqpdc common block
fint nx
bqpdc common block
int pivots_
Number of pivots.
TNLPSolver::ReturnStatus callOptimizer()
Perform optimization using data structure in cache.
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
fint mp
bqpdc common block
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
double cpuTime_
Elapsed CPU time in last optimization.
UnsolvedBqpdError(int errorNum, Ipopt::SmartPtr< TMINLP2TNLP > model, const std::string &name)
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
fint lq
bqpdc common block
fint nprof
bqpdc common block
virtual int IterationCount()
Get the iteration count of the last optimization.
virtual std::string & solverName()
Get the solver name.
fint na
bqpdc common block
virtual bool markHotStart()
Safe the current state (after most recent solve that must have been successful) as hot start informat...
virtual void disableWarmStart()
Solves a problem expresses as a TNLP.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
fint li1
bqpdc common block
Ipopt::SmartPtr< BranchingTQP > tqp_
int mlp_ipt_
Fill-in factor for QP factorization.
fint nu
bqpdc common block
void unmarkHotStart()
Forget about the hot start info.
fint na1
bqpdc common block
static int reinit_freq_
Hot start reinitialization fequency.
bool use_warm_start_in_cache_
flag remembering if warm start information has been put into cache
fint nu1
bqpdc common block
This is a generic class for calling an NLP solver to solve a TNLP.
real sgnf
repc common block
fint lt1
bqpdc common block
real emin
bqpdc common block
fint nb1
bqpdc common block
virtual const std::string & errorName() const
Get the string corresponding to error.
fint irh1
bqpdc common block
virtual ~BqpdSolver()
destructor
fint ka1
bqpdc common block
real vstep
vstepc common block
fint lv1
bqpdc common block
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
fint nt
bqpdc common block
fint lr1
bqpdc common block
virtual void enableWarmStart()
Solves a problem expresses as a TNLP.
ipfint fint
Fortran type for integer used in filter.
fint lc1
bqpdc common block
fint lp1
bqpdc common block
real tol
bqpdc common block
int default_log_level_
To record default log level.
fint li
bqpdc common block
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
fint lastr
bqpdc common block
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
virtual void setOutputToDefault()
turn off all output from the solver
int errorNum() const
Return error number.
fint lv
bqpdc common block
fint nres
bqpdc common block
virtual int errorCode() const
Error code (solver specific).
fint lq1
bqpdc common block
fint np1
bqpdc common block
virtual void forceSolverOutput(int log_level)
turn on all output from the solver
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
fint nx1
bqpdc common block
bool markHotStart()
Store most recent solution as hot start.
fint m1
factorc common block
fint mxm1
mxm1c common block
real eps
epsc common block
int next_reinit_
next reinitialization of hot start.
static int m0de_
Hot start m0de.
double fillin_factor_
Fill-in factor for QP factorization.
void registerOptions()
Register this solver options into passed roptions.
fint ns
sparsec common block
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
fint ls1
bqpdc common block
void copyFromHotStart()
Copy current values from hot start info.
real alpha
alphac common block
cachedInfo(const Ipopt::SmartPtr< BranchingTQP > &tqp, Ipopt::SmartPtr< Ipopt::OptionsList > &options, int kmax_ipt, int mlp_ipt, double *fillin_factor)
fint lc
bqpdc common block
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
bool haveHotStart_
indicates if we should start from a hotstart
int kmax_ipt_
Fill-in factor for QP factorization.
fint irg1
bqpdc common block
fint ll1
bqpdc common block
ReturnStatus
Standard return statuses for a solver.
double * fillin_factor_
Fill-in factor for QP factorization.
fint nb
bqpdc common block
fint lm1
bqpdc common block
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
fint npiv
bqpdc common block
fint lp_
bqpdc common block
Ipopt::SmartPtr< cachedInfo > cached_
Cached information on last problem optimized for reoptimization.
fint nfreq
bqpdc common block
void initialize(const Ipopt::SmartPtr< BranchingTQP > &tqp, Ipopt::SmartPtr< Ipopt::OptionsList > &options, int kmax_ipt, int mlp_ipt, double *fillin_factor)
Fill data structures for filter with info from tnlp.
We will throw this error when a problem is not solved.
virtual double CPUTime()
Get the CpuTime of the last optimization.
BqpdSolver(bool createEmpty=false)
Default constructor.
fint mq
bqpdc common block
void optimize()
Optimize problem described by cache with filter.
virtual const std::string & solverName() const
Return the name of the solver.
fint np
bqpdc common block
fint ls_
bqpdc common block
fint lu1
bqpdc common block
fint irow
bqpdc common block
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get warm start used in last optimization.
fint kc1
bqpdc common block
int amax_
Number of nonzeros in Jacobian and gradient.
static std::string solverName_
To record default log level.
fint nt1
bqpdc common block
Cached information for reoptimizing.
double real
Fortran type for double.used in filter.
const char * prefix()
Get the prefix.
fint nup
refactorc common block
fint nrep
bqpdc common block
fint kb1
bqpdc common block
fint lt
bqpdc common block
fint lr
bqpdc common block