List of all members | Public Member Functions
casadi::BonminUserClass Class Reference

#include <bonmin_nlp.hpp>

Detailed Description

Definition at line 46 of file bonmin_nlp.hpp.

Inheritance diagram for casadi::BonminUserClass:
Inheritance graph
[legend]
Collaboration diagram for casadi::BonminUserClass:
Collaboration graph
[legend]

Public Member Functions

 BonminUserClass (const BonminInterface &bonminInterface, BonminMemory *mem)
 
 ~BonminUserClass () override
 
bool get_nlp_info (Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, TNLP::IndexStyleEnum &index_style) override
 
bool get_bounds_info (Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u) override
 
bool get_starting_point (Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda) override
 
bool eval_f (Index n, const Number *x, bool new_x, Number &obj_value) override
 
bool eval_grad_f (Index n, const Number *x, bool new_x, Number *grad_f) override
 
bool eval_g (Index n, const Number *x, bool new_x, Index m, Number *g) override
 
bool eval_jac_g (Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values) override
 
bool eval_h (Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values) override
 
void finalize_solution (TMINLP::SolverReturn status, Index n, const Number *x, Number obj_value) override
 
virtual Index get_number_of_nonlinear_variables ()
 
virtual bool get_list_of_nonlinear_variables (Index num_nonlin_vars, Index *pos_nonlin_vars)
 
virtual bool intermediate_callback (AlgorithmMode mode, Index iter, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
 
bool get_variables_types (Index n, VariableType *var_types) override
 
bool get_variables_linearity (Index n, Ipopt::TNLP::LinearityType *var_types) override
 
bool get_constraints_linearity (Index m, Ipopt::TNLP::LinearityType *const_types) override
 
const SosInfo * sosConstraints () const override
 
const BranchingInfo * branchingInfo () const override
 

Constructor & Destructor Documentation

◆ BonminUserClass()

casadi::BonminUserClass::BonminUserClass ( const BonminInterface bonminInterface,
BonminMemory mem 
)

Definition at line 32 of file bonmin_nlp.cpp.

33  : solver_(solver), mem_(mem) {
34  n_ = solver_.nx_;
35  m_ = solver_.ng_;
36  }
casadi_int ng_
Number of constraints.
Definition: nlpsol_impl.hpp:69
casadi_int nx_
Number of variables.
Definition: nlpsol_impl.hpp:66

References casadi::Nlpsol::ng_, and casadi::Nlpsol::nx_.

◆ ~BonminUserClass()

casadi::BonminUserClass::~BonminUserClass ( )
override

Definition at line 38 of file bonmin_nlp.cpp.

38  {
39  }

Member Function Documentation

◆ branchingInfo()

const BranchingInfo* casadi::BonminUserClass::branchingInfo ( ) const
inlineoverride

Definition at line 119 of file bonmin_nlp.hpp.

119 {return nullptr;}

◆ eval_f()

bool casadi::BonminUserClass::eval_f ( Index  n,
const Number *  x,
bool  new_x,
Number &  obj_value 
)
override

Method to return the objective value

Definition at line 71 of file bonmin_nlp.cpp.

71  {
72  mem_->arg[0] = x;
73  mem_->arg[1] = mem_->d_nlp.p;
74  mem_->res[0] = &obj_value;
75  try {
76  return solver_.calc_function(mem_, "nlp_f")==0;
77  } catch(KeyboardInterruptException& ex) {
78  casadi_warning("KeyboardInterruptException");
79  throw KeyboardInterruptException();
80  } catch (std::exception& ex) {
81  if (solver_.show_eval_warnings_) {
82  casadi_warning("BonminUserClass::nlp_f failed:" + std::string(ex.what()));
83  }
84  return false;
85  }
86  }
int calc_function(OracleMemory *m, const std::string &fcn, const double *const *arg=nullptr, int thread_id=0) const
bool show_eval_warnings_
Show evaluation warnings.
casadi_nlpsol_data< double > d_nlp
Definition: nlpsol_impl.hpp:42

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::NlpsolMemory::d_nlp, casadi_nlpsol_data< T1 >::p, casadi::OracleMemory::res, casadi::OracleFunction::show_eval_warnings_, and casadi::CasadiException::what().

◆ eval_g()

bool casadi::BonminUserClass::eval_g ( Index  n,
const Number *  x,
bool  new_x,
Index  m,
Number *  g 
)
override

Method to return the constraint residuals

Definition at line 108 of file bonmin_nlp.cpp.

108  {
109  mem_->arg[0] = x;
110  mem_->arg[1] = mem_->d_nlp.p;
111  mem_->res[0] = g;
112  try {
113  return solver_.calc_function(mem_, "nlp_g")==0;
114  } catch(KeyboardInterruptException& ex) {
115  casadi_warning("KeyboardInterruptException");
116  throw KeyboardInterruptException();
117  } catch (std::exception& ex) {
118  if (solver_.show_eval_warnings_) {
119  casadi_warning("BonminUserClass::eval_g failed:" + std::string(ex.what()));
120  }
121  return false;
122  }
123  }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::NlpsolMemory::d_nlp, casadi_nlpsol_data< T1 >::p, casadi::OracleMemory::res, casadi::OracleFunction::show_eval_warnings_, and casadi::CasadiException::what().

◆ eval_grad_f()

bool casadi::BonminUserClass::eval_grad_f ( Index  n,
const Number *  x,
bool  new_x,
Number *  grad_f 
)
override

Method to return the gradient of the objective

Definition at line 89 of file bonmin_nlp.cpp.

89  {
90  mem_->arg[0] = x;
91  mem_->arg[1] = mem_->d_nlp.p;
92  mem_->res[0] = nullptr;
93  mem_->res[1] = grad_f;
94  try {
95  return solver_.calc_function(mem_, "nlp_grad_f")==0;
96  } catch(KeyboardInterruptException& ex) {
97  casadi_warning("KeyboardInterruptException");
98  throw KeyboardInterruptException();
99  } catch (std::exception& ex) {
100  if (solver_.show_eval_warnings_) {
101  casadi_warning("BonminUserClass::eval_grad_f failed:" + std::string(ex.what()));
102  }
103  return false;
104  }
105  }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::NlpsolMemory::d_nlp, casadi_nlpsol_data< T1 >::p, casadi::OracleMemory::res, casadi::OracleFunction::show_eval_warnings_, and casadi::CasadiException::what().

◆ eval_h()

bool casadi::BonminUserClass::eval_h ( Index  n,
const Number *  x,
bool  new_x,
Number  obj_factor,
Index  m,
const Number *  lambda,
bool  new_lambda,
Index  nele_hess,
Index *  iRow,
Index *  jCol,
Number *  values 
)
override

Method to return: 1) The structure of the hessian of the Lagrangian (if "values" is NULL) 2) The values of the hessian of the Lagrangian (if "values" is not NULL)

