26 #ifndef CASADI_IPOPT_INTERFACE_HPP
27 #define CASADI_IPOPT_INTERFACE_HPP
29 #include <casadi/interfaces/ipopt/casadi_nlpsol_ipopt_export.h>
30 #include "casadi/core/nlpsol_impl.hpp"
31 #include "casadi/core/timing.hpp"
64 struct IpoptMemory :
public NlpsolMemory {
78 double *gk, *grad_fk, *jac_gk, *hess_lk, *grad_lk;
81 std::vector<double> inf_pr, inf_du, mu, d_norm, regularization_size,
82 obj, alpha_pr, alpha_du;
83 std::vector<int> ls_trials;
84 const char* return_status;
88 std::map<std::string, std::vector<std::string> > var_string_md;
89 std::map<std::string, std::vector<int> > var_integer_md;
90 std::map<std::string, std::vector<double> > var_numeric_md;
91 std::map<std::string, std::vector<std::string> > con_string_md;
92 std::map<std::string, std::vector<int> > con_integer_md;
93 std::map<std::string, std::vector<double> > con_numeric_md;
107 class IpoptInterface :
public Nlpsol {
108 friend class IpoptUserClass;
111 Sparsity hesslag_sp_;
113 explicit IpoptInterface(
const std::string& name,
const Function& nlp);
114 ~IpoptInterface()
override;
117 const char* plugin_name()
const override {
return "ipopt";}
120 std::string class_name()
const override {
return "IpoptInterface";}
123 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
124 return new IpoptInterface(name, nlp);
129 static const Options options_;
130 const Options& get_options()
const override {
return options_;}
134 void init(
const Dict& opts)
override;
137 void* alloc_mem()
const override {
return new IpoptMemory();}
140 int init_mem(
void* mem)
const override;
143 void free_mem(
void *mem)
const override {
delete static_cast<IpoptMemory*
>(mem);}
146 Dict get_stats(
void* mem)
const override;
149 void set_work(
void* mem,
const double**& arg,
double**& res,
150 casadi_int*& iw,
double*& w)
const override;
153 int solve(
void* mem)
const override;
162 void finalize_solution(IpoptMemory* m,
const double* x,
const double* z_L,
const double* z_U,
163 const double* g,
const double* lambda,
double obj_value,
164 int iter_count)
const;
165 bool get_bounds_info(IpoptMemory* m,
double* x_l,
double* x_u,
166 double* g_l,
double* g_u)
const;
167 bool get_starting_point(IpoptMemory* m,
bool init_x,
double* x,
168 bool init_z,
double* z_L,
double* z_U,
169 bool init_lambda,
double* lambda)
const;
170 void get_nlp_info(IpoptMemory* m,
int& nx,
int& ng,
171 int& nnz_jac_g,
int& nnz_h_lag)
const;
172 int get_number_of_nonlinear_variables()
const;
173 bool get_list_of_nonlinear_variables(
int num_nonlin_vars,
int* pos_nonlin_vars)
const;
174 bool intermediate_callback(IpoptMemory* m,
const double* x,
const double* z_L,
175 const double* z_U,
const double* g,
176 const double* lambda,
double obj_value,
int iter,
177 double inf_pr,
double inf_du,
double mu,
double d_norm,
178 double regularization_size,
double alpha_du,
double alpha_pr,
179 int ls_trials,
bool full_callback)
const;
180 bool get_var_con_metadata(std::map<std::string, std::vector<std::string> >& var_string_md,
181 std::map<std::string, std::vector<int> >& var_integer_md,
182 std::map<std::string, std::vector<double> >& var_numeric_md,
183 std::map<std::string, std::vector<std::string> >& con_string_md,
184 std::map<std::string, std::vector<int> >& con_integer_md,
185 std::map<std::string, std::vector<double> >& con_numeric_md)
const;
188 static const std::string meta_doc;
191 bool pass_nonlinear_variables_;
192 std::vector<bool> nl_ex_;
193 Dict var_string_md_, var_integer_md_, var_numeric_md_,
194 con_string_md_, con_integer_md_, con_numeric_md_;
196 bool clip_inactive_lam_;
197 std::string inactive_lam_strategy_;
198 double inactive_lam_value_;
201 ConvexifyData convexify_data_;
206 void set_ipopt_prob(CodeGenerator& g)
const;
209 void codegen_body(CodeGenerator& g)
const override;
212 void codegen_declarations(CodeGenerator& g)
const override;
215 void codegen_init_mem(CodeGenerator& g)
const override;
218 void codegen_free_mem(CodeGenerator& g)
const override;
221 std::string codegen_mem_type()
const override {
return "struct casadi_ipopt_data"; }
224 void serialize_body(SerializingStream &s)
const override;
227 static ProtoFunction* deserialize(DeserializingStream& s) {
return new IpoptInterface(s); }
231 explicit IpoptInterface(DeserializingStream& s);
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.