#include <alpaqa/problem/ocproblem.hpp>
Nonlinear optimal control problem with finite horizon \( N \).
\[\newcommand\U{U} \newcommand\D{D} \newcommand\nnu{{n_u}} \newcommand\nnx{{n_x}} \newcommand\nny{{n_y}} \newcommand\xinit{x_\text{init}} \begin{equation}\label{eq:OCP} \tag{OCP}\hspace{-0.8em} \begin{aligned} &\minimize_{u,x} && \sum_{k=0}^{N-1} \ell_k\big(h_k(x^k, u^k)\big) + \ell_N\big(h_N(x^N)\big)\hspace{-0.8em} \\ &\subjto && u^k \in \U \\ &&& c_k(x^k) \in \D \\ &&& c_N(x^N) \in \D_N \\ &&& x^0 = \xinit \\ &&& x^{k+1} = f(x^k, u^k) \quad\quad (0 \le k \lt N) \end{aligned} \end{equation} \]
The function \( f : \R^\nnx \times \R^\nnu \to \R^\nnx \) models the discrete-time, nonlinear dynamics of the system, which starts from an initial state \( \xinit \). The functions \( h_k : \R^\nnx \times \R^\nnu \to \R^{n_h} \) for \( 0 \le k \lt N \) and \( h_N : \R^\nnx \to \R^{n_h^N} \) can be used to represent the (possibly time-varying) output mapping of the system, and the convex functions \( \ell_k : \R^{n_h} \to \R \) and \( \ell_N : \R^{n_h^N} \to \R \) define the stage costs and the terminal cost respectively. Stage constraints and terminal constraints are represented by the functions \( c_k : \R^{n_x} \to \R^{n_c} \) and \( c_N : \R^{n_x} \to \R^{n_c^N} \), and the boxes \( D \) and \( D_N \).
Additional functions for computing Gauss-Newton approximations of the cost Hessian are included as well:
\[ \begin{aligned} q^k &\defeq \tp{\jac_{h_k}^x\!(\barxuk)} \nabla \ell_k(\hhbar^k) \\ r^k &\defeq \tp{\jac_{h_k}^u\!(\barxuk)} \nabla \ell_k(\hhbar^k) \\ \Lambda_k &\defeq \partial^2 \ell_k(\hhbar^k) \\ Q_k &\defeq \tp{\jac_{h_k}^x\!(\barxuk)} \Lambda_k\, \jac_{h_k}^x\!(\barxuk) \\ S_k &\defeq \tp{\jac_{h_k}^u\!(\barxuk)} \Lambda_k\, \jac_{h_k}^x\!(\barxuk) \\ R_k &\defeq \tp{\jac_{h_k}^u\!(\barxuk)} \Lambda_k\, \jac_{h_k}^u\!(\barxuk). \\ \end{aligned} \]
See [3] for more details.
Definition at line 242 of file ocproblem.hpp.
Problem dimensions | |
length_t | get_N () const |
Horizon length. | |
length_t | get_nu () const |
Number of inputs. | |
length_t | get_nx () const |
Number of states. | |
length_t | get_nh () const |
Number of outputs. | |
length_t | get_nh_N () const |
length_t | get_nc () const |
Number of constraints. | |
length_t | get_nc_N () const |
Dim | get_dim () const |
All dimensions. | |
length_t | get_num_variables () const |
Total number of variables. | |
length_t | get_num_constraints () const |
Total number of constraints. |
Projections onto constraint sets | |
void | eval_projecting_difference_constraints (crvec z, rvec e) const |
[Required] Function that evaluates the difference between the given point \( z \) and its projection onto the constraint set \( D \). | |
void | eval_projection_multipliers (rvec y, real_t M) const |
[Required] Function that projects the Lagrange multipliers for ALM. |
Constraint sets | |
void | get_U (Box &U) const |
Input box constraints \( U \). | |
void | get_D (Box &D) const |
Stage box constraints \( D \). | |
void | get_D_N (Box &D) const |
Terminal box constraints \( D_N \). |
Dynamics and initial state | |
void | get_x_init (rvec x_init) const |
Initial state \( x_\text{init} \). | |
void | eval_f (index_t timestep, crvec x, crvec u, rvec fxu) const |
Discrete-time dynamics \( x^{k+1} = f_k(x^k, u^k) \). | |
void | eval_jac_f (index_t timestep, crvec x, crvec u, rmat J_fxu) const |
Jacobian of discrete-time dynamics \( \jac_f(x^k, u^k) \). | |
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 \( \nabla f(x^k, u^k)\,p \). |
Output mapping | |
void | eval_h (index_t timestep, crvec x, crvec u, rvec h) const |
Stage output mapping \( h_k(x^k, u^k) \). | |
void | eval_h_N (crvec x, rvec h) const |
Terminal output mapping \( h_N(x^N) \). |
Stage and terminal cost | |
real_t | eval_l (index_t timestep, crvec h) const |
Stage cost \( \ell_k(\hbar^k) \). | |
real_t | eval_l_N (crvec h) const |
Terminal cost \( \ell_N(\hbar^N) \). |
Gauss-Newton approximations | |
void | eval_qr (index_t timestep, crvec xu, crvec h, rvec qr) const |
Cost gradients w.r.t. | |
void | eval_q_N (crvec x, crvec h, rvec q) const |
Terminal cost gradient w.r.t. | |
void | eval_add_Q (index_t timestep, crvec xu, crvec h, rmat Q) const |
Cost Hessian w.r.t. | |
void | eval_add_Q_N (crvec x, crvec h, rmat Q) const |
Terminal cost Hessian w.r.t. | |
void | eval_add_R_masked (index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const |
Cost Hessian w.r.t. | |
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_add_R_prod_masked (index_t timestep, crvec xu, crvec h, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out, rvec work) const |
\( out \leftarrow out + R[\mathcal J, \mathcal K]\,v[\mathcal K] \). | |
void | eval_add_S_prod_masked (index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const |
\( out \leftarrow out + \tp{S[\mathcal K, \cdot]}\, v[\mathcal K] \). | |
length_t | get_R_work_size () const |
Size of the workspace required by eval_add_R_masked() and eval_add_R_prod_masked(). | |
length_t | get_S_work_size () const |
Size of the workspace required by eval_add_S_masked() and eval_add_S_prod_masked(). |
Constraints | |
void | eval_constr (index_t timestep, crvec x, rvec c) const |
Stage constraints \( c_k(x^k) \). | |
void | eval_constr_N (crvec x, rvec c) const |
Terminal constraints \( c_N(x^N) \). | |
void | eval_grad_constr_prod (index_t timestep, crvec x, crvec p, rvec grad_cx_p) const |
Gradient-vector product of stage constraints \( \nabla c_k(x^k)\, p \). | |
void | eval_grad_constr_prod_N (crvec x, crvec p, rvec grad_cx_p) const |
Gradient-vector product of terminal constraints \( \nabla c_N(x^N)\, p \). | |
void | eval_add_gn_hess_constr (index_t timestep, crvec x, crvec M, rmat out) const |
Gauss-Newton Hessian of stage constraints \( \tp{\jac_{c_k}}(x^k)\,
\operatorname{diag}(M)\; \jac_{c_k}(x^k) \). | |
void | eval_add_gn_hess_constr_N (crvec x, crvec M, rmat out) const |
Gauss-Newton Hessian of terminal constraints \( \tp{\jac_{c_N}}(x^N)\,
\operatorname{diag}(M)\; \jac_{c_N}(x^N) \). |
Checks | |
void | check () const |
Check that the problem formulation is well-defined, the dimensions match, etc. |
Querying specialized implementations | |
bool | provides_get_D () const |
bool | provides_get_D_N () const |
bool | provides_eval_h () const |
bool | provides_eval_h_N () const |
bool | provides_eval_add_Q_N () const |
bool | provides_eval_add_R_prod_masked () const |
bool | provides_eval_add_S_prod_masked () const |
bool | provides_get_R_work_size () const |
bool | provides_get_S_work_size () const |
bool | provides_eval_constr () const |
bool | provides_eval_constr_N () const |
bool | provides_eval_grad_constr_prod () const |
bool | provides_eval_grad_constr_prod_N () const |
bool | provides_eval_add_gn_hess_constr () const |
bool | provides_eval_add_gn_hess_constr_N () const |
Public Types | |
using | VTable = ControlProblemVTable<config_t> |
using | allocator_type = Allocator |
using | Box = typename VTable::Box |
using | Dim = OCPDim<config_t> |
using | TypeErased = guanaqo::TypeErased<VTable, allocator_type> |
Static Public Member Functions | |
template<class T, class... Args> | |
static TypeErasedControlProblem | make (Args &&...args) |
using VTable = ControlProblemVTable<config_t> |
Definition at line 245 of file ocproblem.hpp.
using allocator_type = Allocator |
Definition at line 246 of file ocproblem.hpp.
using Box = typename VTable::Box |
Definition at line 247 of file ocproblem.hpp.
using Dim = OCPDim<config_t> |
Definition at line 248 of file ocproblem.hpp.
using TypeErased = guanaqo::TypeErased<VTable, allocator_type> |
Definition at line 249 of file ocproblem.hpp.
|
inlinestatic |
Definition at line 259 of file ocproblem.hpp.
|
inlinenodiscard |
Horizon length.
Definition at line 267 of file ocproblem.hpp.
|
inlinenodiscard |
Number of inputs.
Definition at line 269 of file ocproblem.hpp.
|
inlinenodiscard |
Number of states.
Definition at line 271 of file ocproblem.hpp.
|
inlinenodiscard |
Number of outputs.
Definition at line 273 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 274 of file ocproblem.hpp.
|
inlinenodiscard |
Number of constraints.
Definition at line 276 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 277 of file ocproblem.hpp.
|
inlinenodiscard |
All dimensions.
Definition at line 279 of file ocproblem.hpp.
|
inlinenodiscard |
Total number of variables.
Definition at line 291 of file ocproblem.hpp.
|
inlinenodiscard |
Total number of constraints.
Definition at line 293 of file ocproblem.hpp.
|
inline |
[Required] Function that evaluates the difference between the given point \( z \) and its projection onto the constraint set \( D \).
[in] | z | Slack variable, \( z \in \R^m \) |
[out] | e | The difference relative to its projection, \( e = z - \Pi_D(z) \in \R^m \) |
z
and e
can refer to the same vector. Definition at line 524 of file ocproblem.hpp.
|
inline |
[Required] Function that projects the Lagrange multipliers for ALM.
[in,out] | y | Multipliers, \( y \leftarrow \Pi_Y(y) \in \R^m \) |
[in] | M | The radius/size of the set \( Y \). See max_multiplier. |
Definition at line 525 of file ocproblem.hpp.
|
inline |
Input box constraints \( U \).
Definition at line 526 of file ocproblem.hpp.
|
inline |
Stage box constraints \( D \).
Definition at line 527 of file ocproblem.hpp.
|
inline |
Terminal box constraints \( D_N \).
Definition at line 528 of file ocproblem.hpp.
|
inline |
Initial state \( x_\text{init} \).
Definition at line 529 of file ocproblem.hpp.
|
inline |
Discrete-time dynamics \( x^{k+1} = f_k(x^k, u^k) \).
Definition at line 530 of file ocproblem.hpp.
|
inline |
Jacobian of discrete-time dynamics \( \jac_f(x^k, u^k) \).
Definition at line 531 of file ocproblem.hpp.
|
inline |
Gradient-vector product of discrete-time dynamics \( \nabla f(x^k, u^k)\,p \).
Definition at line 532 of file ocproblem.hpp.
|
inline |
Stage output mapping \( h_k(x^k, u^k) \).
Definition at line 533 of file ocproblem.hpp.
Terminal output mapping \( h_N(x^N) \).
Definition at line 534 of file ocproblem.hpp.
|
inlinenodiscard |
Stage cost \( \ell_k(\hbar^k) \).
Definition at line 535 of file ocproblem.hpp.
|
inlinenodiscard |
Terminal cost \( \ell_N(\hbar^N) \).
Definition at line 536 of file ocproblem.hpp.
|
inline |
Cost gradients w.r.t.
states and inputs \( q^k = \tp{\jac_{h_k}^x\!(\barxuk)} \nabla \ell_k(\hbar^k) \) and \( r^k = \tp{\jac_{h_k}^u\!(\barxuk)} \nabla \ell_k(\hbar^k) \).
Definition at line 537 of file ocproblem.hpp.
Terminal cost gradient w.r.t.
states \( q^N = \tp{\jac_{h_N}(\bar x^N)} \nabla \ell_k(\hbar^N) \).
Definition at line 538 of file ocproblem.hpp.
|
inline |
Cost Hessian w.r.t.
states \( Q_k = \tp{\jac_{h_k}^x\!(\barxuk)}
\partial^2\ell_k(\hbar^k)\, \jac_{h_k}^x\!(\barxuk) \), added to the given matrix Q
. \( Q \leftarrow Q + Q_k \).
Definition at line 539 of file ocproblem.hpp.
Terminal cost Hessian w.r.t.
states \( Q_N = \tp{\jac_{h_N}(\bar x^N)}
\partial^2\ell_N(\hbar^N)\, \jac_{h_N}(\bar x^N) \), added to the given matrix Q
. \( Q \leftarrow Q + Q_N \).
Definition at line 540 of file ocproblem.hpp.
|
inline |
Cost Hessian w.r.t.
inputs \( R_k = \tp{\jac_{h_k}^u\!(\barxuk)}
\partial^2\ell_k(\hbar^k)\, \jac_{h_k}^u\!(\barxuk) \), keeping only rows and columns in the mask \( \mathcal J \), added to the given matrix R
. \( R \leftarrow R + R_k[\mathcal J, \mathcal J] \). The size of work
should be get_R_work_size().
Definition at line 541 of file ocproblem.hpp.
|
inline |
Cost Hessian w.r.t.
inputs and states \( S_k = \tp{\jac_{h_k}^u\!(\barxuk)}
\partial^2\ell_k(\hbar^k)\, \jac_{h_k}^x\!(\barxuk) \), keeping only rows in the mask \( \mathcal J \), added to the given matrix S
. \( S \leftarrow S + S_k[\mathcal J, \cdot] \). The size of work
should be get_S_work_size().
Definition at line 542 of file ocproblem.hpp.
|
inline |
\( out \leftarrow out + R[\mathcal J, \mathcal K]\,v[\mathcal K] \).
Work should contain the contents written to it by a prior call to eval_add_R_masked() in the same point.
Definition at line 543 of file ocproblem.hpp.
|
inline |
\( out \leftarrow out + \tp{S[\mathcal K, \cdot]}\, v[\mathcal K] \).
Work should contain the contents written to it by a prior call to eval_add_S_masked() in the same point.
Definition at line 544 of file ocproblem.hpp.
|
inlinenodiscard |
Size of the workspace required by eval_add_R_masked() and eval_add_R_prod_masked().
Definition at line 545 of file ocproblem.hpp.
|
inlinenodiscard |
Size of the workspace required by eval_add_S_masked() and eval_add_S_prod_masked().
Definition at line 546 of file ocproblem.hpp.
|
inline |
Stage constraints \( c_k(x^k) \).
Definition at line 547 of file ocproblem.hpp.
Terminal constraints \( c_N(x^N) \).
Definition at line 548 of file ocproblem.hpp.
|
inline |
Gradient-vector product of stage constraints \( \nabla c_k(x^k)\, p \).
Definition at line 549 of file ocproblem.hpp.
|
inline |
Gradient-vector product of terminal constraints \( \nabla c_N(x^N)\, p \).
Definition at line 550 of file ocproblem.hpp.
|
inline |
Gauss-Newton Hessian of stage constraints \( \tp{\jac_{c_k}}(x^k)\, \operatorname{diag}(M)\; \jac_{c_k}(x^k) \).
Definition at line 551 of file ocproblem.hpp.
|
inline |
Gauss-Newton Hessian of terminal constraints \( \tp{\jac_{c_N}}(x^N)\, \operatorname{diag}(M)\; \jac_{c_N}(x^N) \).
Definition at line 552 of file ocproblem.hpp.
|
inline |
Check that the problem formulation is well-defined, the dimensions match, etc.
Throws an exception if this is not the case.
Definition at line 553 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 454 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 455 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 456 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 457 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 458 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 459 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 460 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 461 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 462 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 463 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 464 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 465 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 466 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 467 of file ocproblem.hpp.
|
inlinenodiscard |
Definition at line 468 of file ocproblem.hpp.