Definition at line 165 of file bonmin_nlp.cpp.

168  {
169  if (values) {
170  // Evaluate numerically
171  mem_->arg[0] = x;
172  mem_->arg[1] = mem_->d_nlp.p;
173  mem_->arg[2] = &obj_factor;
174  mem_->arg[3] = lambda;
175  mem_->res[0] = values;
176  try {
177  return solver_.calc_function(mem_, "nlp_hess_l")==0;
178  } catch(KeyboardInterruptException& ex) {
179  casadi_warning("KeyboardInterruptException");
180  throw KeyboardInterruptException();
181  } catch (std::exception& ex) {
182  if (solver_.show_eval_warnings_) {
183  casadi_warning("BonminUserClass::eval_h failed:" + std::string(ex.what()));
184  }
185  return false;
186  }
187  } else {
188  // Get the sparsity pattern
189  casadi_int ncol = solver_.hesslag_sp_.size2();
190  const casadi_int* colind = solver_.hesslag_sp_.colind();
191  const casadi_int* row = solver_.hesslag_sp_.row();
192 
193  // Pass to BONMIN
194  for (casadi_int cc=0; cc<ncol; ++cc) {
195  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
196  *iRow++ = row[el];
197  *jCol++ = cc;
198  }
199  }
200  return true;
201  }
202  }
casadi_int size2() const
Get the number of columns.
Definition: sparsity.cpp:128
const casadi_int * row() const
Get a reference to row-vector,.
Definition: sparsity.cpp:164
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
Definition: sparsity.cpp:168

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::Sparsity::colind(), casadi::NlpsolMemory::d_nlp, casadi::BonminInterface::hesslag_sp_, casadi_nlpsol_data< T1 >::p, casadi::OracleMemory::res, casadi::Sparsity::row(), casadi::OracleFunction::show_eval_warnings_, casadi::Sparsity::size2(), and casadi::CasadiException::what().

◆ eval_jac_g()

bool casadi::BonminUserClass::eval_jac_g ( Index  n,
const Number *  x,
bool  new_x,
Index  m,
Index  nele_jac,
Index *  iRow,
Index *  jCol,
Number *  values 
)
override

Method to return: 1) The structure of the Jacobian (if "values" is NULL) 2) The values of the Jacobian (if "values" is not NULL)

Definition at line 126 of file bonmin_nlp.cpp.

