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:
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,
53  std::string name)
54  {
55  return new UnsolvedFilterError(num, problem, name);
56  }
57 
58 
60  FilterSolver(bool createEmpty = false);
61 
62 
67  const std::string & prefix
68  );
69 
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 
93 
96 
98  virtual bool setWarmStart(const CoinWarmStart * warm,
100 
103  if(warmF_.IsValid())
104  return new FilterWarmStart(*warmF_);
105  else return NULL;
106  }
107 
108 
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 
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  }
173  private:
177  TNLPSolver::ReturnStatus callOptimizer();
180 
182  struct cachedInfo : public Coin::ReferencedObject
183  {
184  fint n;
185  fint m;
186  fint nnz_h_;
187  fint kmax;
188  fint maxa;
189  fint maxf;
190  fint mlp;
191  fint maxWk;
192  fint maxiWk;
193  fint iprint;
194  fint nout;
195  fint ifail;
196  real rho;
197  real * x;
198  real * c;
199  real f;
200  real fmin;
201  real * bounds;
202  real * s;
203  real * a;
204  fint * la;
205  real * ws;
206  fint * lws;
207  real * lam;
208  char * cstype;
209  fint maxiter;
210  fint * istat;
211  real * rstat;
212  Ipopt::TNLP * tnlp_;
213  fint * hStruct_;
214  int * permutationJac_;
215  int * permutationHess_;
217  double cpuTime_;
220  bool use_warm_start_in_cache_;
221 
222 
224  cachedInfo():
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),
258  use_warm_start_in_cache_(false)
259  {}
260 
261  cachedInfo(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
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),
296  use_warm_start_in_cache_(false)
297  {
298  initialize(tnlp, options);
299  }
300 
302  void initialize(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
304 
306  void optimize();
307 
309  ~cachedInfo()
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 
334 
335  //name of solver (Filter)
336  static std::string solverName_;
337 
339  int default_log_level_;
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 const std::string & errorName() const
Get the string corresponding to error.
UnsolvedFilterError(int errorNum, Ipopt::SmartPtr< TMINLP2TNLP > model, const std::string &name)
virtual const std::string & solverName() const
Return the name of the solver.
FilterSolver(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist)
Constructor with passed journalist, roptions, options.
virtual void setOutputToDefault()
turn off all output from the solver
FilterSolver(const FilterSolver &other)
Copy constructor.
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
virtual void enableWarmStart()
Enable the warm start options in the solver.
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get warm start used in last optimization.
virtual int errorCode() const
Error code (solver specific).
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
virtual void disableWarmStart()
Disable the warm start options in the solver.
virtual double CPUTime()
Get the CpuTime of the last optimization.
virtual bool Initialize(std::istream &is)
Initialize the TNLPSolver (read options from istream is)
FilterTypes::real real
Fortran type for double.used in filter.
FilterSolver(bool createEmpty=false)
Default constructor.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register this solver options into passed roptions.
FilterSolver(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, const std::string &prefix)
Constructor with passed journalist, roptions, options.
FilterTypes::fint fint
Fortran type for integer used in filter.
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
void registerOptions()
Register this solver options into passed roptions.
virtual Ipopt::SmartPtr< TNLPSolver > clone()
Virtual copy constructor.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
virtual void forceSolverOutput(int log_level)
turn on all output from the solver
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
virtual std::string & solverName()
Get the solver name.
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
friend struct BqpdSolver::cachedInfo
virtual int IterationCount()
Get the iteration count of the last optimization.
virtual CoinWarmStart * getEmptyWarmStart() const
virtual ~FilterSolver()
destructor
Warm start for filter interface.
We will throw this error when a problem is not solved.
int errorNum() const
Return error number.
This is a generic class for calling an NLP solver to solve a TNLP.
ReturnStatus
Standard return statuses for a solver.
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
const char * prefix()
Get the prefix.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
(C) Copyright International Business Machines Corporation 2007
double real
Fortran type for double.used in filter.
FORTRAN_INTEGER_TYPE fint
Fortran type for integer used in filter.
int Index