aligator  0.14.0
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#include "aligator/tracy.hpp"
9
10namespace aligator {
11namespace gar {
12
13#ifdef ALIGATOR_MULTITHREADING
23template <typename _Scalar>
24class ParallelRiccatiSolver : public RiccatiSolverBase<_Scalar> {
25public:
26 using Scalar = _Scalar;
28 using Base = RiccatiSolverBase<Scalar>;
29 using StageFactorVec = std::vector<StageFactor<Scalar>>;
30 StageFactorVec datas;
31
32 using Kernel = ProximalRiccatiKernel<Scalar>;
33 using KnotType = LqrKnotTpl<Scalar>;
34
35 using BlkMat = BlkMatrix<MatrixXs, -1, -1>;
36 using BlkVec = BlkMatrix<VectorXs, -1, 1>;
37
38 explicit ParallelRiccatiSolver(LqrProblemTpl<Scalar> &problem,
39 const uint num_threads);
40
41 void allocateLeg(uint start, uint end, bool last_leg);
42
43 static void setupKnot(KnotType &knot, const Scalar mudyn) {
44 ALIGATOR_TRACY_ZONE_SCOPED;
46 knot.Gx = knot.A.to_const_map().transpose();
47 knot.Gu = knot.B.to_const_map().transpose();
48 knot.Gth.setZero();
49 knot.Gth.diagonal().setConstant(-mudyn);
50 knot.gamma = knot.f;
51 }
52
53 bool backward(const Scalar mudyn, const Scalar mueq);
54
55 inline void collapseFeedback() {
56 using RowMatrix = Eigen::Matrix<Scalar, -1, -1, Eigen::RowMajor>;
57 StageFactor<Scalar> &d = datas[0];
58 Eigen::Ref<RowMatrix> K = d.fb.blockRow(0);
59 Eigen::Ref<RowMatrix> Kth = d.fth.blockRow(0);
60
61 // condensedSystem.subdiagonal contains the 'U' factors in the
62 // block-tridiag UDUt decomposition
63 // and ∂Xi+1 = -Ui+1.t ∂Xi
64 auto &Up1t = condensedKktSystem.subdiagonal[1];
65 K.noalias() -= Kth * Up1t;
66 }
67
68 struct condensed_system_t {
69 std::vector<MatrixXs> subdiagonal;
70 std::vector<MatrixXs> diagonal;
71 std::vector<MatrixXs> superdiagonal;
72 };
73
74 struct condensed_system_factor {
75 std::vector<MatrixXs> diagonalFacs; //< diagonal factors
76 std::vector<MatrixXs> upFacs; //< transposed U factors
77 std::vector<Eigen::BunchKaufman<MatrixXs>> ldlt;
78 };
79
81 void assembleCondensedSystem(const Scalar mudyn);
82
83 bool forward(VectorOfVectors &xs, VectorOfVectors &us, VectorOfVectors &vs,
84 VectorOfVectors &lbdas,
85 const std::optional<ConstVectorRef> & = std::nullopt) const;
86
87 void cycleAppend(const KnotType &knot);
88 VectorRef getFeedforward(size_t i) { return datas[i].ff.matrix(); }
89 RowMatrixRef getFeedback(size_t i) { return datas[i].fb.matrix(); }
90
92 uint numThreads;
93
95 condensed_system_t condensedKktSystem;
97 condensed_system_factor condensedFacs;
99 BlkVec condensedKktRhs, condensedKktSolution, condensedErr;
100
101 Scalar condensedThreshold{1e-11};
102
104 void initializeTridiagSystem(const std::vector<long> &dims);
105
106protected:
107 LqrProblemTpl<Scalar> *problem_;
108};
109#endif
110
111} // namespace gar
112} // namespace aligator
113
114#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
115#include "aligator/gar/parallel-solver.txx"
116#endif
#define ALIGATOR_NOMALLOC_SCOPED
Definition math.hpp:44
#define ALIGATOR_DYNAMIC_TYPEDEFS_WITH_ROW_TYPES(Scalar)
Definition math.hpp:22
::aligator::context::Scalar Scalar
Definition context.hpp:14
unsigned int uint
Definition work.hpp:8
Main package namespace.