128  {
129  if (values) {
130  // Evaluate numerically
131  mem_->arg[0] = x;
132  mem_->arg[1] = mem_->d_nlp.p;
133  mem_->res[0] = nullptr;
134  mem_->res[1] = values;
135  try {
136  return solver_.calc_function(mem_, "nlp_jac_g")==0;
137  } catch(KeyboardInterruptException& ex) {
138  casadi_warning("KeyboardInterruptException");
139  throw KeyboardInterruptException();
140  } catch (std::exception& ex) {
141  if (solver_.show_eval_warnings_) {
142  casadi_warning("BonminUserClass::eval_jac_g failed:" + std::string(ex.what()));
143  }
144  return false;
145  }
146  } else {
147  // Get the sparsity pattern
148  casadi_int ncol = solver_.jacg_sp_.size2();
149  const casadi_int* colind = solver_.jacg_sp_.colind();
150  const casadi_int* row = solver_.jacg_sp_.row();
151  if (nele_jac!=colind[ncol]) return false; // consistency check
152 
153  // Pass to BONMIN
154  for (casadi_int cc=0; cc<ncol; ++cc) {
155  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
156  *iRow++ = row[el];
157  *jCol++ = cc;
158  }
159  }
160  return true;
161  }
162  }

References casadi::OracleMemory::arg, casadi::OracleFunction::calc_function(), casadi::Sparsity::colind(), casadi::NlpsolMemory::d_nlp, casadi::BonminInterface::jacg_sp_, casadi_nlpsol_data< T1 >::p, casadi::OracleMemory::res, casadi::Sparsity::row(), casadi::OracleFunction::show_eval_warnings_, casadi::Sparsity::size2(), and casadi::CasadiException::what().

◆ finalize_solution()

void casadi::BonminUserClass::finalize_solution ( TMINLP::SolverReturn  status,
Index  n,
const Number *  x,
Number  obj_value 
)
override

This method is called when the algorithm is complete so the TNLP can store/write the solution

Definition at line 204 of file bonmin_nlp.cpp.

205  {
206  solver_.finalize_solution(mem_, status, x, obj_value);
207  }
void finalize_solution(BonminMemory *m, Bonmin::TMINLP::SolverReturn status, const double *x, double obj_value) const

References casadi::BonminInterface::finalize_solution().

◆ get_bounds_info()

bool casadi::BonminUserClass::get_bounds_info ( Index  n,
Number *  x_l,
Number *  x_u,
Index  m,
Number *  g_l,
Number *  g_u 
)
override

Method to return the bounds for my problem

Definition at line 53 of file bonmin_nlp.cpp.

54  {
55  casadi_assert_dev(n==solver_.nx_);
56  casadi_assert_dev(m==solver_.ng_);
57  return solver_.get_bounds_info(mem_, x_l, x_u, g_l, g_u);
58  }
bool get_bounds_info(BonminMemory *m, double *x_l, double *x_u, double *g_l, double *g_u) const

References casadi::BonminInterface::get_bounds_info(), casadi::Nlpsol::ng_, and casadi::Nlpsol::nx_.

◆ get_constraints_linearity()

bool casadi::BonminUserClass::get_constraints_linearity ( Index  m,
Ipopt::TNLP::LinearityType *  const_types 
)
override

Definition at line 261 of file bonmin_nlp.cpp.

261  {
262  casadi_assert_dev(m==solver_.nl_g_.size());
263  for (casadi_int i=0; i<m; ++i)
264  const_types[i] = solver_.nl_g_[i] ? Ipopt::TNLP::NON_LINEAR : Ipopt::TNLP::LINEAR;
265  return true;
266  }
std::vector< bool > nl_g_

References casadi::BonminInterface::nl_g_.

◆ get_list_of_nonlinear_variables()

bool casadi::BonminUserClass::get_list_of_nonlinear_variables ( Index  num_nonlin_vars,
Index *  pos_nonlin_vars 
)
virtual

Specify which variables that appear in the Hessian

Definition at line 237 of file bonmin_nlp.cpp.

238  {
239  return solver_.get_list_of_nonlinear_variables(num_nonlin_vars, pos_nonlin_vars);
240  }
bool get_list_of_nonlinear_variables(int num_nonlin_vars, int *pos_nonlin_vars) const

References casadi::BonminInterface::get_list_of_nonlinear_variables().

◆ get_nlp_info()

bool casadi::BonminUserClass::get_nlp_info ( Index &  n,
Index &  m,
Index &  nnz_jac_g,
Index &  nnz_h_lag,
TNLP::IndexStyleEnum &  index_style 
)
override

Method to return some info about the nlp

Definition at line 42 of file bonmin_nlp.cpp.

43  {
44  solver_.get_nlp_info(mem_, n, m, nnz_jac_g, nnz_h_lag);
45 
46  // use the C style indexing (0-based)
47  index_style = TNLP::C_STYLE;
48 
49  return true;
50  }
void get_nlp_info(BonminMemory *m, int &nx, int &ng, int &nnz_jac_g, int &nnz_h_lag) const

References casadi::BonminInterface::get_nlp_info().

