aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
cost-abstract.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include "aligator/fwd.hpp"
7#include <proxsuite-nlp/manifold-base.hpp>
8#include <proxsuite-nlp/third-party/polymorphic_cxx14.hpp>
9
10namespace aligator {
13template <typename _Scalar> struct CostAbstractTpl {
14 using Scalar = _Scalar;
17 using Manifold = ManifoldAbstractTpl<Scalar>;
18
20 xyz::polymorphic<Manifold> space;
22 int nu;
23
24 int nx() const { return space->nx(); }
25 int ndx() const { return space->ndx(); }
26
27 template <class U>
28 CostAbstractTpl(U &&space, const int nu)
29 : space(std::forward<U>(space)), nu(nu) {}
30
32 virtual void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
33 CostData &data) const;
34
36 virtual void computeGradients(const ConstVectorRef &x,
37 const ConstVectorRef &u, CostData &data) const;
38
40 virtual void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u,
41 CostData &data) const;
42
43 virtual shared_ptr<CostData> createData() const {
44 return std::make_shared<CostData>(ndx(), nu);
45 }
46
47 virtual ~CostAbstractTpl() = default;
48};
49
50template <typename Scalar>
51void CostAbstractTpl<Scalar>::evaluate(const ConstVectorRef &,
52 const ConstVectorRef &,
53 CostData &) const {
54 ALIGATOR_RUNTIME_ERROR("not implemented");
55}
56
57template <typename Scalar>
59 const ConstVectorRef &,
60 CostData &) const {
61 ALIGATOR_RUNTIME_ERROR("not implemented");
62}
63
64template <typename Scalar>
65void CostAbstractTpl<Scalar>::computeHessians(const ConstVectorRef &,
66 const ConstVectorRef &,
67 CostData &) const {
68 ALIGATOR_RUNTIME_ERROR("not implemented");
69}
70
72template <typename _Scalar> struct CostDataAbstractTpl {
73 using Scalar = _Scalar;
75 int ndx_, nu_;
77 VectorXs grad_;
78 MatrixXs hess_;
79
81 VectorRef Lx_;
83 VectorRef Lu_;
85 MatrixRef Lxx_;
87 MatrixRef Lxu_;
89 MatrixRef Lux_;
91 MatrixRef Luu_;
92
93 CostDataAbstractTpl(const int ndx, const int nu)
94 : ndx_(ndx), nu_(nu), value_(0.), grad_(ndx + nu),
95 hess_(ndx + nu, ndx + nu), Lx_(grad_.head(ndx)), Lu_(grad_.tail(nu)),
96 Lxx_(hess_.topLeftCorner(ndx, ndx)),
97 Lxu_(hess_.topRightCorner(ndx, nu)),
98 Lux_(hess_.bottomLeftCorner(nu, ndx)),
99 Luu_(hess_.bottomRightCorner(nu, nu)) {
100 grad_.setZero();
101 hess_.setZero();
102 }
103
105 : CostDataAbstractTpl(cost.ndx(), cost.nu) {}
106
107 virtual ~CostDataAbstractTpl() = default;
108};
109
110} // namespace aligator
111
112#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
113#include "aligator/core/cost-abstract.txx"
114#endif
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Forward declarations.
Main package namespace.
Stage costs for control problems.
Definition fwd.hpp:65
virtual void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
Evaluate the cost function.
virtual ~CostAbstractTpl()=default
int nu
Control dimension.
CostAbstractTpl(U &&space, const int nu)
virtual shared_ptr< CostData > createData() const
virtual void computeGradients(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
Compute the cost gradients .
ManifoldAbstractTpl< Scalar > Manifold
xyz::polymorphic< Manifold > space
State dimension.
virtual void computeHessians(const ConstVectorRef &x, const ConstVectorRef &u, CostData &data) const
Compute the cost Hessians .
Data struct for CostAbstractTpl.
Definition fwd.hpp:68
CostDataAbstractTpl(const CostAbstractTpl< Scalar > &cost)
virtual ~CostDataAbstractTpl()=default
CostDataAbstractTpl(const int ndx, const int nu)