26 #ifndef CASADI_IPOPT_NLP_HPP
27 #define CASADI_IPOPT_NLP_HPP
30 #include <IpIpoptCalculatedQuantities.hpp>
31 #include <IpIpoptData.hpp>
33 #ifdef WITH_IPOPT_CALLBACK
34 #define private public
35 #include <IpIpoptData.hpp>
36 #include <IpOrigIpoptNLP.hpp>
37 #include <IpTNLPAdapter.hpp>
38 #include <IpDenseVector.hpp>
39 #include <IpExpansionMatrix.hpp>
41 #define private private
46 #include <casadi/interfaces/ipopt/casadi_nlpsol_ipopt_export.h>
49 using namespace Ipopt;
55 class IpoptUserClass :
public TNLP {
56 #ifdef WITH_IPOPT_CALLBACK
57 friend class TNLPAdapter;
61 IpoptUserClass(
const IpoptInterface& solver, IpoptMemory* mem);
62 ~IpoptUserClass()
override;
65 bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
66 Index& nnz_h_lag, IndexStyleEnum& index_style)
override;
69 bool get_bounds_info(Index n, Number* x_l, Number* x_u,
70 Index m, Number* g_l, Number* g_u)
override;
73 bool get_starting_point(Index n,
bool init_x, Number* x,
74 bool init_z, Number* z_L, Number* z_U,
75 Index m,
bool init_lambda,
76 Number* lambda)
override;
79 bool eval_f(Index n,
const Number* x,
bool new_x, Number& obj_value)
override;
82 bool eval_grad_f(Index n,
const Number* x,
bool new_x, Number* grad_f)
override;
85 bool eval_g(Index n,
const Number* x,
bool new_x, Index m, Number* g)
override;
91 bool eval_jac_g(Index n,
const Number* x,
bool new_x,
92 Index m, Index nele_jac, Index* iRow, Index *jCol,
93 Number* values)
override;
99 bool eval_h(Index n,
const Number* x,
bool new_x,
100 Number obj_factor, Index m,
const Number* lambda,
101 bool new_lambda, Index nele_hess, Index* iRow,
102 Index* jCol, Number* values)
override;
106 void finalize_solution(SolverReturn status,
107 Index n,
const Number* x,
const Number* z_L,
const Number* z_U,
108 Index m,
const Number* g,
const Number* lambda,
110 const IpoptData* ip_data,
111 IpoptCalculatedQuantities* ip_cq)
override;
114 Index get_number_of_nonlinear_variables()
override;
117 bool get_list_of_nonlinear_variables(Index num_nonlin_vars, Index* pos_nonlin_vars)
override;
121 bool intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value,
122 Number inf_pr, Number inf_du,
123 Number mu, Number d_norm,
124 Number regularization_size,
125 Number alpha_du, Number alpha_pr,
127 const IpoptData* ip_data,
128 IpoptCalculatedQuantities* ip_cq)
override;
131 bool get_var_con_metadata(Index n, StringMetaDataMapType& var_string_md,
132 IntegerMetaDataMapType& var_integer_md,
133 NumericMetaDataMapType& var_numeric_md,
134 Index m, StringMetaDataMapType& con_string_md,
135 IntegerMetaDataMapType& con_integer_md,
136 NumericMetaDataMapType& con_numeric_md)
override;
139 void finalize_metadata(Index n,
const StringMetaDataMapType& var_string_md,
140 const IntegerMetaDataMapType& var_integer_md,
141 const NumericMetaDataMapType& var_numeric_md,
142 Index m,
const StringMetaDataMapType& con_string_md,
143 const IntegerMetaDataMapType& con_integer_md,
144 const NumericMetaDataMapType& con_numeric_md)
override;
147 IpoptUserClass(
const IpoptUserClass&);
148 IpoptUserClass& operator=(
const IpoptUserClass&);
149 const IpoptInterface& solver_;