cyqlone develop
Fast, parallel and vectorized solver for linear systems with optimal control structure.
Loading...
Searching...
No Matches
conversion.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * Conversion utilities for optimal control problems.
4 * For example: converting an OCP into a sparse “multiple shooting”
5 * quadratic program, or computing the gradient of the quadratic OCP
6 * cost function.
7 * @ingroup topic-ocp-formulations
8 */
9
10#pragma once
11
12#include <cyqlone/config.hpp>
13#include <cyqlone/ocp.hpp>
14#include <guanaqo/linalg/sparsity.hpp>
15#include <vector>
16
17namespace cyqlone {
18
19using guanaqo::linalg::sparsity::SparseCSC;
20
21/// Represents a sparse multiple shooting formulation of the standard optimal
22/// control problem.
23/// @ingroup topic-ocp-formulations
25 std::vector<index_t> Q_outer_ptr, Q_inner_idx;
26 std::vector<real_t> Q_values;
28 std::vector<index_t> A_outer_ptr, A_inner_idx;
29 std::vector<real_t> A_values;
31 index_t n, m_eq, m_ineq;
32
33 [[nodiscard]] static LinearOCPSparseQP build(const LinearOCPStorage &ocp);
34
35 struct KKTMatrix {
36 std::vector<index_t> outer_ptr, inner_idx;
37 std::vector<real_t> values;
39 };
40 /// Returns the lower part of the symmetric indefinite KKT matrix for the
41 /// active set @p J and penalty factors @p Σ.
42 [[nodiscard]] KKTMatrix build_kkt(real_t S, std::span<const real_t> Σ,
43 std::span<const bool> J) const;
44};
45
46/// Simply computes the gradient of the quadratic cost
47/// @f$ J(x, u) = \sum_{j=1}^{N-1} \ell_j(x^j, u^j) + \ell_N(x^N) @f$,
48/// with @f$ \ell_j(x, u) = \tfrac12 \left\| \begin{pmatrix} x - x^j_\text{ref}
49/// \\ u - u^j_\text{ref} \end{pmatrix} \right\|_{H_j}^2 @f$, with the Hessian
50/// @f$ H_j = \begin{pmatrix} Q_j & S_j^\top \\ S_j & R_j \end{pmatrix} @f$.
51/// Stores @f$ \nabla J(0, 0) @f$ to @p qr.
52/// @ingroup topic-ocp-formulations
53void reference_to_gradient(const LinearOCPStorage &ocp, std::span<const real_t> ref,
54 std::span<real_t> qr);
55/// @copydoc reference_to_gradient
56void reference_to_gradient(LinearOCPStorage &ocp, std::span<const real_t> ref);
57
58} // namespace cyqlone
void reference_to_gradient(const LinearOCPStorage &ocp, std::span< const real_t > ref, std::span< real_t > qr)
Simply computes the gradient of the quadratic cost , with , with the Hessian .
Definition conversion.cpp:9
Data structure for optimal control problems.
Represents a sparse multiple shooting formulation of the standard optimal control problem.
SparseCSC< index_t, index_t > A_sparsity
std::vector< real_t > A_values
std::vector< index_t > A_outer_ptr
static LinearOCPSparseQP build(const LinearOCPStorage &ocp)
std::vector< index_t > A_inner_idx
SparseCSC< index_t, index_t > Q_sparsity
std::vector< index_t > Q_outer_ptr
std::vector< index_t > Q_inner_idx
SparseCSC< index_t, index_t > sparsity
KKTMatrix build_kkt(real_t S, std::span< const real_t > Σ, std::span< const bool > J) const
Returns the lower part of the symmetric indefinite KKT matrix for the active set J and penalty factor...
std::vector< real_t > Q_values
Storage for a linear-quadratic OCP of the form.
Definition ocp.hpp:37