aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
 
Loading...
Searching...
No Matches
cartesian-product.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <type_traits>
7
8namespace aligator {
9
12template <typename _Scalar>
14public:
15 using Scalar = _Scalar;
16
19
20 const Base &getComponent(std::size_t i) const { return *m_components[i]; }
21
22 inline std::size_t numComponents() const { return m_components.size(); }
23
24 template <class Concrete> inline void addComponent(const Concrete &c) {
25 static_assert(
26 std::is_base_of_v<Base, Concrete> ||
27 std::is_same_v<Concrete, xyz::polymorphic<Base>>,
28 "Input type should either be derived from ManifoldAbstractTpl or be "
29 "polymorphic<ManifoldAbstractTpl>.");
30 m_components.emplace_back(c);
31 }
32
33 inline void addComponent(const CartesianProductTpl &other) {
34 for (const auto &c : other.m_components) {
35 this->addComponent(c);
36 }
37 }
38
39 explicit CartesianProductTpl() = default;
44
45 CartesianProductTpl(const std::vector<xyz::polymorphic<Base>> &components)
46 : m_components(components) {}
47
49 : m_components(std::move(components)) {}
50
51 CartesianProductTpl(std::initializer_list<xyz::polymorphic<Base>> components)
52 : m_components(components) {}
53
55 const xyz::polymorphic<Base> &right)
56 : m_components{left, right} {}
57
58 inline int nx() const {
59 int r = 0;
60 for (std::size_t i = 0; i < numComponents(); i++) {
61 r += m_components[i]->nx();
62 }
63 return r;
64 }
65
66 inline int ndx() const {
67 int r = 0;
68 for (std::size_t i = 0; i < numComponents(); i++) {
69 r += m_components[i]->ndx();
70 }
71 return r;
72 }
73
74 void neutral_impl(VectorRef out) const;
75 void rand_impl(VectorRef out) const;
76 bool isNormalized(const ConstVectorRef &x) const;
77
78 template <class VectorType, class U = std::remove_const_t<VectorType>>
79 std::vector<U> split_impl(VectorType &x) const;
80
81 template <class VectorType, class U = std::remove_const_t<VectorType>>
82 std::vector<U> split_vector_impl(VectorType &v) const;
83
84 std::vector<VectorRef> split(VectorRef x) const {
85 return split_impl<VectorRef>(x);
86 }
87
88 std::vector<ConstVectorRef> split(const ConstVectorRef &x) const {
90 }
91
92 std::vector<VectorRef> split_vector(VectorRef v) const {
94 }
95
96 std::vector<ConstVectorRef> split_vector(const ConstVectorRef &v) const {
98 }
99
100 VectorXs merge(const std::vector<VectorXs> &xs) const;
101
102 VectorXs merge_vector(const std::vector<VectorXs> &vs) const;
103
104protected:
105 std::vector<xyz::polymorphic<Base>> m_components;
106
107 void integrate_impl(const ConstVectorRef &x, const ConstVectorRef &v,
108 VectorRef out) const;
109
110 void difference_impl(const ConstVectorRef &x0, const ConstVectorRef &x1,
111 VectorRef out) const;
112
113 void Jintegrate_impl(const ConstVectorRef &x, const ConstVectorRef &v,
114 MatrixRef Jout, int arg) const;
115
116 void JintegrateTransport_impl(const ConstVectorRef &x,
117 const ConstVectorRef &v, MatrixRef Jout,
118 int arg) const;
119
120 void Jdifference_impl(const ConstVectorRef &x0, const ConstVectorRef &x1,
121 MatrixRef Jout, int arg) const;
122};
123
124template <typename T>
127 return CartesianProductTpl<T>(left, right);
128}
129
130template <typename T>
133 CartesianProductTpl<T> out(left);
134 out.addComponent(right);
135 return out;
136}
137
138template <typename T>
140 const CartesianProductTpl<T> &right) {
141 return right * left;
142}
143
144template <typename T>
146 const CartesianProductTpl<T> &right) {
147 CartesianProductTpl<T> out{left};
148 out.addComponent(right);
149 return out;
150}
151
152} // namespace aligator
153
154// implementation details
155#include "aligator/modelling/spaces/cartesian-product.hxx"
Main package namespace.
xyz::polymorphic< CostStackTpl< T > > operator*(T u, xyz::polymorphic< CostStackTpl< T > > &&c1)
The cartesian product of two or more manifolds.
int ndx() const
Get manifold tangent space dimension.
CartesianProductTpl(const std::vector< xyz::polymorphic< Base > > &components)
CartesianProductTpl(const CartesianProductTpl &)=default
int nx() const
Get manifold representation dimension.
void Jintegrate_impl(const ConstVectorRef &x, const ConstVectorRef &v, MatrixRef Jout, int arg) const
const Base & getComponent(std::size_t i) const
std::vector< U > split_impl(VectorType &x) const
std::vector< VectorRef > split_vector(VectorRef v) const
std::vector< VectorRef > split(VectorRef x) const
void neutral_impl(VectorRef out) const
void rand_impl(VectorRef out) const
CartesianProductTpl(std::vector< xyz::polymorphic< Base > > &&components)
CartesianProductTpl & operator=(CartesianProductTpl &&)=default
VectorXs merge(const std::vector< VectorXs > &xs) const
bool isNormalized(const ConstVectorRef &x) const
Check if the input vector x is a viable element of the manifold.
void difference_impl(const ConstVectorRef &x0, const ConstVectorRef &x1, VectorRef out) const
Implementation of the manifold retraction operation.
VectorXs merge_vector(const std::vector< VectorXs > &vs) const
std::vector< ConstVectorRef > split(const ConstVectorRef &x) const
CartesianProductTpl & operator=(const CartesianProductTpl &)=default
void integrate_impl(const ConstVectorRef &x, const ConstVectorRef &v, VectorRef out) const
Perform the manifold integration operation.
void Jdifference_impl(const ConstVectorRef &x0, const ConstVectorRef &x1, MatrixRef Jout, int arg) const
void JintegrateTransport_impl(const ConstVectorRef &x, const ConstVectorRef &v, MatrixRef Jout, int arg) const
CartesianProductTpl(const xyz::polymorphic< Base > &left, const xyz::polymorphic< Base > &right)
CartesianProductTpl(std::initializer_list< xyz::polymorphic< Base > > components)
void addComponent(const Concrete &c)
std::vector< ConstVectorRef > split_vector(const ConstVectorRef &v) const
void addComponent(const CartesianProductTpl &other)
CartesianProductTpl(CartesianProductTpl &&)=default
std::vector< U > split_vector_impl(VectorType &v) const
std::vector< xyz::polymorphic< Base > > m_components
Base class for manifolds, to use in cost funcs, solvers...