OS  2.10.2
OSBonminSolver.h
Go to the documentation of this file.
1 /* $Id: OSBonminSolver.h 5284 2017-12-08 13:52:50Z stefan $ */
15 #ifndef BONMINSOLVER_H
16 #define BONMINSOLVER_H
17 
18 #include "OSConfig.h"
19 #include "OSDefaultSolver.h"
20 #include "OSrLWriter.h"
21 #include "OSInstance.h"
22 #include "OSParameters.h"
23 #include "OSnLNode.h"
24 #include "OSiLReader.h"
25 #include "OSrLReader.h"
26 #include "OSoLReader.h"
27 #include "OSInstance.h"
28 #include "OSExpressionTree.h"
29 #include "OSnLNode.h"
30 #include "OSDataStructures.h"
31 #include "OSFileUtil.h"
32 #include "OSErrorClass.h"
33 
34 #include "OSResult.h"
35 #include "OSInstance.h"
36 #include "OSOption.h"
37 
38 #include <cstddef>
39 #include <cstdlib>
40 #include <cctype>
41 #include <cassert>
42 #include <stack>
43 #include <string>
44 #include <iostream>
45 #include <vector>
46 #include <map>
47 
48 #include "BonCbc.hpp"
49 #include "BonTMINLP.hpp"
50 #include "BonBonminSetup.hpp"
51 
52 // for Stefan
54 {
55 
56 
57 
58 public:
59 
61  BonminProblem(OSInstance *osinstance_ , OSOption *osoption_);
62 
64  virtual ~BonminProblem();
65 
67 
69 
71 
72 
82  virtual bool get_variables_types(Ipopt::Index n, VariableType* var_types);
83 
86 
93 
106  virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index&m, Ipopt::Index& nnz_jac_g,
107  Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style);
108 
109 
110 
112  //virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
113  // Index& nnz_h_lag, IndexStyleEnum& index_style);
114 
116  virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
118 
120  virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
121  bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
122  Ipopt::Index m, bool init_lambda,
123  Ipopt::Number* lambda);
124 
126  virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number& obj_value);
127 
129  virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number* grad_f);
130 
132  virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Index m, Ipopt::Number* g);
133 
138  virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
139  Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, Ipopt::Index *jCol,
140  Ipopt::Number* values);
141 
146  virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
147  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
148  bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow,
149  Ipopt::Index* jCol, Ipopt::Number* values);
150 
152 
153 
154  virtual bool get_scaling_parameters(Ipopt::Number& obj_scaling,
155  bool& use_x_scaling, Ipopt::Index n,
156  Ipopt::Number* x_scaling,
157  bool& use_g_scaling, Ipopt::Index m,
158  Ipopt::Number* g_scaling);
159 
162  virtual void finalize_solution(Bonmin::TMINLP::SolverReturn status_,
163  Ipopt::Index n, const Ipopt::Number* x, Ipopt::Number obj_value);
165 
166  virtual const SosInfo * sosConstraints() const
167  {
168  return NULL;
169  }
170  virtual const BranchingInfo* branchingInfo() const
171  {
172  return NULL;
173  }
174 
176  {
177  printSol_ = true;
178  }
179 
180 
181 
182 
183 
184 private:
185  bool printSol_;
186 
187 private:
199  // HS071_NLP();
200 
202 
203 
204 
205  std::string bonminErrorMsg;
206 
207 
208 };
209 
210 
226 {
227 public:
228 
229 
230 
232  BonminSolver();
233 
235  ~BonminSolver();
236 
237 
238 
240 
241  // this is a Bonmin BonCbc object;
243 
245 
246  //SmartPtr<IpoptApplication> app;
247 
248 
251  virtual void solve() throw (ErrorClass) ;
252 
257  virtual void buildSolverInstance() throw(ErrorClass);
258 
263  virtual void setSolverOptions() throw(ErrorClass);
264 
270  void dataEchoCheck();
271 
277 
283 
284 
285 
290  void writeResult();
291 
292 
293 private:
294  OSrLWriter *osrlwriter;
295 
296  Bonmin::BonminSetup bonminSetup;
297 
298  std::string bonminErrorMsg;
299 };
300 
301 
302 #endif /*BONMINSOLVER_H*/
Bonmin::Bab
OSConfig.h
OSExpressionTree.h
OSDataStructures.h
OSiLReader
Used to read an OSiL string.
Definition: OSiLReader.h:37
BonminProblem::osoption
OSOption * osoption
Definition: OSBonminSolver.h:68
BonminSolver::status
Bonmin::TMINLP::SolverReturn status
Definition: OSBonminSolver.h:244
OSErrorClass.h
BonminProblem::eval_f
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to return the objective value.
OSoLReader
Used to read an OSoL string.
Definition: OSoLReader.h:37
OSrLWriter.h
OSInstance
The in-memory representation of an OSiL instance..
Definition: OSInstance.h:2262
BonminProblem::get_bounds_info
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Bonmin specific methods for defining the nlp problem.
OSrLWriter
Take an OSResult object and write a string that validates against OSrL.
Definition: OSrLWriter.h:30
Bonmin
OSrLReader.h
BonminSolver::tminlp
Ipopt::SmartPtr< BonminProblem > tminlp
Definition: OSBonminSolver.h:239
BonminProblem::sosConstraints
virtual const SosInfo * sosConstraints() const
Definition: OSBonminSolver.h:166
Bonmin::TMINLP
OSResult.h
OSInstance.h
This file defines the OSInstance class along with its supporting classes.
Ipopt::Number
double Number
OSOption.h
BonminProblem
Definition: OSBonminSolver.h:53
BonminProblem::get_starting_point
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Method to return the starting point for the algorithm.
BonminProblem::get_constraints_linearity
virtual bool get_constraints_linearity(Ipopt::Index m, Ipopt::TNLP::LinearityType *const_types)
Pass the type of the constraints (LINEAR, NON_LINEAR) to the optimizer.
BonminSolver::~BonminSolver
~BonminSolver()
the IpoptSolver class destructor
BonminProblem::finalize_solution
virtual void finalize_solution(Bonmin::TMINLP::SolverReturn status_, Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number obj_value)
Method called by Ipopt at the end of optimization.
OSFileUtil.h
OSoLReader.h
OSiLReader.h
Ipopt::Index
int Index
BonminSolver::setSolverOptions
virtual void setSolverOptions()
The implementation of the virtual functions.
BonminProblem::eval_grad_f
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Method to return the gradient of the objective.
OSDefaultSolver.h
Ipopt::SmartPtr< BonminProblem >
BonminSolver::m_osolreader
OSoLReader * m_osolreader
m_osolreader is an OSoLReader object used to create an osoption from an osol string if needed
Definition: OSBonminSolver.h:282
BonminSolver::buildSolverInstance
virtual void buildSolverInstance()
buildSolverInstance is a virtual function – the actual solvers will implement their own buildSolver...
BonminProblem::eval_h
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the hessian of the lagrangian (if "values" is NULL) 2) The valu...
BonminProblem::BonminProblem
BonminProblem(OSInstance *osinstance_, OSOption *osoption_)
the BonminProblemclass constructor
BonminSolver::m_osilreader
OSiLReader * m_osilreader
m_osilreader is an OSiLReader object used to create an osinstance from an osil string if needed
Definition: OSBonminSolver.h:276
ErrorClass
used for throwing exceptions.
Definition: OSErrorClass.h:31
Bonmin::TMINLP::SolverReturn
SolverReturn
BonminProblem::~BonminProblem
virtual ~BonminProblem()
the BonminProblem class destructor
BonminSolver::writeResult
void writeResult()
use this to write the solution information to an OSResult object
BonminProblem::get_nlp_info
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, Ipopt::TNLP::IndexStyleEnum &index_style)
Method to pass the main dimensions of the problem to Ipopt.
BonminSolver::BonminSolver
BonminSolver()
the BonminSolver class constructor
BonminProblem::branchingInfo
virtual const BranchingInfo * branchingInfo() const
Definition: OSBonminSolver.h:170
BonBonminSetup.hpp
BonminSolver
The BonminSolver class solves problems using Ipopt.
Definition: OSBonminSolver.h:225
BonminProblem::status
Bonmin::TMINLP::SolverReturn status
Definition: OSBonminSolver.h:70
Ipopt::TNLP::LinearityType
LinearityType
BonminProblem::get_scaling_parameters
virtual bool get_scaling_parameters(Ipopt::Number &obj_scaling, bool &use_x_scaling, Ipopt::Index n, Ipopt::Number *x_scaling, bool &use_g_scaling, Ipopt::Index m, Ipopt::Number *g_scaling)
OSOption
The Option Class.
Definition: OSOption.h:3564
Bonmin::TMINLP::VariableType
VariableType
BonminProblem::osinstance
OSInstance * osinstance
Definition: OSBonminSolver.h:66
BonminProblem::printSolutionAtEndOfAlgorithm
void printSolutionAtEndOfAlgorithm()
Definition: OSBonminSolver.h:175
BonminProblem::eval_g
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Method to return the constraint residuals.
BonminProblem::get_variables_types
virtual bool get_variables_types(Ipopt::Index n, VariableType *var_types)
Pass the type of the variables (INTEGER, BINARY, CONTINUOUS) to the optimizer.
BonminSolver::solve
virtual void solve()
solve results in an instance being read into the Bonmin data structrues and optimized
Ipopt::TNLP::IndexStyleEnum
IndexStyleEnum
BonminProblem::get_variables_linearity
virtual bool get_variables_linearity(Ipopt::Index n, Ipopt::TNLP::LinearityType *var_types)
Pass info about linear and nonlinear variables.
BonminSolver::dataEchoCheck
void dataEchoCheck()
use this for debugging, print out the instance that the solver thinks it has and compare this with th...
BonCbc.hpp
BonTMINLP.hpp
DefaultSolver
The Default Solver Class.
Definition: OSDefaultSolver.h:35
OSParameters.h
BonminSolver::bb
Bonmin::Bab bb
Definition: OSBonminSolver.h:242
BonminProblem::eval_jac_g
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the jacobian (if "values" is NULL) 2) The values of the jacobia...
OSnLNode.h
This file defines the OSnLNode class along with its derived classes.