Bonmin  1.8.8
BonFilterSolver.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation, 2006, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 10/02/2006
9 
10 #ifndef FilterSolver_H
11 #define FilterSolver_H
12 
13 #include "BonTNLPSolver.hpp"
14 #include "BonFilterTypes.hpp"
15 #include "BonBqpdSolver.hpp"
16 #include "BonFilterWarmStart.hpp"
17 
18 namespace Bonmin
19 {
20  class FilterSolver : public TNLPSolver
21  {
22  public:
23 
24  friend struct BqpdSolver::cachedInfo;
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 
49 
50 
51  virtual UnsolvedError * newUnsolvedError(int num,
52  Ipopt::SmartPtr<TMINLP2TNLP> problem,
53  std::string name)
54  {
55  return new UnsolvedFilterError(num, problem, name);
56  }
57 
58 
60  FilterSolver(bool createEmpty = false);
61 
62 
64  FilterSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
65  Ipopt::SmartPtr<Ipopt::OptionsList> options,
66  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
67  const std::string & prefix
68  );
69 
71  FilterSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
72  Ipopt::SmartPtr<Ipopt::OptionsList> options,
73  Ipopt::SmartPtr<Ipopt::Journalist> journalist
74  );
75 
77  FilterSolver(const FilterSolver & other);
79  virtual ~FilterSolver();
80 
83  virtual bool Initialize(std::string params_file);
84 
87  virtual bool Initialize(std::istream& is);
88 
91  virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
93 
95  virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
96 
98  virtual bool setWarmStart(const CoinWarmStart * warm,
99  Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
100 
102  virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const{
103  if(warmF_.IsValid())
104  return new FilterWarmStart(*warmF_);
105  else return NULL;
106  }
107 
108 
110  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
111 
112  virtual CoinWarmStart * getEmptyWarmStart() const;
113 
115  virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
116 
117 
118  virtual void enableWarmStart()
119  {//No options to be set
120  }
121  virtual void disableWarmStart()
122  {
123  warmF_ = NULL;
124  //No options to be set
125  }
127 
129  virtual Ipopt::SmartPtr<TNLPSolver> clone();
130 
132  virtual double CPUTime()
133  {
134  return (cached_.IsValid()) ? cached_->cpuTime_: 0.;
135  }
136 
138  virtual int IterationCount()
139  {
140  return (cached_.IsValid()) ? cached_->istat[1]:0;
141  }
142 
144  virtual void setOutputToDefault()
145  {
146  if (cached_.IsValid()) cached_->iprint = default_log_level_;
147  }
149  virtual void forceSolverOutput(int log_level)
150  {
151  if (cached_.IsValid()) cached_->iprint = log_level;
152  }
153 
155  virtual std::string & solverName()
156  {
157  return solverName_;
158  }
159 
162  {
164  }
165 
167  virtual int errorCode() const
168  {
169  return -1;
170  }
172  static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
173  private:
179  Coin::SmartPtr<FilterWarmStart> warmF_;
180 
182  struct cachedInfo : public Coin::ReferencedObject
183  {
197  real * x;
198  real * c;
202  real * s;
203  real * a;
204  fint * la;
205  real * ws;
208  char * cstype;
212  Ipopt::TNLP * tnlp_;
217  double cpuTime_;
221 
222 
225  n(-1),
226  m(-1),
227  nnz_h_(-1),
228  kmax(-1),
229  maxa(-1),
230  maxf(-1),
231  mlp(-1),
232  maxWk(-1),
233  maxiWk(-1),
234  iprint(-1),
235  nout(6),
236  ifail(-100),
237  rho(0),
238  x(NULL),
239  c(NULL),
240  f(1e100),
241  fmin(-1e100),
242  bounds(NULL),
243  s(NULL),
244  a(NULL),
245  la(NULL),
246  ws(NULL),
247  lws(NULL),
248  lam(NULL),
249  cstype(NULL),
250  maxiter(1000),
251  istat(NULL),
252  rstat(NULL),
253  tnlp_(NULL),
254  hStruct_(NULL),
255  permutationJac_(NULL),
256  permutationHess_(NULL),
257  cpuTime_(0),
259  {}
260 
261  cachedInfo(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
262  Ipopt::SmartPtr<Ipopt::OptionsList>& options):
263  n(-1),
264  m(-1),
265  nnz_h_(-1),
266  kmax(-1),
267  maxa(-1),
268  maxf(-1),
269  mlp(-1),
270  maxWk(-1),
271  maxiWk(-1),
272  iprint(-1),
273  nout(6),
274  ifail(0),
275  rho(0),
276  x(NULL),
277  c(NULL),
278  f(1e100),
279  fmin(-1e100),
280  bounds(NULL),
281  s(NULL),
282  a(NULL),
283  la(NULL),
284  ws(NULL),
285  lws(NULL),
286  lam(NULL),
287  cstype(NULL),
288  maxiter(1000),
289  istat(NULL),
290  rstat(NULL),
291  tnlp_(NULL),
292  hStruct_(NULL),
293  permutationJac_(NULL),
294  permutationHess_(NULL),
295  cpuTime_(0),
297  {
298  initialize(tnlp, options);
299  }
300 
302  void initialize(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
303  Ipopt::SmartPtr<Ipopt::OptionsList>& options);
304 
306  void optimize();
307 
310  {
311  delete [] x;
312  delete [] c;
313  delete [] bounds;
314  delete [] s;
315  delete [] a;
316  delete [] la;
317  delete [] ws;
318  delete [] lws;
319  delete [] lam;
320  delete [] cstype;
321  delete [] istat;
322  delete [] rstat;
323  delete [] permutationJac_;
324  delete [] permutationHess_;
325  delete [] hStruct_;
326  tnlp_ = NULL;
327  }
328 
329  void load_ws(Coin::SmartPtr<FilterWarmStart>);
330  };
331 
333  Coin::SmartPtr<cachedInfo> cached_;
334 
335  //name of solver (Filter)
336  static std::string solverName_;
337 
341  static void TMat2RowPMat(bool symmetric, fint n, fint m, int nnz, const Ipopt::Index* iRow,
342  const Ipopt::Index* iCol, int * permutation2,
343  fint * lws, int nnz_offset, int n_offset,
344  Ipopt::TNLP::IndexStyleEnum index_style);
345  };
346 
347 }// end namespace Bonmin
348 #endif
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
Coin::SmartPtr< FilterWarmStart > warmF_
cachedInfo(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, Ipopt::SmartPtr< Ipopt::OptionsList > &options)
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
TNLPSolver::ReturnStatus callOptimizer()
Perform optimization using data structure in cache.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get warm start used in last optimization.
UnsolvedFilterError(int errorNum, Ipopt::SmartPtr< TMINLP2TNLP > model, const std::string &name)
int default_log_level_
To record default log level.
static std::string solverName_
This is a generic class for calling an NLP solver to solve a TNLP.
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
void optimize()
Optimize problem described by cache with filter.
virtual double CPUTime()
Get the CpuTime of the last optimization.
virtual int IterationCount()
Get the iteration count of the last optimization.
void initialize(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, Ipopt::SmartPtr< Ipopt::OptionsList > &options)
Fill data structures for filter with info from tnlp.
virtual ~FilterSolver()
destructor
virtual const std::string & solverName() const
Return the name of the solver.
virtual int errorCode() const
Error code (solver specific).
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
int errorNum() const
Return error number.
double cpuTime_
Elapsed CPU time in last optimization.
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
virtual void enableWarmStart()
Solves a problem expresses as a TNLP.
FilterSolver(bool createEmpty=false)
Default constructor.
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
Warm start for filter interface.
FilterTypes::real real
Fortran type for double.used in filter.
Cached information for reoptimizing.
virtual void setOutputToDefault()
turn off all output from the solver
void load_ws(Coin::SmartPtr< FilterWarmStart >)
virtual void disableWarmStart()
Solves a problem expresses as a TNLP.
Coin::SmartPtr< cachedInfo > cached_
Cached information on last problem optimized for reoptimization.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
ReturnStatus
Standard return statuses for a solver.
FORTRAN_INTEGER_TYPE fint
Fortran type for integer used in filter.
bool use_warm_start_in_cache_
flag remembering if warm start information has been put into cache
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
double real
Fortran type for double.used in filter.
We will throw this error when a problem is not solved.
virtual const std::string & errorName() const
Get the string corresponding to error.
void registerOptions()
Register this solver options into passed roptions.
virtual std::string & solverName()
Get the solver name.
virtual void forceSolverOutput(int log_level)
turn on all output from the solver
Cached information for reoptimizing.
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
const char * prefix()
Get the prefix.
FilterTypes::fint fint
Fortran type for integer used in filter.
static void TMat2RowPMat(bool symmetric, fint n, fint m, int nnz, const Ipopt::Index *iRow, const Ipopt::Index *iCol, int *permutation2, fint *lws, int nnz_offset, int n_offset, Ipopt::TNLP::IndexStyleEnum index_style)
Converting TMatrices into row-ordered matrices.