Bonmin 1.8.9
Loading...
Searching...
No Matches
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"
20#include "CoinTime.hpp"
21namespace Bonmin {
27 public:
28
45
46
47
48//#############################################################################
49
53 {
54 public:
56 UnsolvedError(int errorNum = -10000,
58 std::string name="")
59 :
60 errorNum_(errorNum),
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
89
91 std::string name_;
92 }
93 ;
94
97 std::string name) = 0;
98
99
100
103
108 const std::string & prefix);
109
112
114 virtual ~TNLPSolver();
115
118 virtual bool Initialize(std::string params_file) = 0;
119
122 virtual bool Initialize(std::istream& is) = 0;
123
128
131
133 virtual bool setWarmStart(const CoinWarmStart * warm,
135
138
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
157
161
165
169
171 const char * prefix(){
172 return prefix_.c_str();
173 }
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
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;}
205virtual int errorCode() const = 0;
206protected:
210 ReturnStatus &optimization_status);
211
214
217
220
223
225 std::string prefix_;
228
231
235 TNLPSolver(const TNLPSolver & other);
236
237};
238}
239#endif
240
241
We will throw this error when a problem is not solved.
virtual const std::string & solverName() const =0
Return the name of the solver.
virtual ~UnsolvedError()
destructor.
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
virtual const std::string & errorName() const =0
Get the string corresponding to error.
void printError(std::ostream &os)
Print error message.
UnsolvedError(int errorNum=-10000, Ipopt::SmartPtr< TMINLP2TNLP > model=NULL, std::string name="")
Constructor.
int errorNum() const
Return error number.
This is a generic class for calling an NLP solver to solve a TNLP.
virtual int IterationCount()=0
Get the iteration count of the last optimization.
ReturnStatus
Standard return statuses for a solver.
@ numReturnCodes
Fake member to know size.
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Resolves a problem expresses as a TNLP.
virtual void setOutputToDefault()=0
turn off all output from the solver
bool isRecoverable(ReturnStatus &r)
Say if an optimization status for a problem which failed is recoverable (problem may be solvable).
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
double start_time_
Global start time.
static void RegisterOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register this solver options into passed roptions.
virtual CoinWarmStart * getEmptyWarmStart() const =0
virtual bool warmStartIsValid(const CoinWarmStart *ws) const =0
Check that warm start object is valid.
virtual void enableWarmStart()=0
Enable the warm start options in the solver.
virtual double CPUTime()=0
Get the CpuTime of the last optimization.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
void setup_global_time_limit(double time_limit)
Setup for a global time limit for solver.
TNLPSolver()
default Constructor
virtual void disableWarmStart()=0
Disable the warm start options in the solver.
virtual int errorCode() const =0
Error code (solver specific).
bool isError(ReturnStatus &r)
Say if return status is an error.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
virtual std::string & solverName()=0
Get the solver name.
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get the warm start form the solver.
virtual bool Initialize(std::istream &is)=0
Initialize the TNLPSolver (read options from istream is)
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.
virtual bool Initialize(std::string params_file)=0
Initialize the TNLPSolver (read options from params_file)
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)=0
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Get the options (for getting and setting their values).
int default_log_level_
To record default log level.
TNLPSolver(const TNLPSolver &other)
Copy Constructor.
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
virtual void forceSolverOutput(int log_level)=0
turn on all output from the solver
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)=0
Set the warm start in the solver.
double time_limit_
Global time limit.
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
std::string prefix_
Prefix to use for reading bonmin's options.
const char * prefix()
Get the prefix.
void initializeOptionsAndJournalist()
Initializes options and journalist.
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Solves a problem expresses as a TNLP.
virtual Ipopt::SmartPtr< TNLPSolver > clone()=0
virtual copy constructor
TNLPSolver(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, const std::string &prefix)
Constructor with options initialization.
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get warm start used in last optimization.
virtual ~TNLPSolver()
Virtual destructor.
(C) Copyright International Business Machines Corporation 2007
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)