bonmin_nlp.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_BONMIN_NLP_HPP
27 #define CASADI_BONMIN_NLP_HPP
28 
29 #include <BonTMINLP.hpp>
30 #include <IpIpoptCalculatedQuantities.hpp>
31 #include <IpIpoptData.hpp>
32 #include <CoinError.hpp>
33 #include <iostream>
34 
35 #include <casadi/interfaces/bonmin/casadi_nlpsol_bonmin_export.h>
36 
38 using namespace Ipopt;
39 using namespace Bonmin;
40 
41 namespace casadi {
42  // Forward declarations
43  class BonminInterface;
44  struct BonminMemory;
45 
46  class BonminUserClass : public TMINLP {
47 
48  public:
49  BonminUserClass(const BonminInterface& bonminInterface, BonminMemory* mem);
50  ~BonminUserClass() override;
51 
53  bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
54  Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style) override;
55 
57  bool get_bounds_info(Index n, Number* x_l, Number* x_u,
58  Index m, Number* g_l, Number* g_u) override;
59 
61  bool get_starting_point(Index n, bool init_x, Number* x,
62  bool init_z, Number* z_L, Number* z_U,
63  Index m, bool init_lambda,
64  Number* lambda) override;
65 
67  bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value) override;
68 
70  bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) override;
71 
73  bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) override;
74 
79  bool eval_jac_g(Index n, const Number* x, bool new_x,
80  Index m, Index nele_jac, Index* iRow, Index *jCol,
81  Number* values) override;
82 
87  bool eval_h(Index n, const Number* x, bool new_x,
88  Number obj_factor, Index m, const Number* lambda,
89  bool new_lambda, Index nele_hess, Index* iRow,
90  Index* jCol, Number* values) override;
91 
94  void finalize_solution(TMINLP::SolverReturn status,
95  Index n, const Number* x,
96  Number obj_value) override;
97 
99  virtual Index get_number_of_nonlinear_variables();
100 
102  virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, Index* pos_nonlin_vars);
103 
104 
106  virtual bool intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value,
107  Number inf_pr, Number inf_du,
108  Number mu, Number d_norm,
109  Number regularization_size,
110  Number alpha_du, Number alpha_pr,
111  Index ls_trials,
112  const IpoptData* ip_data,
113  IpoptCalculatedQuantities* ip_cq);
114 
115  bool get_variables_types(Index n, VariableType* var_types) override;
116  bool get_variables_linearity(Index n, Ipopt::TNLP::LinearityType* var_types) override;
117  bool get_constraints_linearity(Index m, Ipopt::TNLP::LinearityType* const_types) override;
118  const SosInfo * sosConstraints() const override;
119  const BranchingInfo* branchingInfo() const override {return nullptr;}
120 
121  private:
122  BonminUserClass(const BonminUserClass&);
123  BonminUserClass& operator=(const BonminUserClass&);
124  const BonminInterface& solver_;
125  BonminMemory* mem_;
126 
127  double * x_;
128  double * z_L_;
129  double * z_U_;
130  double * g_;
131  double * lambda_;
132  int n_;
133  int m_;
134  double obj_value_;
135  };
136 
137 } // namespace casadi
139 
140 #endif //BONMIN_NLP
The casadi namespace.