Bonmin  1.8.8
BonIpoptSolver.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines (IBM) 2005, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, IBM
7 //
8 // Date : 26/09/2006
9 
10 #ifndef IpoptSolver_HPP
11 #define IpoptSolver_HPP
12 #include "BonTNLPSolver.hpp"
13 #include "IpIpoptApplication.hpp"
14 
15 
16 namespace Bonmin
17 {
18  class IpoptSolver: public TNLPSolver
19  {
20  public:
22  {
23  public:
25  Ipopt::SmartPtr<TMINLP2TNLP> problem,
26  std::string name):
27  TNLPSolver::UnsolvedError(errorNum, problem, name)
28  {}
29  virtual const std::string& errorName() const;
30 
31  virtual const std::string& solverName() const;
33  {}
34  private:
35  static std::string errorNames [17];
36  static std::string solverName_;
37  };
38 
39  virtual UnsolvedError * newUnsolvedError(int num,
40  Ipopt::SmartPtr<TMINLP2TNLP> problem,
41  std::string name)
42  {
43  return new UnsolvedIpoptError(num, problem, name);
44  }
45 
46 
47 
49  IpoptSolver(bool createEmpty = false);
50 
52  IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
53  Ipopt::SmartPtr<Ipopt::OptionsList> options,
54  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
55  const std::string & prefix);
56 
58  IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
59  Ipopt::SmartPtr<Ipopt::OptionsList> options,
60  Ipopt::SmartPtr<Ipopt::Journalist> journalist);
61 
63  IpoptSolver(const IpoptSolver &other);
64 
66  virtual Ipopt::SmartPtr<TNLPSolver> clone();
67 
69  virtual ~IpoptSolver();
70 
73  virtual bool Initialize(std::string params_file);
74 
77  virtual bool Initialize(std::istream& is);
78 
81  virtual TNLPSolver::ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
83 
85  virtual TNLPSolver::ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
86 
88  virtual bool setWarmStart(const CoinWarmStart * warm,
89  Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
90 
92  virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
93 
94 
96  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<Bonmin::TMINLP2TNLP> tnlp) const;
97 
98  virtual CoinWarmStart * getEmptyWarmStart() const;
99 
101  virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
102 
104  virtual void enableWarmStart();
105 
107  virtual void disableWarmStart();
108 
110 
112  virtual double CPUTime();
113 
115  virtual int IterationCount();
116 
118  virtual void setOutputToDefault();
120  virtual void forceSolverOutput(int log_level);
121 
123  virtual std::string & solverName()
124  {
125  return solverName_;
126  }
127 
129  static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
130  {
131  Ipopt::IpoptApplication::RegisterAllIpoptOptions(GetRawPtr(roptions));
132  }
133 
134 
135 
137  Ipopt::ApplicationReturnStatus getOptStatus() const
138  {
139  return optimizationStatus_;
140  }
141 
142  Ipopt::IpoptApplication& getIpoptApp()
143  {
144  return *app_;
145  }
146 
147  virtual int errorCode() const
148  {
149  return (int) optimizationStatus_;
150  }
151  private:
153  void setMinlpDefaults(Ipopt::SmartPtr< Ipopt::OptionsList> Options);
154 
156  TNLPSolver::ReturnStatus solverReturnStatus(Ipopt::ApplicationReturnStatus optimization_status) const;
157 
159  Ipopt::SmartPtr<Ipopt::IpoptApplication> app_;
161  Ipopt::ApplicationReturnStatus optimizationStatus_;
163 
164 
167 
176 
179 
183  //name of solver (Ipopt)
184  static std::string solverName_;
185  };
186 }
187 #endif
188 
virtual TNLPSolver::ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Solves a problem expresses as a TNLP.
UnsolvedIpoptError(int errorNum, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
virtual TNLPSolver::ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)
Resolves a problem expresses as a TNLP.
void setMinlpDefaults(Ipopt::SmartPtr< Ipopt::OptionsList > Options)
Set default Ipopt parameters for use in a MINLP.
virtual const std::string & solverName() const
Return the name of the solver.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
virtual Ipopt::SmartPtr< TNLPSolver > clone()
virtual copy constructor
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
bool problemHadZeroDimension_
Flag to indicate if last problem solved had 0 dimension.
virtual void disableWarmStart()
Disable the warm start options in the solver.
IpoptSolver(bool createEmpty=false)
Constructor.
This is a generic class for calling an NLP solver to solve a TNLP.
virtual void setOutputToDefault()
turn off all output from the solver
static std::string solverName_
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)
Set the warm start in the solver.
virtual int errorCode() const
Error code (solver specific).
int errorNum() const
Return error number.
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< Bonmin::TMINLP2TNLP > tnlp) const
Get the warm start form the solver.
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)
Ipopt::ApplicationReturnStatus optimizationStatus_
return status of last optimization.
virtual std::string & solverName()
Get the solver name.
virtual ~IpoptSolver()
Virtual destructor.
virtual double CPUTime()
Get the CpuTime of the last optimization.
Ipopt::SmartPtr< Ipopt::IpoptApplication > app_
Ipopt application.
static void RegisterOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register this solver options into passed roptions.
bool enable_warm_start_
flag remembering if we want to use warm start option
TNLPSolver::ReturnStatus solverReturnStatus(Ipopt::ApplicationReturnStatus optimization_status) const
get Bonmin return status from Ipopt one.
virtual bool Initialize(std::string params_file)
Initialize the TNLPSolver (read options from params_file)
ReturnStatus
Standard return statuses for a solver.
Ipopt::IpoptApplication & getIpoptApp()
virtual void forceSolverOutput(int log_level)
turn on all output from the solver
bool optimized_before_
flag remembering if we have call the Optimize method of the IpoptInterface before ...
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const
Get warm start used in last optimization.
We will throw this error when a problem is not solved.
virtual bool warmStartIsValid(const CoinWarmStart *ws) const
Check that warm start object is valid.
virtual CoinWarmStart * getEmptyWarmStart() const
Solves a problem expresses as a TNLP.
virtual void enableWarmStart()
Enable the warm start options in the solver.
virtual int IterationCount()
Get the iteration count of the last optimization.
int warmStartStrategy_
Warm start strategy :
Ipopt::ApplicationReturnStatus getOptStatus() const
Return status of last optimization.
virtual const std::string & errorName() const
Get the string corresponding to error.
const char * prefix()
Get the prefix.