aligator  0.14.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
7
8namespace aligator {
9
10namespace detail {
11
16template <typename _Scalar, unsigned int arg>
18
20template <typename _Scalar>
21struct StateOrControlErrorResidual<_Scalar, 0> : UnaryFunctionTpl<_Scalar> {
22 using Scalar = _Scalar;
29
31 VectorXs target_;
32
34 const ConstVectorRef &target)
35 : Base(xspace->ndx(), nu, xspace->ndx())
36 , space_(xspace)
37 , target_(target) {
38 validate();
39 }
40
41 template <typename U, typename std::enable_if_t<
43 StateOrControlErrorResidual(U &&xspace, const int nu,
44 const ConstVectorRef &target)
45 : Base(xspace.ndx(), nu, xspace.ndx())
46 , space_{std::forward<U>(xspace)}
47 , target_(target) {
48 validate();
49 }
50
51 void evaluate(const ConstVectorRef &x, Data &data) const override {
52 space_->difference(target_, x, data.value_);
53 }
54
55 void computeJacobians(const ConstVectorRef &x, Data &data) const override {
56 space_->Jdifference(target_, x, data.Jx_, 1);
57 }
58
59protected:
60 void validate() const {
61 if (!space_->isNormalized(target_)) {
63 "Target parameter invalid (not a viable element of state manifold.)");
64 }
65 }
66};
67
68template <typename _Scalar, unsigned int arg>
70 static_assert(arg == 1, "arg value must be 1");
71 using Scalar = _Scalar;
77
79 VectorXs target_;
80
83 template <typename U,
84 typename = std::enable_if_t<!is_polymorphic_of_v<Manifold, U>>>
85 StateOrControlErrorResidual(const int ndx, U &&uspace,
86 const ConstVectorRef &target)
87 : Base(ndx, uspace.nx(), uspace.ndx())
88 , space_(std::forward<U>(uspace))
89 , target_(target) {
90 validate();
91 }
92
94 const xyz::polymorphic<Manifold> &uspace,
95 const ConstVectorRef &target)
96 : Base(ndx, uspace->nx(), uspace->ndx())
97 , space_(uspace)
98 , target_(target) {
99 validate();
100 }
101
102 StateOrControlErrorResidual(const int ndx, const int nu)
103 : Base(ndx, nu, nu)
105 , target_(space_->neutral()) {}
106
109 StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
110 : StateOrControlErrorResidual(ndx, (int)target.size()) {
111 target_ = target;
112 }
113
114 void evaluate(const ConstVectorRef &, const ConstVectorRef &u,
115 Data &data) const override {
116 switch (arg) {
117 case 1:
118 space_->difference(target_, u, data.value_);
119 break;
120 default:
121 break;
122 }
123 }
124
125 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u,
126 Data &data) const override {
127 switch (arg) {
128 case 1:
129 space_->Jdifference(target_, u, data.Ju_, 1);
130 break;
131 default:
132 break;
133 }
134 }
135
136protected:
137 void validate() const {
138 if (!space_->isNormalized(target_)) {
140 "Target parameter invalid (not a viable element of state manifold.)");
141 }
142 }
143};
144
145} // namespace detail
146
151template <typename Scalar>
156
157template <typename Scalar>
163
164} // namespace aligator
165
166#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
167#include "aligator/modelling/state-error.txx"
168#endif
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Base definitions for ternary functions.
Main package namespace.
constexpr bool is_polymorphic_of_v
Definition fwd.hpp:68
detail::StateOrControlErrorResidual< Scalar, 1 > Base
Base class for manifolds, to use in cost funcs, solvers...
Base struct for function data.
const int nu
Control dimension.
StageFunctionTpl(const int ndx, const int nu, const int nr)
detail::StateOrControlErrorResidual< Scalar, 0 > Base
Represents unary functions of the form , with no control (or next-state) arguments.
Standard Euclidean vector space.
StateOrControlErrorResidual(const PolyManifold &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
StateOrControlErrorResidual(U &&xspace, const int nu, const ConstVectorRef &target)
VectorSpaceTpl< Scalar, Eigen::Dynamic > VectorSpace
ManifoldAbstractTpl< Scalar > Manifold
VectorSpaceTpl< Scalar, Eigen::Dynamic > VectorSpace
StateOrControlErrorResidual(const int ndx, const xyz::polymorphic< Manifold > &uspace, const ConstVectorRef &target)
StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
Constructor using state space and control space dimensions, the control space is assumed to be Euclid...
StateOrControlErrorResidual(const int ndx, U &&uspace, const ConstVectorRef &target)
Constructor using the state space dimension, control manifold and control target.
void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u, Data &data) const override
Compute Jacobians of this function.
void evaluate(const ConstVectorRef &, const ConstVectorRef &u, Data &data) const override
Evaluate the function.
StateOrControlErrorResidual(const int ndx, const int nu)
StageFunctionDataTpl< Scalar > Data