◆ get_number_of_nonlinear_variables()

Index casadi::BonminUserClass::get_number_of_nonlinear_variables ( )
virtual

Specify the number of variables that appear in the Hessian

Definition at line 233 of file bonmin_nlp.cpp.

233  {
234  return solver_.get_number_of_nonlinear_variables();
235  }
int get_number_of_nonlinear_variables() const

References casadi::BonminInterface::get_number_of_nonlinear_variables().

◆ get_starting_point()

bool casadi::BonminUserClass::get_starting_point ( Index  n,
bool  init_x,
Number *  x,
bool  init_z,
Number *  z_L,
Number *  z_U,
Index  m,
bool  init_lambda,
Number *  lambda 
)
override

Method to return the starting point for the algorithm

Definition at line 61 of file bonmin_nlp.cpp.

64  {
65  casadi_assert_dev(n==solver_.nx_);
66  casadi_assert_dev(m==solver_.ng_);
67  return solver_.get_starting_point(mem_, init_x, x, init_z, z_L, z_U, init_lambda, lambda);
68  }
bool get_starting_point(BonminMemory *m, bool init_x, double *x, bool init_z, double *z_L, double *z_U, bool init_lambda, double *lambda) const

References casadi::BonminInterface::get_starting_point(), casadi::Nlpsol::ng_, and casadi::Nlpsol::nx_.

◆ get_variables_linearity()

bool casadi::BonminUserClass::get_variables_linearity ( Index  n,
Ipopt::TNLP::LinearityType *  var_types 
)
override

Definition at line 254 of file bonmin_nlp.cpp.

254  {
255  casadi_assert_dev(n==solver_.nl_ex_.size());
256  for (casadi_int i=0; i<n; ++i)
257  var_types[i] = solver_.nl_ex_[i] ? Ipopt::TNLP::NON_LINEAR : Ipopt::TNLP::LINEAR;
258  return true;
259  }
std::vector< bool > nl_ex_

References casadi::BonminInterface::nl_ex_.

◆ get_variables_types()

bool casadi::BonminUserClass::get_variables_types ( Index  n,
VariableType var_types 
)
override

Definition at line 242 of file bonmin_nlp.cpp.

242  {
243  if (solver_.discrete_.empty()) {
244  std::fill_n(var_types, n, CONTINUOUS);
245  } else {
246  if (solver_.discrete_.size()!=n) return false;
247  for (auto&& d : solver_.discrete_) {
248  *var_types++ = d ? INTEGER : CONTINUOUS;
249  }
250  }
251  return true;
252  }
std::vector< bool > discrete_
Options.

References casadi::CONTINUOUS, casadi::Nlpsol::discrete_, and casadi::INTEGER.

◆ intermediate_callback()

bool casadi::BonminUserClass::intermediate_callback ( AlgorithmMode  mode,
Index  iter,
Number  obj_value,
Number  inf_pr,
Number  inf_du,
Number  mu,
Number  d_norm,
Number  regularization_size,
Number  alpha_du,
Number  alpha_pr,
Index  ls_trials,
const IpoptData *  ip_data,
IpoptCalculatedQuantities *  ip_cq 
)
virtual

This method is called at every iteration

Code copied from TNLPAdapter::FinalizeSolution See also: http://list.coin-or.org/pipermail/ipopt/2010-July/002078.html

Definition at line 210 of file bonmin_nlp.cpp.

217  {
218 
219  // Only do the callback every few iterations
220  if (iter % solver_.callback_step_!=0) return true;
221 
224  // http://list.coin-or.org/pipermail/ipopt/2010-April/001965.html
225 
226  bool full_callback = false;
227 
228  return solver_.intermediate_callback(mem_, x_, z_L_, z_U_, g_, lambda_, obj_value, iter,
229  inf_pr, inf_du, mu, d_norm, regularization_size,
230  alpha_du, alpha_pr, ls_trials, full_callback);
231  }
bool intermediate_callback(BonminMemory *m, const double *x, const double *z_L, const double *z_U, const double *g, const double *lambda, double obj_value, int iter, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials, bool full_callback) const
casadi_int callback_step_
Execute the callback function only after this amount of iterations.
Definition: nlpsol_impl.hpp:78

References casadi::Nlpsol::callback_step_, and casadi::BonminInterface::intermediate_callback().

◆ sosConstraints()

const Bonmin::TMINLP::SosInfo * casadi::BonminUserClass::sosConstraints ( ) const
override

Definition at line 268 of file bonmin_nlp.cpp.

268  {
269  return &solver_.sosConstraints(mem_);
270  }
const Bonmin::TMINLP::SosInfo & sosConstraints(BonminMemory *m) const

References casadi::BonminInterface::sosConstraints().


The documentation for this class was generated from the following files: