aligator  0.15.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
riccati-kernel.hpp
Go to the documentation of this file.
1
3#pragma once
4
7#include "blk-matrix.hpp"
8
10#include <Eigen/LU>
11#include <Eigen/Cholesky>
12
14
15#include <optional>
16
17namespace aligator {
18namespace gar {
19
21template <class T, class A>
22inline boost::span<T> make_span_from_indices(std::vector<T, A> &vec, size_t i0,
23 size_t i1) {
24 return boost::make_span(vec.data() + i0, i1 - i0);
25}
26
28template <class T, class A>
29inline boost::span<const T> make_span_from_indices(const std::vector<T, A> &vec,
30 size_t i0, size_t i1) {
31 return boost::make_span(vec.data() + i0, i1 - i0);
32}
33
35template <typename _Scalar> struct StageFactor {
36 using Scalar = _Scalar;
38
39 struct value_t {
40 MatrixXs Pmat; //< Riccati matrix
41 VectorXs pvec; //< Riccati bias
42 MatrixXs Vxx; //< "cost-to-go" matrix
43 VectorXs vx; //< "cost-to-go" gradient
44 MatrixXs Vxt;
45 MatrixXs Vtt;
46 VectorXs vt;
47
48 value_t(uint nx, uint nth)
49 : Pmat(nx, nx)
50 , pvec(nx)
51 , Vxx(nx, nx)
52 , vx(nx)
53 , Vxt(nx, nth)
54 , Vtt(nth, nth)
55 , vt(nth) {
56 Vxt.setZero();
57 Vtt.setZero();
58 vt.setZero();
59 }
60 };
61
62 StageFactor(uint nx, uint nu, uint nc, uint nx2, uint nth);
63
64 MatrixXs Qhat;
65 MatrixXs Rhat;
66 MatrixXs Shat;
67 VectorXs qhat;
68 VectorXs rhat;
69 RowMatrixXs AtV;
70 RowMatrixXs BtV;
71
72 // Parametric
73 MatrixXs Gxhat;
74 MatrixXs Guhat;
75
76 BlkMatrix<VectorXs, 4, 1> ff; //< feedforward gains
77 BlkMatrix<RowMatrixXs, 4, 1> fb; //< feedback gains
78 BlkMatrix<RowMatrixXs, 4, 1> fth; //< parameter feedback gains
79 BlkMatrix<MatrixXs, 2, 2> kktMat; //< reduced KKT matrix buffer
80 Eigen::BunchKaufman<MatrixXs> kktChol; //< reduced KKT LDLT solver
81 Eigen::PartialPivLU<MatrixXs> Efact; //< LU decomp. of E matrix
82 VectorXs yff_pre;
83 MatrixXs A_pre;
84 MatrixXs Yth_pre;
85 MatrixXs Ptilde; //< product Et.inv P * E.inv
86 MatrixXs Einv; //< product P * E.inv
87 MatrixXs EinvP; //< product P * E.inv
88 MatrixXs schurMat; //< Dual-space Schur matrix
89 Eigen::LLT<MatrixXs> schurChol; //< Cholesky decomposition of Schur matrix
90 value_t vm; //< cost-to-go parameters
91};
92
95template <typename Scalar> struct ProximalRiccatiKernel {
100
111
112 static void terminalSolve(typename KnotType::const_view_t model,
113 const Scalar mueq, StageFactorType &d);
114
115 static bool backwardImpl(boost::span<const KnotType> stages,
116 const Scalar mudyn, const Scalar mueq,
117 boost::span<StageFactorType> datas);
118
120 static void computeInitial(VectorRef x0, VectorRef lbd0, const kkt0_t &kkt0,
121 const std::optional<ConstVectorRef> &theta_);
122
123 static void stageKernelSolve(typename KnotType::const_view_t model,
124 StageFactorType &d, value_t &vn,
125 const Scalar mudyn, const Scalar mueq);
126
128 static bool
129 forwardImpl(boost::span<const KnotType> stages,
130 boost::span<const StageFactorType> datas,
131 boost::span<VectorXs> xs, boost::span<VectorXs> us,
132 boost::span<VectorXs> vs, boost::span<VectorXs> lbdas,
133 const std::optional<ConstVectorRef> &theta_ = std::nullopt);
134};
135
136#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
137extern template struct StageFactor<context::Scalar>;
138extern template struct ProximalRiccatiKernel<context::Scalar>;
139#endif
140
141} // namespace gar
142} // namespace aligator
Block matrix class, with a fixed-size number of row and column blocks.
const row_dim_t & rowDims() const
unsigned int uint
Definition work.hpp:8
boost::span< T > make_span_from_indices(std::vector< T, A > &vec, size_t i0, size_t i1)
Create a boost::span object from a vector and two indices.
Main package namespace.
constexpr span< I > make_span(I *f, std::size_t c) noexcept
Definition make_span.hpp:17
Struct describing a stage of a constrained LQ problem.
__view_base< true > const_view_t
Kernel for use in Riccati-like algorithms for the proximal LQ subproblem.
static bool backwardImpl(boost::span< const KnotType > stages, const Scalar mudyn, const Scalar mueq, boost::span< StageFactorType > datas)
static bool forwardImpl(boost::span< const KnotType > stages, boost::span< const StageFactorType > datas, boost::span< VectorXs > xs, boost::span< VectorXs > us, boost::span< VectorXs > vs, boost::span< VectorXs > lbdas, const std::optional< ConstVectorRef > &theta_=std::nullopt)
Forward sweep.
static void stageKernelSolve(typename KnotType::const_view_t model, StageFactorType &d, value_t &vn, const Scalar mudyn, const Scalar mueq)
typename StageFactor< Scalar >::value_t value_t
static void computeInitial(VectorRef x0, VectorRef lbd0, const kkt0_t &kkt0, const std::optional< ConstVectorRef > &theta_)
Solve initial stage.
static void terminalSolve(typename KnotType::const_view_t model, const Scalar mueq, StageFactorType &d)
Per-node struct for all computations in the factorization.
BlkMatrix< RowMatrixXs, 4, 1 > fth
Eigen::PartialPivLU< MatrixXs > Efact
BlkMatrix< VectorXs, 4, 1 > ff
ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar)
BlkMatrix< RowMatrixXs, 4, 1 > fb
Eigen::BunchKaufman< MatrixXs > kktChol
BlkMatrix< MatrixXs, 2, 2 > kktMat
StageFactor(uint nx, uint nu, uint nc, uint nx2, uint nth)