Bonmin  1.8.8
BonTNLPSolver.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines (IBM) 2006, 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 
11 #ifndef TNLPSolver_H
12 #define TNLPSolver_H
13 #include "IpTNLP.hpp"
14 #include "BonTMINLP2TNLP.hpp"
15 
16 //Some declarations
17 #include "IpOptionsList.hpp"
18 #include "CoinWarmStart.hpp"
19 #include "BonRegisteredOptions.hpp"
20 #include "CoinTime.hpp"
21 namespace Bonmin {
26 class TNLPSolver: public Ipopt::ReferencedObject{
27  public:
28 
29  enum ReturnStatus {
31  timeLimit = 5,
38  exception =-7,
42  unbounded = 4,
44  };
45 
46 
47 
48 //#############################################################################
49 
53  {
54  public:
56  UnsolvedError(int errorNum = -10000,
57  Ipopt::SmartPtr<TMINLP2TNLP> model = NULL,
58  std::string name="")
59  :
61  model_(model),
62  name_(name)
63  {if(name_=="")
64 {
65 #ifndef NDEBUG
66  std::cerr<<"FIXME"<<std::endl;
67 #endif
68 }}
70  void printError(std::ostream & os);
72  virtual const std::string& errorName() const = 0;
74  virtual const std::string& solverName() const = 0;
76  int errorNum() const{
77  return errorNum_;}
79  virtual ~UnsolvedError(){}
82  void writeDiffFiles(const std::string prefix=std::string()) const;
83  private:
85  int errorNum_;
86 
88  Ipopt::SmartPtr< TMINLP2TNLP > model_;
89 
91  std::string name_;
92  }
93  ;
94 
95  virtual UnsolvedError * newUnsolvedError(int num,
96  Ipopt::SmartPtr<TMINLP2TNLP> problem,
97  std::string name) = 0;
98 
99 
100 
102  TNLPSolver();
103 
105 TNLPSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
106  Ipopt::SmartPtr<Ipopt::OptionsList> options,
107  Ipopt::SmartPtr<Ipopt::Journalist> journalist,
108  const std::string & prefix);
109 
111  virtual Ipopt::SmartPtr<TNLPSolver> clone() = 0;
112 
114  virtual ~TNLPSolver();
115 
118  virtual bool Initialize(std::string params_file) = 0;
119 
122  virtual bool Initialize(std::istream& is) = 0;
123 
126  virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
128 
130  virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp) = 0;
131 
133  virtual bool setWarmStart(const CoinWarmStart * warm,
134  Ipopt::SmartPtr<TMINLP2TNLP> tnlp) = 0;
135 
137  virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
138 
140  virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const = 0;
141 
142  virtual CoinWarmStart * getEmptyWarmStart() const = 0;
143 
145  virtual bool warmStartIsValid(const CoinWarmStart * ws) const = 0;
146 
148  virtual void enableWarmStart() = 0;
149 
151  virtual void disableWarmStart() = 0;
153 
155  Ipopt::SmartPtr<Ipopt::Journalist> journalist(){
156  return journalist_;}
157 
159  Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions(){
160  return roptions_;}
161 
163  Ipopt::SmartPtr<const Ipopt::OptionsList> options() const {
164  return ConstPtr(options_);}
165 
167  Ipopt::SmartPtr<Ipopt::OptionsList> options() {
168  return options_;}
169 
171  const char * prefix(){
172  return prefix_.c_str();
173  }
175 static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){}
176 
178  virtual double CPUTime() = 0;
179 
181  virtual int IterationCount() = 0;
182 
183 
185  virtual void setOutputToDefault() = 0 ;
187  virtual void forceSolverOutput(int log_level) = 0;
189  virtual std::string & solverName() = 0;
190 
193  bool isRecoverable(ReturnStatus &r);
194 
196  void setup_global_time_limit(double time_limit){
197  time_limit_ = time_limit + 5;
198  start_time_ = CoinCpuTime();
199  }
200 
203  return r < 0;}
205 virtual int errorCode() const = 0;
206 protected:
209  bool zeroDimension(const Ipopt::SmartPtr<Ipopt::TNLP> &tnlp,
210  ReturnStatus &optimization_status);
211 
214 
216  Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
217 
219  Ipopt::SmartPtr<Ipopt::OptionsList> options_;
220 
222  Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
223 
225  std::string prefix_;
227  double start_time_;
228 
230  double time_limit_;
231 
235  TNLPSolver(const TNLPSolver & other);
236 
237 };
238 }
239 #endif
240 
241 
int default_log_level_
To record default log level.
virtual Ipopt::SmartPtr< TNLPSolver > clone()=0
virtual copy constructor
UnsolvedError(int errorNum=-10000, Ipopt::SmartPtr< TMINLP2TNLP > model=NULL, std::string name="")
Constructor.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Get the options (for getting and setting their values).
bool isError(ReturnStatus &r)
Say if return status is an error.
void initializeOptionsAndJournalist()
Initializes options and journalist.
virtual double CPUTime()=0
Get the CpuTime of the last optimization.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
virtual ~UnsolvedError()
destructor.
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Resolves a problem expresses as a TNLP.
std::string prefix_
Prefix to use for reading bonmin&#39;s options.
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
This is a generic class for calling an NLP solver to solve a TNLP.
virtual const std::string & errorName() const =0
Get the string corresponding to error.
double start_time_
Global start time.
void setup_global_time_limit(double time_limit)
Setup for a global time limit for solver.
double time_limit_
Global time limit.
virtual CoinWarmStart * getEmptyWarmStart() const =0
Solves a problem expresses as a TNLP.
virtual void setOutputToDefault()=0
turn off all output from the solver
static void RegisterOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register this solver options into passed roptions.
int errorNum() const
Return error number.
int errorNum_
Error code (solver dependent).
virtual const std::string & solverName() const =0
Return the name of the solver.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)=0
Set the warm start in the solver.
virtual int IterationCount()=0
Get the iteration count of the last optimization.
virtual std::string & solverName()=0
Get the solver name.
void printError(std::ostream &os)
Print error message.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
virtual void enableWarmStart()=0
Enable the warm start options in the solver.
ReturnStatus
Standard return statuses for a solver.
virtual bool warmStartIsValid(const CoinWarmStart *ws) const =0
Check that warm start object is valid.
bool isRecoverable(ReturnStatus &r)
Say if an optimization status for a problem which failed is recoverable (problem may be solvable)...
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get the warm start form the solver.
virtual void forceSolverOutput(int log_level)=0
turn on all output from the solver
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
std::string name_
name of the model on which error occured.
We will throw this error when a problem is not solved.
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get warm start used in last optimization.
TNLPSolver()
default Constructor
virtual void disableWarmStart()=0
Disable the warm start options in the solver.
virtual bool Initialize(std::string params_file)=0
Initialize the TNLPSolver (read options from params_file)
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Solves a problem expresses as a TNLP.
virtual ~TNLPSolver()
Virtual destructor.
bool zeroDimension(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, ReturnStatus &optimization_status)
Determine if problem is of dimension zero and if it is check if solution is feasible.
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
const char * prefix()
Get the prefix.
virtual int errorCode() const =0
Error code (solver specific).
Ipopt::SmartPtr< TMINLP2TNLP > model_
model_ on which error occured
Fake member to know size.
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)=0