aligator  0.9.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
5#include <proxsuite-nlp/third-party/polymorphic_cxx14.hpp>
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
17 xyz::polymorphic<FunType> func;
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
28 linear_func_composition_impl(xyz::polymorphic<FunType> func,
29 const ConstMatrixRef A, const ConstVectorRef b)
30 : FunType(func->ndx1, func->nu, (int)A.rows()), func(func), A(A), b(b) {
31 // if (func == 0) {
32 // ALIGATOR_RUNTIME_ERROR("Underlying function cannot be nullptr.");
33 // }
34 if (A.rows() != b.rows()) {
35 ALIGATOR_RUNTIME_ERROR("Incompatible dimensions: A.rows() != b.rows()");
36 }
37 if (A.cols() != func->nr) {
38 ALIGATOR_RUNTIME_ERROR("Incompatible dimensions: A.cols() != func.nr");
39 }
40 }
41
42 linear_func_composition_impl(xyz::polymorphic<FunType> func,
43 const ConstMatrixRef A)
44 : linear_func_composition_impl(func, A, VectorXs::Zero(A.rows())) {}
45
46 shared_ptr<BaseData> createData() const {
47 return std::make_shared<Data>(*this);
48 }
49};
50} // namespace detail
51
52template <typename _Scalar>
54 : detail::linear_func_composition_impl<StageFunctionTpl<_Scalar>> {
55 using Scalar = _Scalar;
58 using Base = typename Impl::FunType;
59 using Data = typename Impl::Data;
61
62 using Impl::A;
63 using Impl::b;
64 using Impl::createData;
65 using Impl::func;
66 using Impl::Impl;
67
68 void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
69 BaseData &data) const override;
70
71 void computeJacobians(const ConstVectorRef &x, const ConstVectorRef &u,
72 BaseData &data) const override;
73};
74
75template <typename _Scalar>
77 : detail::linear_func_composition_impl<UnaryFunctionTpl<_Scalar>> {
78 using Scalar = _Scalar;
82 using Data = typename Impl::Data;
84
85 using Impl::A;
86 using Impl::b;
87 using Impl::createData;
88 using Impl::func;
89 using Impl::Impl;
90
91 void evaluate(const ConstVectorRef &x, BaseData &data) const override;
92 void computeJacobians(const ConstVectorRef &x, BaseData &data) const override;
93};
94
96template <typename Scalar>
97auto linear_compose(xyz::polymorphic<StageFunctionTpl<Scalar>> func,
98 const typename math_types<Scalar>::ConstMatrixRef A,
99 const typename math_types<Scalar>::ConstVectorRef b) {
100 return LinearFunctionCompositionTpl<Scalar>(func, A, b);
101}
102
104template <typename Scalar>
105auto linear_compose(xyz::polymorphic<UnaryFunctionTpl<Scalar>> func,
106 const typename math_types<Scalar>::ConstMatrixRef A,
107 const typename math_types<Scalar>::ConstVectorRef b) {
109}
110
111} // namespace aligator
112
113#include "aligator/modelling/linear-function-composition.hxx"
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
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
void computeJacobians(const ConstVectorRef &x, const ConstVectorRef &u, BaseData &data) const override
void evaluate(const ConstVectorRef &x, BaseData &data) const override
void computeJacobians(const ConstVectorRef &x, BaseData &data) const override
Base struct for function data.
Definition fwd.hpp:62
Class representing ternary functions .
Definition fwd.hpp:56
Represents unary functions of the form , with no control (or next-state) arguments.
Definition fwd.hpp:59
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)