aligator  0.6.1
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
7namespace aligator {
8
9namespace detail {
10
15template <typename _Scalar, unsigned int arg>
16struct StateOrControlErrorResidual;
17
19template <typename _Scalar>
20struct StateOrControlErrorResidual<_Scalar, 0> : UnaryFunctionTpl<_Scalar> {
21 using Scalar = _Scalar;
24 using Data = StageFunctionDataTpl<Scalar>;
25 using Manifold = ManifoldAbstractTpl<Scalar>;
26 using VectorSpace = proxsuite::nlp::VectorSpaceTpl<Scalar, Eigen::Dynamic>;
27
28 shared_ptr<Manifold> space_;
29 VectorXs target_;
30
31 StateOrControlErrorResidual(const shared_ptr<Manifold> &xspace, const int nu,
32 const ConstVectorRef &target)
33 : Base(xspace->ndx(), nu, xspace->ndx()), space_(xspace),
34 target_(target) {
35 if (!xspace->isNormalized(target)) {
37 "Target parameter invalid (not a viable element of state manifold.)");
38 }
39 }
40
41 void evaluate(const ConstVectorRef &x, Data &data) const override {
42 space_->difference(x, target_, data.value_);
43 }
44
45 void computeJacobians(const ConstVectorRef &x, Data &data) const override {
46 space_->Jdifference(x, target_, data.Jx_, 0);
47 }
48};
49
50template <typename _Scalar, unsigned int arg>
52 static_assert(arg > 0 && arg <= 2, "arg value must be 1 or 2!");
53 using Scalar = _Scalar;
55 using Base = StageFunctionTpl<Scalar>;
56 using Data = StageFunctionDataTpl<Scalar>;
57 using Manifold = ManifoldAbstractTpl<Scalar>;
58 using VectorSpace = proxsuite::nlp::VectorSpaceTpl<Scalar, Eigen::Dynamic>;
59
60 shared_ptr<Manifold> space_;
61 VectorXs target_;
62
65 template <unsigned int N = arg, typename = std::enable_if_t<N == 2>>
66 StateOrControlErrorResidual(const shared_ptr<Manifold> &xspace, const int nu,
67 const ConstVectorRef &target);
68
71 template <unsigned int N = arg, typename = std::enable_if_t<N == 1>>
72 StateOrControlErrorResidual(const int ndx, const shared_ptr<Manifold> &uspace,
73 const ConstVectorRef &target)
74 : Base(ndx, uspace->nx(), uspace->ndx()), space_(uspace),
75 target_(target) {
76 check_target_viable();
77 }
78
81 template <unsigned int N = arg, typename = std::enable_if_t<N == 1>>
82 StateOrControlErrorResidual(const int ndx, const ConstVectorRef &target)
84 ndx, std::make_shared<VectorSpace>(target.size()), 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, ndx, nu), space_(std::make_shared<VectorSpace>(nu)),
89 target_(space_->neutral()) {
90 check_target_viable();
91 }
92
93 void evaluate(const ConstVectorRef &, const ConstVectorRef &u,
94 const ConstVectorRef &y, Data &data) const {
95 switch (arg) {
96 case 1:
97 space_->difference(target_, u, data.value_);
98 break;
99 case 2:
100 space_->difference(target_, y, data.value_);
101 break;
102 default:
103 break;
104 }
105 }
106
107 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u,
108 const ConstVectorRef &y, Data &data) const {
109 switch (arg) {
110 case 1:
111 space_->Jdifference(target_, u, data.Ju_, 1);
112 break;
113 case 2:
114 space_->Jdifference(target_, y, data.Jy_, 1);
115 break;
116 default:
117 break;
118 }
119 }
120
121private:
122 inline void check_target_viable() const {
123 if (!space_->isNormalized(target_)) {
125 "Target parameter invalid (not a viable element of state manifold.)");
126 }
127 }
128};
129
130template <typename Scalar, unsigned int arg>
131template <unsigned int N, typename>
133 const shared_ptr<Manifold> &xspace, const int nu,
134 const ConstVectorRef &target)
135 : Base(xspace->ndx(), nu, xspace->ndx()), space_(xspace), target_(target) {
136 check_target_viable();
137}
138} // namespace detail
139
140template <typename Scalar>
145
146template <typename Scalar>
152
153} // namespace aligator
154
155#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
156#include "aligator/modelling/state-error.txx"
157#endif
#define ALIGATOR_RUNTIME_ERROR(msg)
Definition exceptions.hpp:6
Base definitions for ternary functions.
Main package namespace.
const int nu
Control dimension.
Represents unary functions of the form , with no control (or next-state) arguments.
void computeJacobians(const ConstVectorRef &x, Data &data) const override
StateOrControlErrorResidual(const shared_ptr< Manifold > &xspace, const int nu, const ConstVectorRef &target)
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)
void computeJacobians(const ConstVectorRef &, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Compute Jacobians of this function.
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 shared_ptr< Manifold > &xspace, const int nu, const ConstVectorRef &target)
Constructor using the state space, control dimension and state target.
proxsuite::nlp::VectorSpaceTpl< Scalar, Eigen::Dynamic > VectorSpace
StateOrControlErrorResidual(const int ndx, const shared_ptr< Manifold > &uspace, const ConstVectorRef &target)
Constructor using the state space dimension, control manifold and control target.
void evaluate(const ConstVectorRef &, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Evaluate the function.