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 {
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  :
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 
95  virtual UnsolvedError * newUnsolvedError(int num,
97  std::string name) = 0;
98 
99 
100 
102  TNLPSolver();
103 
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,
135 
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 
156  return journalist_;}
157 
160  return roptions_;}
161 
164  return ConstPtr(options_);}
165 
168  return options_;}
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 
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:
210  ReturnStatus &optimization_status);
211 
214 
217 
220 
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 
Bonmin::TNLPSolver::getUsedWarmStart
virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get warm start used in last optimization.
BonTMINLP2TNLP.hpp
Bonmin::TNLPSolver::newUnsolvedError
virtual UnsolvedError * newUnsolvedError(int num, Ipopt::SmartPtr< TMINLP2TNLP > problem, std::string name)=0
Bonmin::TNLPSolver::clone
virtual Ipopt::SmartPtr< TNLPSolver > clone()=0
virtual copy constructor
Bonmin::TNLPSolver::setOutputToDefault
virtual void setOutputToDefault()=0
turn off all output from the solver
Bonmin::TNLPSolver::UnsolvedError::solverName
virtual const std::string & solverName() const =0
Return the name of the solver.
Bonmin::TNLPSolver::doesNotConverge
@ doesNotConverge
Definition: BonTNLPSolver.hpp:32
Bonmin::TNLPSolver::ReturnStatus
ReturnStatus
Standard return statuses for a solver.
Definition: BonTNLPSolver.hpp:29
Bonmin::TNLPSolver::start_time_
double start_time_
Global start time.
Definition: BonTNLPSolver.hpp:227
Bonmin::TNLPSolver::options_
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
Definition: BonTNLPSolver.hpp:219
Bonmin::TNLPSolver::illDefinedProblem
@ illDefinedProblem
Definition: BonTNLPSolver.hpp:35
CoinTime.hpp
Bonmin::TNLPSolver::options
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Get the options (for getting and setting their values).
Definition: BonTNLPSolver.hpp:167
Bonmin
(C) Copyright International Business Machines Corporation 2007
Definition: BonAmplSetup.hpp:15
Bonmin::TNLPSolver::getEmptyWarmStart
virtual CoinWarmStart * getEmptyWarmStart() const =0
Bonmin::TNLPSolver::provenInfeasible
@ provenInfeasible
Definition: BonTNLPSolver.hpp:41
Bonmin::TNLPSolver::options
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
Definition: BonTNLPSolver.hpp:163
CoinWarmStart.hpp
Bonmin::TNLPSolver::UnsolvedError
We will throw this error when a problem is not solved.
Definition: BonTNLPSolver.hpp:52
Bonmin::TNLPSolver::CPUTime
virtual double CPUTime()=0
Get the CpuTime of the last optimization.
Bonmin::TNLPSolver::enableWarmStart
virtual void enableWarmStart()=0
Enable the warm start options in the solver.
Bonmin::TNLPSolver::unbounded
@ unbounded
Definition: BonTNLPSolver.hpp:42
Bonmin::TNLPSolver::externalException
@ externalException
Definition: BonTNLPSolver.hpp:37
Bonmin::TNLPSolver::computationError
@ computationError
Definition: BonTNLPSolver.hpp:33
Bonmin::TNLPSolver::OptimizeTNLP
virtual ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Solves a problem expresses as a TNLP.
Bonmin::TNLPSolver::exception
@ exception
Definition: BonTNLPSolver.hpp:38
Bonmin::TNLPSolver::UnsolvedError::errorNum
int errorNum() const
Return error number.
Definition: BonTNLPSolver.hpp:76
Bonmin::TNLPSolver::solvedOptimal
@ solvedOptimal
Definition: BonTNLPSolver.hpp:39
BonRegisteredOptions.hpp
Bonmin::TNLPSolver::UnsolvedError::writeDiffFiles
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
Bonmin::TNLPSolver
This is a generic class for calling an NLP solver to solve a TNLP.
Definition: BonTNLPSolver.hpp:26
Bonmin::TNLPSolver::solvedOptimalTol
@ solvedOptimalTol
Definition: BonTNLPSolver.hpp:40
Bonmin::TNLPSolver::zeroDimension
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.
Bonmin::TNLPSolver::Initialize
virtual bool Initialize(std::string params_file)=0
Initialize the TNLPSolver (read options from params_file)
Bonmin::TNLPSolver::journalist
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
Definition: BonTNLPSolver.hpp:155
Ipopt::SmartPtr
Bonmin::TNLPSolver::timeLimit
@ timeLimit
Definition: BonTNLPSolver.hpp:31
Bonmin::TNLPSolver::roptions_
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
Definition: BonTNLPSolver.hpp:222
Bonmin::TNLPSolver::isError
bool isError(ReturnStatus &r)
Say if return status is an error.
Definition: BonTNLPSolver.hpp:202
Bonmin::TNLPSolver::notEnoughFreedom
@ notEnoughFreedom
Definition: BonTNLPSolver.hpp:34
Bonmin::TNLPSolver::journalist_
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
Definition: BonTNLPSolver.hpp:216
Bonmin::TNLPSolver::RegisterOptions
static void RegisterOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register this solver options into passed roptions.
Definition: BonTNLPSolver.hpp:175
Bonmin::TNLPSolver::forceSolverOutput
virtual void forceSolverOutput(int log_level)=0
turn on all output from the solver
Bonmin::TNLPSolver::iterationLimit
@ iterationLimit
Definition: BonTNLPSolver.hpp:30
Bonmin::TNLPSolver::disableWarmStart
virtual void disableWarmStart()=0
Disable the warm start options in the solver.
Bonmin::TNLPSolver::time_limit_
double time_limit_
Global time limit.
Definition: BonTNLPSolver.hpp:230
Bonmin::TNLPSolver::prefix_
std::string prefix_
Prefix to use for reading bonmin's options.
Definition: BonTNLPSolver.hpp:225
ConstPtr
SmartPtr< const U > ConstPtr(const SmartPtr< U > &smart_ptr)
Bonmin::TNLPSolver::TNLPSolver
TNLPSolver()
default Constructor
Bonmin::TNLPSolver::numReturnCodes
@ numReturnCodes
Fake member to know size.
Definition: BonTNLPSolver.hpp:43
Bonmin::TNLPSolver::setup_global_time_limit
void setup_global_time_limit(double time_limit)
Setup for a global time limit for solver.
Definition: BonTNLPSolver.hpp:196
Bonmin::TNLPSolver::UnsolvedError::UnsolvedError
UnsolvedError(int errorNum=-10000, Ipopt::SmartPtr< TMINLP2TNLP > model=NULL, std::string name="")
Constructor.
Definition: BonTNLPSolver.hpp:56
CoinWarmStart
Bonmin::TNLPSolver::default_log_level_
int default_log_level_
To record default log level.
Definition: BonTNLPSolver.hpp:233
Bonmin::TNLPSolver::errorCode
virtual int errorCode() const =0
Error code (solver specific).
Bonmin::TNLPSolver::isRecoverable
bool isRecoverable(ReturnStatus &r)
Say if an optimization status for a problem which failed is recoverable (problem may be solvable).
Bonmin::TNLPSolver::ReOptimizeTNLP
virtual ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp)=0
Resolves a problem expresses as a TNLP.
Bonmin::TNLPSolver::setWarmStart
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)=0
Set the warm start in the solver.
Bonmin::TNLPSolver::~TNLPSolver
virtual ~TNLPSolver()
Virtual destructor.
Bonmin::TNLPSolver::solverName
virtual std::string & solverName()=0
Get the solver name.
Bonmin::TNLPSolver::getWarmStart
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get the warm start form the solver.
Bonmin::TNLPSolver::prefix
const char * prefix()
Get the prefix.
Definition: BonTNLPSolver.hpp:171
Bonmin::TNLPSolver::UnsolvedError::errorName
virtual const std::string & errorName() const =0
Get the string corresponding to error.
Bonmin::TNLPSolver::IterationCount
virtual int IterationCount()=0
Get the iteration count of the last optimization.
Bonmin::TNLPSolver::UnsolvedError::printError
void printError(std::ostream &os)
Print error message.
Bonmin::TNLPSolver::initializeOptionsAndJournalist
void initializeOptionsAndJournalist()
Initializes options and journalist.
IpOptionsList.hpp
Ipopt::ReferencedObject
Bonmin::TNLPSolver::roptions
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
Definition: BonTNLPSolver.hpp:159
Bonmin::TNLPSolver::warmStartIsValid
virtual bool warmStartIsValid(const CoinWarmStart *ws) const =0
Check that warm start object is valid.
Bonmin::TNLPSolver::UnsolvedError::~UnsolvedError
virtual ~UnsolvedError()
destructor.
Definition: BonTNLPSolver.hpp:79
Bonmin::TNLPSolver::illegalOption
@ illegalOption
Definition: BonTNLPSolver.hpp:36
IpTNLP.hpp