aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
linear-function-composition.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace aligator {
8
9namespace detail {
10
11template <typename _FunType> struct linear_func_composition_impl : _FunType {
12 using FunType = _FunType;
13 using Scalar = typename FunType::Scalar;
16
18 MatrixXs A;
19 VectorXs b;
20
21 struct Data : BaseData {
22 shared_ptr<BaseData> sub_data;
24 : BaseData(model.ndx1, model.nu, model.nr)
25 , sub_data(model.func->createData()) {}
26 };
27
29 const ConstMatrixRef A, const ConstVectorRef b)
30 : FunType(func->ndx1, func->nu, (int)A.rows())
31 , func(func)
32 , A(A)
33 , b(b) {
34 // if (func == 0) {
35 // ALIGATOR_RUNTIME_ERROR("Underlying function cannot be nullptr.");
36 // }
37 if (A.rows() != b.rows()) {
38 ALIGATOR_RUNTIME_ERROR("Incompatible dimensions: A.rows() != b.rows()");
39 }
40 if (A.cols() != func->nr) {
41 ALIGATOR_RUNTIME_ERROR("Incompatible dimensions: A.cols() != func.nr");
42 }
43 }
44
46 const ConstMatrixRef A)
47 : linear_func_composition_impl(func, A, VectorXs::Zero(A.rows())) {}
48
49 shared_ptr<BaseData> createData() const {
50 return std::make_shared<Data>(*this);
51 }
52};
53} // namespace detail
54
55template <typename _Scalar>
57 : detail::linear_func_composition_impl<StageFunctionTpl<_Scalar>> {
58 using Scalar = _Scalar;
61 using Base = typename Impl::FunType;
62 using Data = typename Impl::Data;
64
65 using Impl::A;
66 using Impl::b;
67 using Impl::createData;
68 using Impl::func;
69 using Impl::Impl;
70
71 void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
72 BaseData &data) const override;
73
74 void computeJacobians(const ConstVectorRef &x, const ConstVectorRef &u,
75 BaseData &data) const override;
76};
77
78template <typename _Scalar>
80 : detail::linear_func_composition_impl<UnaryFunctionTpl<_Scalar>> {
81 using Scalar = _Scalar;
85 using Data = typename Impl::Data;
87
88 using Impl::A;
89 using Impl::b;
90 using Impl::createData;
91 using Impl::func;
92 using Impl::Impl;
93
94 void evaluate(const ConstVectorRef &x, BaseData &data) const override;
95 void computeJacobians(const ConstVectorRef &x, BaseData &data) const override;
96};
97
99template <typename Scalar>
105
107template <typename Scalar>
113
114#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
115extern template struct LinearFunctionCompositionTpl<context::Scalar>;
116extern template struct LinearUnaryFunctionCompositionTpl<context::Scalar>;
117#endif
118
119} // namespace aligator
Base definitions for ternary functions.
Main package namespace.
auto linear_compose(xyz::polymorphic< StageFunctionTpl< Scalar > > func, const typename math_types< Scalar >::ConstMatrixRef A, const typename math_types< Scalar >::ConstVectorRef b)
Create a linear composition of the input function func.
void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
Evaluate the function.
void computeJacobians(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
Compute Jacobians of this function.
detail::linear_func_composition_impl< StageFunctionTpl< Scalar > > Impl
detail::linear_func_composition_impl< Base > Impl
void evaluate(const ConstVectorRef &x, BaseData &data) const override
void computeJacobians(const ConstVectorRef &x, BaseData &data) const override
Base struct for function data.
Class representing ternary functions .
Represents unary functions of the form , with no control (or next-state) arguments.
linear_func_composition_impl(xyz::polymorphic< FunType > func, const ConstMatrixRef A)
linear_func_composition_impl(xyz::polymorphic< FunType > func, const ConstMatrixRef A, const ConstVectorRef b)
Typedefs for math (Eigen vectors, matrices) depending on scalar type.
Definition math.hpp:100