aligator  0.16.0
A versatile and efficient C++ library for real-time constrained 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
10#ifdef ALIGATOR_MULTITHREADING
11namespace aligator {
12namespace gar {
13
25template <typename _Scalar>
27public:
28 using Scalar = _Scalar;
33 using BlkView = BlkMatrix<VectorRef, -1, 1>;
35
37 const uint num_threads);
38
39 bool backward(const Scalar mueq) override;
40
41 inline void collapseFeedback() override {
43 RowMatrixRef K = d.fb.blockRow(0);
44 RowMatrixRef Kth = d.fth.blockRow(0);
45
46 // condensedSystem.subdiagonal contains the 'U' factors in the
47 // block-tridiag UDUt decomposition
48 // and ∂Xi+1 = -Ui+1.t ∂Xi
49 auto &Up1t = condensedKktSystem.subdiagonal[1];
50 K.noalias() -= Kth * Up1t;
51 }
52
53 struct CondensedKkt {
55 std::pmr::vector<ArMat> subdiagonal;
56 std::pmr::vector<ArMat> diagonal;
57 std::pmr::vector<ArMat> superdiagonal;
58 // factors
59 std::pmr::vector<ArMat> diagonalFacs; //< diagonal factors
60 std::pmr::vector<ArMat> upFacs; //< transposed U factors
61 std::pmr::vector<BunchKaufman<ArMat>> ldlt;
62 explicit CondensedKkt(const allocator_type &alloc)
63 : subdiagonal{alloc}
64 , diagonal{alloc}
65 , superdiagonal{alloc}
66 , diagonalFacs{alloc}
67 , upFacs{alloc}
68 , ldlt{alloc} {}
69 };
70
73
74 bool
75 forward(VectorOfVectors &xs, VectorOfVectors &us, VectorOfVectors &vs,
76 VectorOfVectors &lbdas,
77 const std::optional<ConstVectorRef> & = std::nullopt) const override;
78
79 void cycleAppend(const KnotType &knot) override;
80 VectorRef getFeedforward(size_t i) override { return datas[i].ff.matrix(); }
81 RowMatrixRef getFeedback(size_t i) override { return datas[i].fb.matrix(); }
82
83 allocator_type get_allocator() const { return problem_->get_allocator(); }
84
85 std::pmr::vector<StageFactor<Scalar>> datas;
86
95
97 uint getNumThreads() const noexcept { return numThreads; }
98
101
102protected:
105 std::vector<long> rhsDims_;
106
108};
109
110template <typename Scalar>
113
114#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
115extern template class ParallelRiccatiSolver<context::Scalar>;
116#endif
117} // namespace gar
118} // namespace aligator
119#endif
Block matrix class, with a fixed or dynamic-size number of row and column blocks.
auto blockRow(size_t i)
A parallel-condensing LQ solver.
Scalar condensedThreshold
Tolerance on condensed KKT system.
ParallelRiccatiSolver(LqrProblemTpl< Scalar > &problem, const uint num_threads)
ProximalRiccatiKernel< Scalar > Kernel
uint getNumThreads() const noexcept
Number of parallel divisions in the problem: in the math.
BlkMatrix< VectorRef, -1, 1 > BlkView
bool backward(const Scalar mueq) override
VectorRef getFeedforward(size_t i) override
uint maxRefinementSteps
Max number of refinement steps (condensed solver)
void initializeTridiagSystem()
Initialize the buffers for the block-tridiagonal system.
void assembleCondensedSystem(const Scalar mudyn)
Create the sparse representation of the reduced KKT system.
RowMatrixRef getFeedback(size_t i) override
ArenaMatrix< VectorXs > condensedKktRhs
Contains the right-hand side and solution of the condensed KKT system.
CondensedKkt condensedKktSystem
Block-sparse condensed KKT system.
::aligator::polymorphic_allocator allocator_type
std::pmr::vector< StageFactor< Scalar > > datas
ArenaMatrix< VectorXs > condensedKktSolution
void cycleAppend(const KnotType &knot) override
Cycle the solver data, given the specs from a given new knot.
RiccatiSolverBase< Scalar > Base
bool forward(VectorOfVectors &xs, VectorOfVectors &us, VectorOfVectors &vs, VectorOfVectors &lbdas, const std::optional< ConstVectorRef > &=std::nullopt) const override
A convenience subclass of std::pmr::polymorphic_allocator for bytes.
Definition allocator.hpp:16
ParallelRiccatiSolver(LqrProblemTpl< Scalar > &, const uint) -> ParallelRiccatiSolver< Scalar >
Main package namespace.
unsigned int uint
Definition logger.hpp:10
Struct describing a stage of a constrained LQ problem.
std::pmr::vector< BunchKaufman< ArMat > > ldlt
Kernel for use in Riccati-like algorithms for the proximal LQ subproblem.
Per-node struct for all computations in the factorization.
BlkMatrix< RowMatrixXs, 3, 1 > fb
BlkMatrix< RowMatrixXs, 3, 1 > fth