26 #ifndef CASADI_SQPMETHOD_HPP
27 #define CASADI_SQPMETHOD_HPP
29 #include "casadi/core/nlpsol_impl.hpp"
30 #include <casadi/solvers/casadi_nlpsol_sqpmethod_export.h>
44 struct SqpmethodMemory :
public NlpsolMemory {
58 const char* return_status;
68 class Sqpmethod :
public Nlpsol {
70 explicit Sqpmethod(
const std::string& name,
const Function& nlp);
71 ~Sqpmethod()
override;
74 const char* plugin_name()
const override {
return "sqpmethod";}
77 std::string class_name()
const override {
return "Sqpmethod";}
80 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
81 return new Sqpmethod(name, nlp);
86 static const Options options_;
87 const Options& get_options()
const override {
return options_;}
91 Dict get_stats(
void* mem)
const override;
94 void init(
const Dict& opts)
override;
97 void* alloc_mem()
const override {
return new SqpmethodMemory();}
100 int init_mem(
void* mem)
const override;
103 void free_mem(
void* mem)
const override;
106 void set_work(
void* mem,
const double**& arg,
double**& res,
107 casadi_int*& iw,
double*& w)
const override;
110 int solve(
void* mem)
const override;
125 casadi_int block_size_ = 0;
128 casadi_int max_iter_, min_iter_;
131 casadi_int lbfgs_memory_;
134 double tol_pr_, tol_du_;
137 double min_step_size_;
143 double gamma_0_, gamma_max_, gamma_1_min_;
152 casadi_int max_iter_ls_;
153 casadi_int merit_memsize_;
157 bool print_header_, print_iteration_, print_status_;
166 ConvexifyData convexify_data_;
175 void codegen_body(CodeGenerator& g)
const override;
178 void codegen_declarations(CodeGenerator& g)
const override;
181 std::string codegen_mem_type()
const override {
return "struct casadi_sqpmethod_data"; }
184 const Function getConic()
const {
return qpsol_;}
187 void print_iteration()
const;
190 void print_iteration(casadi_int iter,
double obj,
double pr_inf,
double du_inf,
191 double dx_norm,
double rg, casadi_int ls_trials,
bool ls_success,
192 bool so_succes, std::string info)
const;
195 virtual int solve_QP(SqpmethodMemory* m,
const double* H,
const double* g,
196 const double* lbdz,
const double* ubdz,
198 double* x_opt,
double* dlam,
int mode)
const;
201 virtual int solve_ela_QP(SqpmethodMemory* m,
const double* H,
const double* g,
202 const double* lbdz,
const double* ubdz,
const double* A,
203 double* x_opt,
double* dlam)
const;
206 virtual int solve_elastic_mode(SqpmethodMemory* m, casadi_int* ela_it,
double gamma_1,
207 casadi_int ls_iter,
bool ls_success,
bool so_succes,
double pr_inf,
208 double du_inf,
double dx_norminf, std::string* info,
int mode)
const;
212 void codegen_qp_solve(CodeGenerator& cg,
const std::string& H,
const std::string& g,
213 const std::string& lbdz,
const std::string& ubdz,
214 const std::string& A,
const std::string& x_opt,
const std::string& dlam,
int mode)
const;
217 void codegen_qp_ela_solve(CodeGenerator& cg,
const std::string& H,
const std::string& g,
218 const std::string& lbdz,
const std::string& ubdz,
219 const std::string& A,
const std::string& x_opt,
const std::string& dlam)
const;
222 void codegen_solve_elastic_mode(CodeGenerator& cg,
int mode)
const;
225 void codegen_calc_gamma_1(CodeGenerator& cg)
const;
229 double calc_gamma_1(SqpmethodMemory* m)
const;
232 static const std::string meta_doc;
236 void serialize_body(SerializingStream &s)
const override;
239 static ProtoFunction* deserialize(DeserializingStream& s) {
return new Sqpmethod(s); }
243 explicit Sqpmethod(DeserializingStream& s);
246 void set_sqpmethod_prob();
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.