aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
parallel-solver.hpp
Go to the documentation of this file.
1
3#pragma once
4
8
9namespace aligator {
10namespace gar {
11
12#ifdef ALIGATOR_MULTITHREADING
22template <typename _Scalar>
23class ParallelRiccatiSolver : public RiccatiSolverBase<_Scalar> {
24public:
25 using Scalar = _Scalar;
27 using Base = RiccatiSolverBase<Scalar>;
28 using StageFactorVec = std::vector<StageFactor<Scalar>>;
29 StageFactorVec datas;
30
31 using Impl = ProximalRiccatiKernel<Scalar>;
32 using KnotType = LQRKnotTpl<Scalar>;
33
34 using BlkMat = BlkMatrix<MatrixXs, -1, -1>;
35 using BlkVec = BlkMatrix<VectorXs, -1, 1>;
36
37 explicit ParallelRiccatiSolver(LQRProblemTpl<Scalar> &problem,
38 const uint num_threads);
39
40 void allocateLeg(uint start, uint end, bool last_leg);
41
42 static void setupKnot(KnotType &knot, const Scalar mudyn) {
43 ZoneScoped;
45 knot.Gx = knot.A.transpose();
46 knot.Gu = knot.B.transpose();
47 knot.Gth.setZero();
48 knot.Gth.diagonal().setConstant(-mudyn);
49 knot.gamma = knot.f;
50 }
51
52 bool backward(const Scalar mudyn, const Scalar mueq);
53
54 inline void collapseFeedback() {
55 using RowMatrix = Eigen::Matrix<Scalar, -1, -1, Eigen::RowMajor>;
56 StageFactor<Scalar> &d = datas[0];
57 Eigen::Ref<RowMatrix> K = d.fb.blockRow(0);
58 Eigen::Ref<RowMatrix> Kth = d.fth.blockRow(0);
59
60 // condensedSystem.subdiagonal contains the 'U' factors in the
61 // block-tridiag UDUt decomposition
62 // and ∂Xi+1 = -Ui+1.t ∂Xi
63 auto &Up1t = condensedKktSystem.subdiagonal[1];
64 K.noalias() -= Kth * Up1t;
65 }
66
67 struct condensed_system_t {
68 std::vector<MatrixXs> subdiagonal;
69 std::vector<MatrixXs> diagonal;
70 std::vector<MatrixXs> superdiagonal;
71 };
72
73 struct condensed_system_factor {
74 std::vector<MatrixXs> diagonalFacs; //< diagonal factors
75 std::vector<MatrixXs> upFacs; //< transposed U factors
76 std::vector<Eigen::BunchKaufman<MatrixXs>> ldlt;
77 };
78
80 void assembleCondensedSystem(const Scalar mudyn);
81
82 bool forward(VectorOfVectors &xs, VectorOfVectors &us, VectorOfVectors &vs,
83 VectorOfVectors &lbdas,
84 const std::optional<ConstVectorRef> & = std::nullopt) const;
85
86 VectorRef getFeedforward(size_t i) { return datas[i].ff.matrix(); }
87 RowMatrixRef getFeedback(size_t i) { return datas[i].fb.matrix(); }
88
90 uint numThreads;
91
93 condensed_system_t condensedKktSystem;
95 condensed_system_factor condensedFacs;
97 BlkVec condensedKktRhs, condensedKktSolution;
98
100 void initializeTridiagSystem(const std::vector<long> &dims);
101
102protected:
103 LQRProblemTpl<Scalar> *problem_;
104};
105#endif
106
107} // namespace gar
108} // namespace aligator
109
110#include "aligator/gar/parallel-solver.hxx"
111
112#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
113#include "aligator/gar/parallel-solver.txx"
114#endif
#define ALIGATOR_NOMALLOC_SCOPED
#define ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar)
Definition math.hpp:20
Main package namespace.
unsigned int uint
Definition logger.hpp:11