aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
state-error.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <proxsuite-nlp/modelling/spaces/vector-space.hpp>
6#include <proxsuite-nlp/third-party/polymorphic_cxx14.hpp>
7
8namespace aligator {
9
10namespace detail {
11
16template <typename _Scalar, unsigned int arg>
17struct StateOrControlErrorResidual;
18
20template <typename _Scalar>
21struct StateOrControlErrorResidual<_Scalar, 0> : UnaryFunctionTpl<_Scalar> {
22 using Scalar = _Scalar;
26 using Manifold = ManifoldAbstractTpl<Scalar>;
27 using VectorSpace = proxsuite::nlp::VectorSpaceTpl<Scalar, Eigen::Dynamic>;
28
29 xyz::polymorphic<Manifold> space_;
30 VectorXs target_;
31
32 StateOrControlErrorResidual(const xyz::polymorphic<Manifold> &xspace,
33 const int nu, const ConstVectorRef &target)
34 : Base(xspace->ndx(), nu, xspace->ndx()), space_(xspace),
35 target_(target) {
36 if (!xspace->isNormalized(target)) {
38 "Target parameter invalid (not a viable element of state manifold.)");
39 }
40 }
41
42 void evaluate(const ConstVectorRef &x, Data &data) const override {
43 space_->difference(x, target_, data.value_);
44 }
45
46 void computeJacobians(const ConstVectorRef &x, Data &data) const override {
47 space_->Jdifference(x, target_, data.Jx_, 0);
48 }
49};
50
51template <typename _Scalar, unsigned int arg>
53 static_assert(arg == 1, "arg value must be 1");
54 using Scalar = _Scalar;
58 using Manifold = ManifoldAbstractTpl<Scalar>;
59 using VectorSpace = proxsuite::nlp::VectorSpaceTpl<Scalar, Eigen::Dynamic>;
60
61 xyz::polymorphic<Manifold> space_;
62 VectorXs target_;
63
66 template <unsigned int N = arg, typename = std::enable_if_t<N == 1>>
68 const xyz::polymorphic<Manifold> &uspace,
69 const ConstVectorRef &target)
70 : Base(ndx, uspace->nx(), uspace->ndx()), space_(uspace),
71 target_(target) {
72 check_target_viable();
73 }
74
77 auto get_polymorphic(const int &size) const {
78 VectorSpace vs = VectorSpace(size);
79 return xyz::polymorphic<Manifold>(VectorSpace(size));
80 }
81 template <unsigned int N = arg, typename = std::enable_if_t<N == 1>>
82 StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
83 : StateOrControlErrorResidual(ndx, get_polymorphic((int)target.size()),
84 target) {}
85
86 template <unsigned int N = arg, typename = std::enable_if_t<N == 1>>
87 StateOrControlErrorResidual(const int ndx, const int nu)
88 : Base(ndx, nu, nu), space_(VectorSpace(nu)), target_(space_->neutral()) {
89 check_target_viable();
90 }
91
92 void evaluate(const ConstVectorRef &, const ConstVectorRef &u,
93 Data &data) const override {
94 switch (arg) {
95 case 1:
96 space_->difference(target_, u, data.value_);
97 break;
98 default:
99 break;
100 }
101 }
102
103 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u,
104 Data &data) const override {
105 switch (arg) {
106 case 1:
107 space_->Jdifference(target_, u, data.Ju_, 1);
108 break;
109 default:
110 break;
111 }
112 }
113
114private:
115 inline void check_target_viable() const {
116 if (!space_->isNormalized(target_)) {
118 "Target parameter invalid (not a viable element of state manifold.)");
119 }
120 }
121};
122
123} // namespace detail
124
125template <typename Scalar>
130
131template <typename Scalar>
137
138} // namespace aligator
139
140#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
141#include "aligator/modelling/state-error.txx"
142#endif
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Base definitions for ternary functions.
Main package namespace.
Base struct for function data.
Definition fwd.hpp:59
Represents unary functions of the form , with no control (or next-state) arguments.
Definition fwd.hpp:56
StateOrControlErrorResidual(const xyz::polymorphic< Manifold > &xspace, const int nu, const ConstVectorRef &target)
void computeJacobians(const ConstVectorRef &x, Data &data) const override
void evaluate(const ConstVectorRef &x, Data &data) const override
proxsuite::nlp::VectorSpaceTpl< Scalar, Eigen::Dynamic > VectorSpace
ManifoldAbstractTpl< Scalar > Manifold
StateOrControlErrorResidual(const int ndx, const int nu)
StateOrControlErrorResidual(const int ndx, const xyz::polymorphic< Manifold > &uspace, const ConstVectorRef &target)
Constructor using the state space dimension, control manifold and control target.
StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
proxsuite::nlp::VectorSpaceTpl< Scalar, Eigen::Dynamic > VectorSpace
void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u, Data &data) const override
void evaluate(const ConstVectorRef &, const ConstVectorRef &u, Data &data) const override
auto get_polymorphic(const int &size) const
Constructor using state space and control space dimensions, the control space is assumed to be Euclid...