8#include <batmat/config.hpp>
9#include <guanaqo/mat-view.hpp>
59 auto [N, nx, nu, ny, ny_N] =
dim;
60 index_t size = N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 2 + N) * nx +
61 2 * N * ny + 2 * ny_N;
62 return std::vector<real_t>(size);
65 auto [N, nx, nu, ny, ny_N] =
dim;
68 index_t size = (nx + nu) * (nx + nu);
70 .data = &
storage[offset + i * size],
71 .rows = i < N ? nx + nu : nx,
72 .cols = i < N ? nx + nu : nx,
76 auto [N, nx, nu, ny, ny_N] =
dim;
78 return H(i).top_left(nx, nx);
81 auto [N, nx, nu, ny, ny_N] =
dim;
83 return H(i).bottom_right(nu, nu);
86 auto [N, nx, nu, ny, ny_N] =
dim;
88 return H(i).bottom_left(nu, nx);
91 auto [N, nx, nu, ny, ny_N] =
dim;
93 return H(i).top_right(nx, nu);
96 auto [N, nx, nu, ny, ny_N] =
dim;
98 index_t offset = N * (nx + nu) * (nx + nu) + nx * nx;
99 index_t size = ny * (nx + nu);
101 .data = &
storage[offset + i * size],
102 .rows = i < N ? ny : ny_N,
103 .cols = i < N ? nx + nu : nx,
107 auto [N, nx, nu, ny, ny_N] =
dim;
109 return CD(i).left_cols(nx);
112 auto [N, nx, nu, ny, ny_N] =
dim;
114 return CD(i).right_cols(nu);
117 auto [N, nx, nu, ny, ny_N] =
dim;
119 index_t offset = N * (nx + nu + ny) * (nx + nu) + (nx + ny_N) * nx;
120 index_t size = nx * (nx + nu);
122 .data = &
storage[offset + i * size],
128 auto [N, nx, nu, ny, ny_N] =
dim;
130 return AB(i).left_cols(nx);
133 auto [N, nx, nu, ny, ny_N] =
dim;
135 return AB(i).right_cols(nu);
139 auto [N, nx, nu, ny, ny_N] =
dim;
142 index_t size = (nx + nu) * (nx + nu);
144 .data = &
storage[offset + i * size],
145 .rows = i < N ? nx + nu : nx,
146 .cols = i < N ? nx + nu : nx,
150 auto [N, nx, nu, ny, ny_N] =
dim;
152 return H(i).top_left(nx, nx);
155 auto [N, nx, nu, ny, ny_N] =
dim;
157 return H(i).bottom_right(nu, nu);
160 auto [N, nx, nu, ny, ny_N] =
dim;
162 return H(i).bottom_left(nu, nx);
165 auto [N, nx, nu, ny, ny_N] =
dim;
167 return H(i).top_right(nx, nu);
170 auto [N, nx, nu, ny, ny_N] =
dim;
172 index_t offset = N * (nx + nu) * (nx + nu) + nx * nx;
173 index_t size = ny * (nx + nu);
175 .data = &
storage[offset + i * size],
176 .rows = i < N ? ny : ny_N,
177 .cols = i < N ? nx + nu : nx,
181 auto [N, nx, nu, ny, ny_N] =
dim;
183 return CD(i).left_cols(nx);
186 auto [N, nx, nu, ny, ny_N] =
dim;
188 return CD(i).right_cols(nu);
191 auto [N, nx, nu, ny, ny_N] =
dim;
193 index_t offset = N * (nx + nu + ny) * (nx + nu) + (nx + ny_N) * nx;
194 index_t size = nx * (nx + nu);
196 .data = &
storage[offset + i * size],
202 auto [N, nx, nu, ny, ny_N] =
dim;
204 return AB(i).left_cols(nx);
207 auto [N, nx, nu, ny, ny_N] =
dim;
209 return AB(i).right_cols(nu);
213 auto [N, nx, nu, ny, ny_N] =
dim;
214 return N * (nx + nu) + nx;
217 auto [N, nx, nu, ny, ny_N] =
dim;
218 return N * ny + ny_N;
221 auto [N, nx, nu, ny, ny_N] =
dim;
226 auto [N, nx, nu, ny, ny_N] =
dim;
227 index_t offset = N * (2 * nx + nu + ny) * (nx + nu) + (nx + ny_N) * nx;
229 .data =
storage.data() + offset,
230 .rows = N * (nx + nu) + nx,
235 auto [N, nx, nu, ny, ny_N] =
dim;
237 index_t size = nx + nu;
238 return qr().middle_rows(i * size, i < N ? size : nx);
241 auto [N, nx, nu, ny, ny_N] =
dim;
243 return qr(i).top_rows(nx);
246 auto [N, nx, nu, ny, ny_N] =
dim;
248 return qr(i).bottom_rows(nu);
252 auto [N, nx, nu, ny, ny_N] =
dim;
253 index_t offset = N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 1) * nx;
255 .data =
storage.data() + offset,
256 .rows = (N + 1) * nx,
261 auto [N, nx, nu, ny, ny_N] =
dim;
264 return b().middle_rows(i * size, size);
268 auto [N, nx, nu, ny, ny_N] =
dim;
269 index_t offset = N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 2 + N) * nx;
271 .data =
storage.data() + offset,
272 .rows = N * ny + ny_N,
277 auto [N, nx, nu, ny, ny_N] =
dim;
280 return b_min().middle_rows(i * size, i < N ? size : ny_N);
284 auto [N, nx, nu, ny, ny_N] =
dim;
286 N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 2 + N) * nx + N * ny + ny_N;
288 .data =
storage.data() + offset,
289 .rows = N * ny + ny_N,
294 auto [N, nx, nu, ny, ny_N] =
dim;
297 return b_max().middle_rows(i * size, i < N ? size : ny_N);
301 auto [N, nx, nu, ny, ny_N] =
dim;
302 index_t offset = N * (2 * nx + nu + ny) * (nx + nu) + (nx + ny_N) * nx;
304 .data =
storage.data() + offset,
305 .rows = N * (nx + nu) + nx,
310 auto [N, nx, nu, ny, ny_N] =
dim;
312 index_t size = nx + nu;
313 return qr().middle_rows(i * size, i < N ? size : nx);
316 auto [N, nx, nu, ny, ny_N] =
dim;
318 return qr(i).top_rows(nx);
321 auto [N, nx, nu, ny, ny_N] =
dim;
323 return qr(i).bottom_rows(nu);
327 auto [N, nx, nu, ny, ny_N] =
dim;
328 index_t offset = N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 1) * nx;
330 .data =
storage.data() + offset,
331 .rows = (N + 1) * nx,
336 auto [N, nx, nu, ny, ny_N] =
dim;
339 return b().middle_rows(i * size, size);
343 auto [N, nx, nu, ny, ny_N] =
dim;
344 index_t offset = N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 2 + N) * nx;
346 .data =
storage.data() + offset,
347 .rows = N * ny + ny_N,
352 auto [N, nx, nu, ny, ny_N] =
dim;
355 return b_min().middle_rows(i * size, i < N ? size : ny_N);
359 auto [N, nx, nu, ny, ny_N] =
dim;
361 N * (2 * nx + nu + ny + 1) * (nx + nu) + (nx + ny_N + 2 + N) * nx + N * ny + ny_N;
363 .data =
storage.data() + offset,
364 .rows = N * ny + ny_N,
369 auto [N, nx, nu, ny, ny_N] =
dim;
372 return b_max().middle_rows(i * size, i < N ? size : ny_N);
379 auto [N, nx, nu, ny, ny_N] =
dim;
380 return {{.data =
solution.data(), .rows = nx, .cols = N + 1, .outer_stride = nx + nu}};
383 auto [N, nx, nu, ny, ny_N] =
dim;
384 return {{.data =
solution.data(), .rows = nx, .cols = N + 1, .outer_stride = nx + nu}};
387 return x(
dim).middle_cols(i, 1);
390 return x(
dim).middle_cols(i, 1);
394 auto [N, nx, nu, ny, ny_N] =
dim;
395 return {{.data =
solution.data() + nx, .rows = nu, .cols = N, .outer_stride = nx + nu}};
398 auto [N, nx, nu, ny, ny_N] =
dim;
399 return {{.data =
solution.data() + nx, .rows = nu, .cols = N, .outer_stride = nx + nu}};
402 return u(
dim).middle_cols(i, 1);
405 return u(
dim).middle_cols(i, 1);
409 auto [N, nx, nu, ny, ny_N] =
dim;
413 .outer_stride = nx}};
416 auto [N, nx, nu, ny, ny_N] =
dim;
420 .outer_stride = nx}};
423 return λ(
dim).middle_cols(i, 1);
426 return λ(
dim).middle_cols(i, 1);
430 auto [N, nx, nu, ny, ny_N] =
dim;
432 .rows = i < N ? ny : ny_N,
436 auto [N, nx, nu, ny, ny_N] =
dim;
438 .rows = i < N ? ny : ny_N,
guanaqo::MatrixView< real_t, index_t > u(OCPDim dim)
std::vector< real_t > inequality_multipliers
guanaqo::MatrixView< real_t, index_t > u(OCPDim dim, index_t i)
guanaqo::MatrixView< const real_t, index_t > y(OCPDim dim, index_t i) const
std::vector< real_t > solution
guanaqo::MatrixView< real_t, index_t > x(OCPDim dim)
guanaqo::MatrixView< real_t, index_t > y(OCPDim dim, index_t i)
guanaqo::MatrixView< real_t, index_t > x(OCPDim dim, index_t i)
guanaqo::MatrixView< const real_t, index_t > x(OCPDim dim) const
guanaqo::MatrixView< const real_t, index_t > u(OCPDim dim) const
guanaqo::MatrixView< real_t, index_t > λ(OCPDim dim, index_t i)
std::vector< real_t > equality_multipliers
guanaqo::MatrixView< real_t, index_t > λ(OCPDim dim)
guanaqo::MatrixView< const real_t, index_t > x(OCPDim dim, index_t i) const
guanaqo::MatrixView< const real_t, index_t > u(OCPDim dim, index_t i) const
guanaqo::MatrixView< const real_t, index_t > λ(OCPDim dim) const
guanaqo::MatrixView< const real_t, index_t > λ(OCPDim dim, index_t i) const
Storage for a linear-quadratic OCP of the form.
guanaqo::MatrixView< real_t, index_t > r(index_t i)
guanaqo::MatrixView< real_t, index_t > q(index_t i)
guanaqo::MatrixView< real_t, index_t > qr(index_t i)
std::vector< real_t > storage
Create a single contiguous storage for all problem data.
guanaqo::MatrixView< const real_t, index_t > b_max(index_t i) const
guanaqo::MatrixView< const real_t, index_t > A(index_t i) const
guanaqo::MatrixView< real_t, index_t > B(index_t i)
guanaqo::MatrixView< real_t, index_t > CD(index_t i)
guanaqo::MatrixView< real_t, index_t > D(index_t i)
guanaqo::MatrixView< real_t, index_t > b_min()
KKTError compute_kkt_error(const Solution &sol) const
guanaqo::MatrixView< real_t, index_t > b()
guanaqo::MatrixView< real_t, index_t > R(index_t i)
guanaqo::MatrixView< const real_t, index_t > S(index_t i) const
guanaqo::MatrixView< const real_t, index_t > CD(index_t i) const
guanaqo::MatrixView< const real_t, index_t > q(index_t i) const
guanaqo::MatrixView< real_t, index_t > H(index_t i)
guanaqo::MatrixView< const real_t, index_t > H(index_t i) const
guanaqo::MatrixView< const real_t, index_t > B(index_t i) const
static std::vector< real_t > create_storage(OCPDim dim)
guanaqo::MatrixView< const real_t, index_t > D(index_t i) const
guanaqo::MatrixView< const real_t, index_t > b_min() const
guanaqo::MatrixView< real_t, index_t > C(index_t i)
guanaqo::MatrixView< real_t, index_t > S(index_t i)
guanaqo::MatrixView< real_t, index_t > Q(index_t i)
guanaqo::MatrixView< real_t, index_t > A(index_t i)
guanaqo::MatrixView< real_t, index_t > S_trans(index_t i)
guanaqo::MatrixView< real_t, index_t > b_max()
guanaqo::MatrixView< const real_t, index_t > b() const
index_t num_constraints() const
index_t num_dynamics_constraints() const
guanaqo::MatrixView< real_t, index_t > b_min(index_t i)
guanaqo::MatrixView< const real_t, index_t > S_trans(index_t i) const
guanaqo::MatrixView< real_t, index_t > AB(index_t i)
guanaqo::MatrixView< const real_t, index_t > C(index_t i) const
guanaqo::MatrixView< const real_t, index_t > b_max() const
guanaqo::MatrixView< const real_t, index_t > R(index_t i) const
guanaqo::MatrixView< const real_t, index_t > qr(index_t i) const
guanaqo::MatrixView< const real_t, index_t > r(index_t i) const
index_t num_variables() const
guanaqo::MatrixView< real_t, index_t > qr()
guanaqo::MatrixView< real_t, index_t > b(index_t i)
guanaqo::MatrixView< const real_t, index_t > b(index_t i) const
guanaqo::MatrixView< const real_t, index_t > qr() const
guanaqo::MatrixView< const real_t, index_t > AB(index_t i) const
guanaqo::MatrixView< const real_t, index_t > b_min(index_t i) const
guanaqo::MatrixView< real_t, index_t > b_max(index_t i)
real_t inequality_residual
guanaqo::MatrixView< const real_t, index_t > Q(index_t i) const
Dimensions of an optimal control problem.
index_t ny
Number of output variables.
index_t nu
Number of input variables.
index_t ny_N
Number of output variables in the last stage.
friend constexpr bool operator==(OCPDim, OCPDim)=default
index_t nx
Number of state variables.
friend constexpr bool operator!=(OCPDim, OCPDim)=default
index_t N_horiz
Horizon length (one less than the number of stages).