alpaqa matlab
Nonconvex constrained optimization
Loading...
Searching...
No Matches
ocp-vars.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <concepts>
6#include <numeric>
7
8namespace alpaqa {
9
10template <class V, class Conf>
12 std::convertible_to<V, rvec<Conf>> || std::convertible_to<V, crvec<Conf>>;
13
14template <Config Conf, VectorRefLike<Conf> V>
15constexpr auto const_or_mut_rvec(V &&v) {
16 if constexpr (Eigen::internal::is_lvalue<std::remove_reference_t<V>>::value)
17 return rvec<Conf>{v};
18 else
19 return crvec<Conf>{v};
20}
21
22template <Config Conf>
25
27 /// nx, nu, nh, nc
28 const std::array<index_t, 4> &sizes,
29 /// nx, nh, nc
30 const std::array<index_t, 3> &sizes_N,
31 /// Horizon length
32 length_t N)
33 : N{N} {
34 std::partial_sum(sizes.begin(), sizes.end(), indices.begin());
35 std::partial_sum(sizes_N.begin(), sizes_N.end(), indices_N.begin());
36 }
39 {prob.get_nx(), prob.get_nu(), prob.get_nh(), prob.get_nc()},
40 {prob.get_nx(), prob.get_nh_N(), prob.get_nc_N()},
41 prob.get_N(),
42 } {}
43
44 enum Indices {
45 i_u = 0,
46 i_h = 1,
47 i_c = 2,
48 i_h_N = 0,
49 i_c_N = 1,
50 };
52 std::array<index_t, 4> indices;
53 std::array<index_t, 3> indices_N;
54 length_t size(size_t i) const { return indices[i + 1] - indices[i]; }
55 length_t size_N(size_t i) const { return indices_N[i + 1] - indices_N[i]; }
56 length_t nx() const { return indices[0]; }
57 length_t nu() const { return size(i_u); }
58 length_t nxu() const { return nx() + nu(); }
59 length_t nh() const { return size(i_h); }
60 length_t nc() const { return size(i_c); }
61 length_t nx_N() const { return indices_N[0]; }
62 length_t nh_N() const { return size_N(i_h_N); }
63 length_t nc_N() const { return size_N(i_c_N); }
64
65 vec create() const { return vec(N * indices.back() + indices_N.back()); }
66 auto xk(VectorRefLike<config_t> auto &&v, index_t t) const {
67 return const_or_mut_rvec<config_t>(v.segment(t * indices.back(), nx()));
68 }
69 auto x(crvec v) const {
70 return [v, this](index_t t) { return xk(v, t); };
71 }
72 auto xuk(VectorRefLike<config_t> auto &&v, index_t t) const {
74 v.segment(t * indices.back(), nxu()));
75 }
76 auto uk(VectorRefLike<config_t> auto &&v, index_t t) const {
77 assert(t < N);
79 v.segment(t * indices.back() + indices[0], nu()));
80 }
81 auto u(crvec v) const {
82 return [v, this](index_t t) { return uk(v, t); };
83 }
84 auto hk(VectorRefLike<config_t> auto &&v, index_t t) const {
85 return const_or_mut_rvec<config_t>(v.segment(
86 t * indices.back() + (t < N ? indices[i_h] : indices_N[i_h_N]),
87 (t < N ? nh() : nh_N())));
88 }
89 auto ck(VectorRefLike<config_t> auto &&v, index_t t) const {
90 return v.segment(t * indices.back() +
91 (t < N ? indices[i_c] : indices_N[i_c_N]),
92 (t < N ? nc() : nc_N()));
93 }
94
95 vec create_qr() const { return vec(N * nxu() + nx()); }
96 auto qk(VectorRefLike<config_t> auto &&v, index_t t) const {
97 assert(t <= N);
98 return const_or_mut_rvec<config_t>(v.segment(t * nxu(), nx()));
99 }
100 auto q(crvec v) const {
101 return [v, this](index_t t) { return qk(v, t); };
102 }
103 auto qN_mut(vec &v) const {
104 return [&v, this]() { return qk(v, N); };
105 }
106 auto rk(VectorRefLike<config_t> auto &&v, index_t t) const {
107 assert(t < N);
108 return const_or_mut_rvec<config_t>(v.segment(t * nxu() + nx(), nu()));
109 }
110 auto r(crvec v) const {
111 return [v, this](index_t t) { return rk(v, t); };
112 }
113 auto qrk(VectorRefLike<config_t> auto &&v, index_t t) const {
114 assert(t < N);
115 return const_or_mut_rvec<config_t>(v.segment(t * nxu(), nxu()));
116 }
117 auto qr(crvec v) const {
118 return [v, this](index_t t) { return qrk(v, t); };
119 }
120 auto qr_mut(vec &v) const {
121 return [&v, this](index_t t) { return qrk(v, t); };
122 }
123
124 mat create_AB() const { return mat(nx(), nxu() * N); }
125 rmat ABk(rmat AB, index_t t) const {
126 return AB.middleCols(t * nxu(), nxu());
127 }
128 auto ABk(mat &AB, index_t t) const {
129 return AB.middleCols(t * nxu(), nxu());
130 }
131 crmat ABk(crmat AB, index_t t) const {
132 return AB.middleCols(t * nxu(), nxu());
133 }
134 auto AB(crmat AB) const {
135 return [AB, this](index_t t) { return ABk(AB, t); };
136 }
137 rmat Ak(rmat AB, index_t t) const { return AB.middleCols(t * nxu(), nx()); }
138 crmat Ak(crmat AB, index_t t) const {
139 return AB.middleCols(t * nxu(), nx());
140 }
141 auto Ak(mat &AB, index_t t) const { return AB.middleCols(t * nxu(), nx()); }
142 auto A(crmat AB) const {
143 return [AB, this](index_t t) { return Ak(AB, t); };
144 }
145 rmat Bk(rmat AB, index_t t) const {
146 return AB.middleCols(t * nxu() + nx(), nu());
147 }
148 crmat Bk(crmat AB, index_t t) const {
149 return AB.middleCols(t * nxu() + nx(), nu());
150 }
151 auto Bk(mat &AB, index_t t) const {
152 return AB.middleCols(t * nxu() + nx(), nu());
153 }
154 auto B(crmat AB) const {
155 return [AB, this](index_t t) { return Bk(AB, t); };
156 }
157};
158
159template <Config Conf>
167 mutable vec work_x{vars.nc() > 0 || vars.nc_N() ? vars.nx() : 0};
168 mutable vec work_λ{vars.nx()};
169 mutable vec work_c{std::max(vars.nc(), vars.nc_N())};
170 mutable vec work_R{problem->get_R_work_size()};
171 mutable vec work_S{problem->get_S_work_size()};
172
173 OCPEvaluator(const Problem &problem) : problem{&problem}, vars{problem} {}
174
175 length_t N() const { return vars.N; }
176
177 /// @pre x0 and u initialized
178 /// @post x, h and c updated
179 /// @return @f$ V(u) =
180 /// \sum_{k=0}^{N-1} \ell(h_k(x_k, u_k)) + V_f(h_N(x_N)) @f$
181 real_t forward(rvec storage, const Box &D, const Box &D_N, crvec μ,
182 crvec y) const {
183 real_t V = 0;
184 auto N = this->N();
185 auto nc = vars.nc();
186 auto nc_N = vars.nc_N();
187 for (index_t t = 0; t < N; ++t) {
188 auto xk = vars.xk(storage, t);
189 auto uk = vars.uk(storage, t);
190 auto ck = vars.ck(storage, t);
191 if (vars.nh() > 0) {
192 auto hk = vars.hk(storage, t);
193 problem->eval_h(t, xk, uk, hk);
194 V += problem->eval_l(t, hk);
195 } else {
196 auto xuk = vars.xuk(storage, t);
197 V += problem->eval_l(t, xuk);
198 }
199 if (nc > 0) {
200 problem->eval_constr(t, xk, ck);
201 auto yk = y.segment(t * nc, nc);
202 auto μk = μ.segment(t * nc, nc);
203 auto ζ = ck + μk.asDiagonal().inverse() * yk;
204 V += real_t(0.5) * dist_squared(ζ, D, μk);
205 }
206 problem->eval_f(t, xk, uk, vars.xk(storage, t + 1));
207 }
208 auto xN = vars.xk(storage, N);
209 auto cN = vars.ck(storage, N);
210 if (vars.nh_N() > 0) {
211 auto hN = vars.hk(storage, N);
212 problem->eval_h_N(xN, hN);
213 V += problem->eval_l_N(hN);
214 } else {
215 V += problem->eval_l_N(xN);
216 }
217 if (nc_N > 0) {
218 problem->eval_constr_N(xN, cN);
219 auto yN = y.segment(N * nc, nc_N);
220 auto μN = μ.segment(N * nc, nc_N);
221 auto ζ = cN + μN.asDiagonal().inverse() * yN;
222 V += real_t(0.5) * dist_squared(ζ, D_N, μN);
223 }
224 return V;
225 }
226
227 /// @pre x0 and u initialized
228 /// @post x updated
229 void forward_simulate(rvec storage) const {
230 for (index_t t = 0; t < N(); ++t) {
231 auto xk = vars.xk(storage, t);
232 auto uk = vars.uk(storage, t);
233 auto ck = vars.ck(storage, t);
234 if (vars.nh() > 0) {
235 auto hk = vars.hk(storage, t);
236 problem->eval_h(t, xk, uk, hk);
237 }
238 if (vars.nc() > 0)
239 problem->eval_constr(t, xk, ck);
240 problem->eval_f(t, xk, uk, vars.xk(storage, t + 1));
241 }
242 auto xN = vars.xk(storage, N());
243 auto cN = vars.ck(storage, N());
244 if (vars.nh_N() > 0) {
245 auto hN = vars.hk(storage, N());
246 problem->eval_h_N(xN, hN);
247 }
248 if (vars.nc_N() > 0)
249 problem->eval_constr_N(xN, cN);
250 }
251
252 /// @pre x0 and u initialized
253 void forward_simulate(crvec u, rvec x) const {
254 assert(u.size() == vars.N * vars.nu());
255 assert(x.size() == vars.nx());
256 for (index_t t = 0; t < N(); ++t) {
257 auto uk = u.segment(t * vars.nu(), vars.nu());
258 problem->eval_f(t, x, uk, x);
259 }
260 }
261
262 /// @pre x, u, h and c initialized (i.e. forward was called)
263 void backward(rvec storage, rvec g, const auto &qr, const auto &q_N,
264 const Box &D, const Box &D_N, crvec μ, crvec y) const {
265 auto N = this->N();
266 auto nc = vars.nc();
267 auto nc_N = vars.nc_N();
268 auto nu = vars.nu();
269 auto nx = vars.nx();
270 auto &w = work_x;
271 auto &v = work_c;
272 auto &λ = work_λ;
273 assert((nc <= 0 && nc_N <= 0) || w.size() == nx);
274 assert((nc <= 0 && nc_N <= 0) || v.size() == std::max(nc, nc_N));
275 auto qN = q_N();
276 auto xN = vars.xk(storage, N);
277 auto hN = vars.hk(storage, N);
278 auto vN = v.topRows(nc_N);
279 auto vk = v.topRows(nc);
280 // λ ← ∇h(x)·∇l(h)
281 problem->eval_q_N(xN, hN, λ);
282 // λ ← ∇h(x)·∇l(h) + ∇c(x)·μ·(c(x) + μ⁻¹y - Π(c(x) + μ⁻¹y; D))
283 if (nc_N > 0) {
284 auto cN = vars.ck(storage, N);
285 auto yN = y.segment(N * nc, nc_N);
286 auto μN = μ.segment(N * nc, nc_N);
287 auto ζ = cN + μN.asDiagonal().inverse() * yN;
288 vN = μN.asDiagonal() * projecting_difference(ζ, D_N);
289 problem->eval_grad_constr_prod_N(xN, vN, w);
290 λ += w;
291 }
292 qN = λ;
293 for (index_t t = N; t-- > 0;) {
294 auto gt = g.segment(t * nu, nu);
295 auto hk = vars.hk(storage, t);
296 auto xuk = vars.xuk(storage, t);
297 auto xk = vars.xk(storage, t);
298 auto uk = vars.uk(storage, t);
299 auto &&qrk = qr(t);
300 auto &&qk = qrk.topRows(nx);
301 auto &&rk = qrk.bottomRows(nu);
302 // /q\ ← /Aᵀ\ λ
303 // \r/ \Bᵀ/ λ
304 problem->eval_grad_f_prod(t, xk, uk, λ, qrk);
305 // λ ← Aᵀλ, ∇ψ ← Bᵀλ
306 λ = qk;
307 gt = rk;
308 // /q\ ← ∇h(x,u)·∇l(h)
309 // \r/
310 problem->eval_qr(t, xuk, hk, qrk);
311 // q ← ∇h(x)·∇l(h) + ∇c(x)·μ·(c(x) + μ⁻¹y - Π(c(x) + μ⁻¹y; D))
312 if (nc > 0) {
313 auto ck = vars.ck(storage, t);
314 auto yk = y.segment(t * nc, nc);
315 auto μk = μ.segment(t * nc, nc);
316 auto ζ = ck + μk.asDiagonal().inverse() * yk;
317 vk = μk.asDiagonal() * projecting_difference(ζ, D);
318 problem->eval_grad_constr_prod(t, xk, vk, w);
319 qk += w;
320 }
321 // λ ← q + Aᵀλ, ∇ψ ← r + Bᵀλ
322 λ += qk;
323 gt += rk;
324 }
325 }
326
327 void Qk(crvec storage, crvec y, crvec μ, const Box &D, const Box &D_N,
328 index_t k, rmat out) const {
329 auto N = this->N();
330 auto nc = vars.nc();
331 auto nc_N = vars.nc_N();
332 auto work_cN = work_c.topRows(nc_N);
333 auto work_ck = work_c.topRows(nc);
334 check_finiteness(out.reshaped(), "Qk input");
335 auto hk = vars.hk(storage, k);
336 auto xuk = vars.xuk(storage, k);
337 auto xk = vars.xk(storage, k);
338 if (k < N)
339 problem->eval_add_Q(k, xuk, hk, out);
340 else
341 problem->eval_add_Q_N(xk, hk, out);
342 if (nc > 0 || nc_N > 0) {
343 auto ck = vars.ck(storage, k);
344 auto yk = y.segment(k * nc, k < N ? nc : nc_N);
345 auto μk = μ.segment(k * nc, k < N ? nc : nc_N);
346 auto ζ = ck + μk.asDiagonal().inverse() * yk;
347 if (k < N) {
348 for (index_t i = 0; i < nc; ++i)
349 work_ck(i) = μk(i) * (ζ(i) < D.lowerbound(i) ||
350 ζ(i) > D.upperbound(i));
351 problem->eval_add_gn_hess_constr(k, xk, work_ck, out);
352 } else {
353 for (index_t i = 0; i < nc_N; ++i)
354 work_cN(i) = μk(i) * (ζ(i) < D_N.lowerbound(i) ||
355 ζ(i) > D_N.upperbound(i));
356 problem->eval_add_gn_hess_constr_N(xk, work_cN, out);
357 }
358 }
359 check_finiteness(out.reshaped(), "Qk output");
360 }
361 auto Q(crvec storage, crvec y, crvec μ, const Box &D,
362 const Box &D_N) const {
363 return [=, this, &D, &D_N](index_t k) {
364 return [=, this, &D, &D_N](rmat out) {
365 return Qk(storage, y, μ, D, D_N, k, out);
366 };
367 };
368 }
369
370 /// @post initialize work_R
371 void Rk(crvec storage, index_t k, crindexvec mask, rmat out) {
372 check_finiteness(out.reshaped(), "Rk input");
373 auto hk = vars.hk(storage, k);
374 auto xuk = vars.xuk(storage, k);
375 problem->eval_add_R_masked(k, xuk, hk, mask, out, work_R);
376 check_finiteness(out.reshaped(), "Rk output");
377 }
378 auto R(crvec storage) {
379 return [=, this](index_t k) {
380 return [=, this](crindexvec mask, rmat out) {
381 return Rk(storage, k, mask, out);
382 };
383 };
384 }
385
386 /// @post initialize work_S
387 void Sk(crvec storage, index_t k, crindexvec mask, rmat out) {
388 check_finiteness(out.reshaped(), "Sk input");
389 auto hk = vars.hk(storage, k);
390 auto xuk = vars.xuk(storage, k);
391 problem->eval_add_S_masked(k, xuk, hk, mask, out, work_S);
392 check_finiteness(out.reshaped(), "Sk output");
393 }
394 auto S(crvec storage) {
395 return [=, this](index_t k) {
396 return [=, this](crindexvec mask, rmat out) {
397 return Sk(storage, k, mask, out);
398 };
399 };
400 }
401
402 /// @pre initialized work_R
403 void Rk_prod(crvec storage, index_t k, crindexvec mask_J, crindexvec mask_K,
404 crvec v, rvec out) const {
405
406 check_finiteness(v(mask_K), "Rk_prod input v");
407 check_finiteness(out.reshaped(), "Rk_prod input");
408 auto hk = vars.hk(storage, k);
409 auto xuk = vars.xuk(storage, k);
410 problem->eval_add_R_prod_masked(k, xuk, hk, mask_J, mask_K, v, out,
411 work_R);
412 check_finiteness(out.reshaped(), "Rk_prod output");
413 }
414 auto R_prod(crvec storage) const {
415 return [=, this](index_t k) {
416 return [=, this](crindexvec mask_J, crindexvec mask_K, crvec v,
417 rvec out) {
418 return Rk_prod(storage, k, mask_J, mask_K, v, out);
419 };
420 };
421 }
422
423 /// @pre initialized work_S
424 void Sk_prod(crvec storage, index_t k, crindexvec mask_K, crvec v,
425 rvec out) const {
426 check_finiteness(v(mask_K), "Sk_prod input v");
427 check_finiteness(out.reshaped(), "Sk_prod input");
428 auto hk = vars.hk(storage, k);
429 auto xuk = vars.xuk(storage, k);
430 problem->eval_add_S_prod_masked(k, xuk, hk, mask_K, v, out, work_S);
431 check_finiteness(out.reshaped(), "Sk_prod output");
432 }
433 auto S_prod(crvec storage) const {
434 return [=, this](index_t k) {
435 return [=, this](crindexvec mask_K, crvec v, rvec out) {
436 return Sk_prod(storage, k, mask_K, v, out);
437 };
438 };
439 }
440};
441
442namespace detail {
443
444template <Config Conf>
446 rvec<Conf> storage) {
447 for (index_t<Conf> t = 0; t < dim.N; ++t)
448 dim.uk(storage, t) = u.segment(t * dim.nu(), dim.nu());
449}
450template <Config Conf>
452 crvec<Conf> u, rvec<Conf> storage) {
453 for (index_t<Conf> t = 0; t < dim.N; ++t) {
454 dim.xk(storage, t) = x.segment(t * dim.nx(), dim.nx());
455 dim.uk(storage, t) = u.segment(t * dim.nu(), dim.nu());
456 }
457 dim.xk(storage, dim.N) = x.segment(dim.N * dim.nx(), dim.nx());
458}
459template <Config Conf>
461 rvec<Conf> u) {
462 for (index_t<Conf> t = 0; t < dim.N; ++t)
463 u.segment(t * dim.nu(), dim.nu()) = dim.uk(storage, t);
464}
465template <Config Conf>
467 rvec<Conf> x) {
468 for (index_t<Conf> t = 0; t < dim.N + 1; ++t)
469 x.segment(t * dim.nx(), dim.nx()) =
470 storage.segment(t * (dim.nx() + dim.nu()), dim.nx());
471}
472
473template <Config Conf>
475 crvec<Conf> xu) {
476 OCPVariables<Conf> dim{problem};
477 vec<Conf> u(dim.N * dim.nu());
478 assign_extract_u(dim, xu, u);
479 return u;
480}
481template <Config Conf>
483 crvec<Conf> xu) {
484 OCPVariables<Conf> dim{problem};
485 vec<Conf> x((dim.N + 1) * dim.nx());
486 assign_extract_x(dim, xu, x);
487 return x;
488}
489
490} // namespace detail
491
492} // namespace alpaqa
Nonlinear optimal control problem with finite horizon .
void eval_add_R_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out, rvec work) const
.
void eval_add_gn_hess_constr_N(crvec x, crvec M, rmat out) const
Gauss-Newton Hessian of terminal constraints .
length_t get_S_work_size() const
Size of the workspace required by eval_add_S_masked() and eval_add_S_prod_masked().
void eval_qr(index_t timestep, crvec xu, crvec h, rvec qr) const
Cost gradients w.r.t.
void eval_add_S_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const
.
void eval_constr_N(crvec x, rvec c) const
Terminal constraints .
void eval_grad_constr_prod_N(crvec x, crvec p, rvec grad_cx_p) const
Gradient-vector product of terminal constraints .
void eval_add_R_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const
Cost Hessian w.r.t.
real_t eval_l_N(crvec h) const
Terminal cost .
real_t eval_l(index_t timestep, crvec h) const
Stage cost .
void eval_grad_f_prod(index_t timestep, crvec x, crvec u, crvec p, rvec grad_fxu_p) const
Gradient-vector product of discrete-time dynamics .
void eval_add_gn_hess_constr(index_t timestep, crvec x, crvec M, rmat out) const
Gauss-Newton Hessian of stage constraints .
void eval_constr(index_t timestep, crvec x, rvec c) const
Stage constraints .
void eval_h(index_t timestep, crvec x, crvec u, rvec h) const
Stage output mapping .
length_t get_R_work_size() const
Size of the workspace required by eval_add_R_masked() and eval_add_R_prod_masked().
void eval_add_S_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat S, rvec work) const
Cost Hessian w.r.t.
void eval_q_N(crvec x, crvec h, rvec q) const
Terminal cost gradient w.r.t.
void eval_add_Q_N(crvec x, crvec h, rmat Q) const
Terminal cost Hessian w.r.t.
void eval_grad_constr_prod(index_t timestep, crvec x, crvec p, rvec grad_cx_p) const
Gradient-vector product of stage constraints .
void eval_add_Q(index_t timestep, crvec xu, crvec h, rmat Q) const
Cost Hessian w.r.t.
void eval_f(index_t timestep, crvec x, crvec u, rvec fxu) const
Discrete-time dynamics .
void eval_h_N(crvec x, rvec h) const
Terminal output mapping .
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
void assign_extract_x(const OCPVariables< Conf > &dim, crvec< Conf > storage, rvec< Conf > x)
Definition ocp-vars.hpp:466
void assign_extract_u(const OCPVariables< Conf > &dim, crvec< Conf > storage, rvec< Conf > u)
Definition ocp-vars.hpp:460
vec< Conf > extract_u(const TypeErasedControlProblem< Conf > &problem, crvec< Conf > xu)
Definition ocp-vars.hpp:474
vec< Conf > extract_x(const TypeErasedControlProblem< Conf > &problem, crvec< Conf > xu)
Definition ocp-vars.hpp:482
void assign_interleave_xu(const OCPVariables< Conf > &dim, crvec< Conf > u, rvec< Conf > storage)
Definition ocp-vars.hpp:445
typename Conf::mat mat
Definition config.hpp:71
constexpr auto const_or_mut_rvec(V &&v)
Definition ocp-vars.hpp:15
typename Conf::crmat crmat
Definition config.hpp:75
typename Conf::rmat rmat
Definition config.hpp:74
typename Conf::real_t real_t
Definition config.hpp:65
typename Conf::index_t index_t
Definition config.hpp:77
void check_finiteness(const auto &v, std::string_view msg)
If the given vector v is not finite, break or throw an exception with the given message msg.
typename Conf::length_t length_t
Definition config.hpp:76
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70
typename Conf::vec vec
Definition config.hpp:66
typename Conf::crindexvec crindexvec
Definition config.hpp:80
void forward_simulate(rvec storage) const
Definition ocp-vars.hpp:229
OCPEvaluator(const Problem &problem)
Definition ocp-vars.hpp:173
void forward_simulate(crvec u, rvec x) const
Definition ocp-vars.hpp:253
void Rk(crvec storage, index_t k, crindexvec mask, rmat out)
Definition ocp-vars.hpp:371
auto R_prod(crvec storage) const
Definition ocp-vars.hpp:414
auto S(crvec storage)
Definition ocp-vars.hpp:394
void Sk(crvec storage, index_t k, crindexvec mask, rmat out)
Definition ocp-vars.hpp:387
auto Q(crvec storage, crvec y, crvec μ, const Box &D, const Box &D_N) const
Definition ocp-vars.hpp:361
real_t forward(rvec storage, const Box &D, const Box &D_N, crvec μ, crvec y) const
Definition ocp-vars.hpp:181
void backward(rvec storage, rvec g, const auto &qr, const auto &q_N, const Box &D, const Box &D_N, crvec μ, crvec y) const
Definition ocp-vars.hpp:263
void Sk_prod(crvec storage, index_t k, crindexvec mask_K, crvec v, rvec out) const
Definition ocp-vars.hpp:424
const Problem * problem
Definition ocp-vars.hpp:165
void Qk(crvec storage, crvec y, crvec μ, const Box &D, const Box &D_N, index_t k, rmat out) const
Definition ocp-vars.hpp:327
auto R(crvec storage)
Definition ocp-vars.hpp:378
length_t N() const
Definition ocp-vars.hpp:175
void Rk_prod(crvec storage, index_t k, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out) const
Definition ocp-vars.hpp:403
auto S_prod(crvec storage) const
Definition ocp-vars.hpp:433
vec create_qr() const
Definition ocp-vars.hpp:95
auto r(crvec v) const
Definition ocp-vars.hpp:110
rmat Bk(rmat AB, index_t t) const
Definition ocp-vars.hpp:145
vec create() const
Definition ocp-vars.hpp:65
length_t nh_N() const
Definition ocp-vars.hpp:62
rmat Ak(rmat AB, index_t t) const
Definition ocp-vars.hpp:137
auto ck(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:89
crmat Ak(crmat AB, index_t t) const
Definition ocp-vars.hpp:138
mat create_AB() const
Definition ocp-vars.hpp:124
auto A(crmat AB) const
Definition ocp-vars.hpp:142
rmat ABk(rmat AB, index_t t) const
Definition ocp-vars.hpp:125
auto qN_mut(vec &v) const
Definition ocp-vars.hpp:103
length_t nu() const
Definition ocp-vars.hpp:57
length_t nx() const
Definition ocp-vars.hpp:56
auto xk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:66
length_t size(size_t i) const
Definition ocp-vars.hpp:54
length_t nx_N() const
Definition ocp-vars.hpp:61
length_t nxu() const
Definition ocp-vars.hpp:58
auto B(crmat AB) const
Definition ocp-vars.hpp:154
std::array< index_t, 4 > indices
Definition ocp-vars.hpp:52
length_t nh() const
Definition ocp-vars.hpp:59
auto qr_mut(vec &v) const
Definition ocp-vars.hpp:120
auto qr(crvec v) const
Definition ocp-vars.hpp:117
auto uk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:76
crmat Bk(crmat AB, index_t t) const
Definition ocp-vars.hpp:148
length_t nc_N() const
Definition ocp-vars.hpp:63
auto qrk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:113
auto ABk(mat &AB, index_t t) const
Definition ocp-vars.hpp:128
auto AB(crmat AB) const
Definition ocp-vars.hpp:134
length_t nc() const
Definition ocp-vars.hpp:60
auto qk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:96
crmat ABk(crmat AB, index_t t) const
Definition ocp-vars.hpp:131
auto rk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:106
auto Ak(mat &AB, index_t t) const
Definition ocp-vars.hpp:141
auto xuk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:72
auto hk(VectorRefLike< config_t > auto &&v, index_t t) const
Definition ocp-vars.hpp:84
std::array< index_t, 3 > indices_N
Definition ocp-vars.hpp:53
length_t size_N(size_t i) const
Definition ocp-vars.hpp:55
auto Bk(mat &AB, index_t t) const
Definition ocp-vars.hpp:151
auto u(crvec v) const
Definition ocp-vars.hpp:81
OCPVariables(const std::array< index_t, 4 > &sizes, const std::array< index_t, 3 > &sizes_N, length_t N)
Definition ocp-vars.hpp:26
auto x(crvec v) const
Definition ocp-vars.hpp:69
OCPVariables(const TypeErasedControlProblem< config_t > &prob)
Definition ocp-vars.hpp:37
auto q(crvec v) const
Definition ocp-vars.hpp:100