1 // NOLINT(legal/copyright)
2
3 // C-REPLACE "casadi_nlpsol_prob<T1>" "struct casadi_nlpsol_prob"
4
5 // SYMBOL "sqpmethod_prob"
6 template<typename T1>
7 struct casadi_sqpmethod_prob {
8 const casadi_nlpsol_prob<T1>* nlp;
9 // Sparsity patterns
10 const casadi_int *sp_h, *sp_a, *sp_hr;
11 casadi_int merit_memsize;
12 casadi_int max_iter_ls;
13 };
14 // C-REPLACE "casadi_sqpmethod_prob<T1>" "struct casadi_sqpmethod_prob"
15
16
17 // SYMBOL "sqpmethod_data"
18 template<typename T1>
19 struct casadi_sqpmethod_data {
20 // Problem structure
21 const casadi_sqpmethod_prob<T1>* prob;
22
23 T1* z_cand;
24 // Lagrange gradient in the next iterate
25 T1 *gLag, *gLag_old;
26 // Gradient of the objective
27 T1 *gf;
28 // Bounds of the QP
29 T1 *lbdz, *ubdz;
30 // QP solution
31 T1 *dx, *dlam;
32 // Hessian approximation
33 T1 *Bk;
34 // Jacobian
35 T1* Jk;
36 // merit_mem
37 T1* merit_mem;
38 };
39 // C-REPLACE "casadi_sqpmethod_data<T1>" "struct casadi_sqpmethod_data"
40
41
42 // SYMBOL "sqpmethod_work"
43 template<typename T1>
casadi_sqpmethod_work(const casadi_sqpmethod_prob<T1> * p,casadi_int * sz_iw,casadi_int * sz_w)44 void casadi_sqpmethod_work(const casadi_sqpmethod_prob<T1>* p,
45 casadi_int* sz_iw, casadi_int* sz_w) {
46 // Local variables
47 casadi_int nnz_h, nnz_a, nx, ng;
48 nnz_h = p->sp_h[2+p->sp_h[1]];
49 nnz_a = p->sp_a[2+p->sp_a[1]];
50 nx = p->nlp->nx;
51 ng = p->nlp->ng;
52
53 // Reset sz_w, sz_iw
54 *sz_w = *sz_iw = 0;
55 if (p->max_iter_ls>0) *sz_w += nx + ng; // z_cand
56 // Lagrange gradient in the next iterate
57 *sz_w += nx; // gLag
58 *sz_w += nx; // gLag_old
59 // Gradient of the objective
60 *sz_w += nx; // gf
61 // Bounds of the QP
62 *sz_w += nx + ng; // lbdz
63 *sz_w += nx + ng; // ubdz
64 // QP solution
65 *sz_w += nx; // dx
66 *sz_w += nx + ng; // dlam
67 // Hessian approximation
68 *sz_w += nnz_h; // Bk
69 // Jacobian
70 *sz_w += nnz_a; // Jk
71 // merit_mem
72 if (p->max_iter_ls>0) *sz_w += p->merit_memsize;
73 }
74
75 // SYMBOL "sqpmethod_init"
76 template<typename T1>
casadi_sqpmethod_init(casadi_sqpmethod_data<T1> * d,casadi_int ** iw,T1 ** w)77 void casadi_sqpmethod_init(casadi_sqpmethod_data<T1>* d, casadi_int** iw, T1** w) {
78 // Local variables
79 casadi_int nnz_h, nnz_a, nx, ng;
80 const casadi_sqpmethod_prob<T1>* p = d->prob;
81 // Get matrix number of nonzeros
82 nnz_h = p->sp_h[2+p->sp_h[1]];
83 nnz_a = p->sp_a[2+p->sp_a[1]];
84 nx = p->nlp->nx;
85 ng = p->nlp->ng;
86 if (p->max_iter_ls>0) {
87 d->z_cand = *w;
88 *w += nx + ng;
89 }
90 // Lagrange gradient in the next iterate
91 d->gLag = *w; *w += nx;
92 d->gLag_old = *w; *w += nx;
93 // Gradient of the objective
94 d->gf = *w; *w += nx;
95 // Bounds of the QP
96 d->lbdz = *w; *w += nx + ng;
97 d->ubdz = *w; *w += nx + ng;
98 // QP solution
99 d->dx = *w; *w += nx;
100 d->dlam = *w; *w += nx + ng;
101 // Hessian approximation
102 d->Bk = *w; *w += nnz_h;
103 // Jacobian
104 d->Jk = *w; *w += nnz_a;
105 // merit_mem
106 if (p->max_iter_ls>0) {
107 d->merit_mem = *w;
108 *w += p->merit_memsize;
109 }
110 }
111