26 #ifndef CASADI_SCPGEN_HPP
27 #define CASADI_SCPGEN_HPP
29 #include "casadi/core/nlpsol_impl.hpp"
30 #include <casadi/solvers/casadi_nlpsol_scpgen_export.h>
46 struct ScpgenMemory :
public NlpsolMemory {
48 double *dxk, *dlam, *gfk, *gL, *b_gn;
52 double *dx, *x0, *x, *lam, *dlam;
55 std::vector<VarMem> lifted_mem;
65 const char* iteration_note;
67 double *qpH, *qpA, *qpB, *qpL, *qpG, *qpH_times_du;
74 double t_eval_mat, t_eval_res, t_eval_vec, t_eval_exp, t_solve_qp, t_mainloop;
76 casadi_int iter_count;
87 class Scpgen :
public Nlpsol {
89 explicit Scpgen(
const std::string& name,
const Function& nlp);
93 const char* plugin_name()
const override {
return "scpgen";}
96 std::string class_name()
const override {
return "Scpgen";}
99 static Nlpsol* creator(
const std::string& name,
const Function& nlp) {
100 return new Scpgen(name, nlp);
105 static const Options options_;
106 const Options& get_options()
const override {
return options_;}
110 void init(
const Dict& opts)
override;
113 void* alloc_mem()
const override {
return new ScpgenMemory();}
116 int init_mem(
void* mem)
const override;
119 void free_mem(
void *mem)
const override {
delete static_cast<ScpgenMemory*
>(mem);}
122 Dict get_stats(
void* mem)
const override;
125 void set_work(
void* mem,
const double**& arg,
double**& res,
126 casadi_int*& iw,
double*& w)
const override;
129 int solve(
void* mem)
const override;
132 double primalInfeasibility(ScpgenMemory* m)
const;
135 double dualInfeasibility(ScpgenMemory* m)
const;
138 void printIteration(ScpgenMemory* m, std::ostream &stream)
const;
141 void printIteration(ScpgenMemory* m, std::ostream &stream, casadi_int iter,
double obj,
142 double pr_inf,
double du_inf,
143 double rg, casadi_int ls_trials,
bool ls_success)
const;
146 void eval_mat(ScpgenMemory* m)
const;
149 void eval_vec(ScpgenMemory* m)
const;
152 void eval_res(ScpgenMemory* m)
const;
155 void regularize(ScpgenMemory* m)
const;
158 void solve_qp(ScpgenMemory* m)
const;
161 void line_search(ScpgenMemory* m, casadi_int& ls_iter,
bool& ls_success)
const;
164 void eval_exp(ScpgenMemory* m)
const;
173 casadi_int max_iter_;
176 casadi_int lbfgs_memory_;
197 casadi_int max_iter_ls_;
198 casadi_int merit_memsize_;
206 const Function getConic()
const {
return qpsol_;}
215 double reg_threshold_;
228 casadi_int mat_jac_, mat_hes_;
232 casadi_int vec_gf_, vec_g_;
238 casadi_int res_x_, res_p_, res_g_lam_, res_p_lam_, res_p_d_;
239 casadi_int res_f_, res_gl_, res_g_;
242 casadi_int mod_x_, mod_p_, mod_g_lam_;
243 casadi_int mod_f_, mod_gl_, mod_g_;
244 casadi_int mod_du_, mod_dlam_g_;
248 MX v, v_def, v_lam, v_defL;
249 MX d, d_def, d_lam, d_defL;
252 casadi_int res_var, res_lam, res_d, res_lam_d;
253 casadi_int mod_var, mod_lam, mod_def, mod_defL;
254 casadi_int exp_def, exp_defL;
260 std::vector<std::string> name_x_;
263 std::vector<casadi_int> print_x_;
266 Sparsity spH_, spA_, spL_;
272 static const std::string meta_doc;
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.