aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
stage-model.hpp
Go to the documentation of this file.
1
3#pragma once
4
8
10
11namespace aligator {
12
20template <typename _Scalar>
21struct StageModelTpl : Cloneable<StageModelTpl<_Scalar>> {
22public:
23 using Scalar = _Scalar;
25
26 using Manifold = ManifoldAbstractTpl<Scalar>;
27 using ManifoldPtr = shared_ptr<Manifold>;
28 using Dynamics = DynamicsModelTpl<Scalar>;
29 using DynamicsPtr = shared_ptr<Dynamics>;
30 using FunctionPtr = shared_ptr<StageFunctionTpl<Scalar>>;
31 using ConstraintSetPtr = shared_ptr<ConstraintSetBase<Scalar>>;
32 using Constraint = StageConstraintTpl<Scalar>;
33 using Cost = CostAbstractTpl<Scalar>;
34 using CostPtr = shared_ptr<Cost>;
35 using Data = StageDataTpl<Scalar>;
36
44 ConstraintStackTpl<Scalar> constraints_;
49
53 virtual ~StageModelTpl() = default;
54
55 const Manifold &xspace() const { return *xspace_; }
56 const Manifold &uspace() const { return *uspace_; }
57 const Manifold &xspace_next() const { return *xspace_next_; }
58
59 const Cost &cost() const { return *cost_; }
63 virtual bool has_dyn_model() const { return true; }
64 ALIGATOR_DEPRECATED virtual const Dynamics &dyn_model() const {
65 return *dynamics_;
66 }
67
68 int nx1() const { return xspace_->nx(); }
69 int ndx1() const { return xspace_->ndx(); }
70 int nu() const { return uspace_->ndx(); }
71 int nx2() const { return xspace_next_->nx(); }
72 int ndx2() const { return xspace_next_->ndx(); }
74 int nc() const { return (int)constraints_.totalDim(); }
75
77 std::size_t numConstraints() const { return constraints_.size(); }
78
80 int numPrimal() const { return nu() + ndx2(); }
82 int numDual() const { return ndx2() + nc(); }
83
85 template <typename T> void addConstraint(T &&cstr);
86
90
91 /* Evaluate costs, constraints, ... */
92
95 virtual void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
96 const ConstVectorRef &y, Data &data) const;
97
99 virtual void computeFirstOrderDerivatives(const ConstVectorRef &x,
100 const ConstVectorRef &u,
101 const ConstVectorRef &y,
102 Data &data) const;
103
105 virtual void computeSecondOrderDerivatives(const ConstVectorRef &x,
106 const ConstVectorRef &u,
107 Data &data) const;
108
110 virtual shared_ptr<Data> createData() const;
111
112 friend std::ostream &operator<<(std::ostream &oss,
113 const StageModelTpl &stage) {
114 oss << "StageModel { ";
115 if (stage.ndx1() == stage.ndx2()) {
116 oss << "ndx: " << stage.ndx1() << ", "
117 << "nu: " << stage.nu();
118 } else {
119 oss << "ndx1:" << stage.ndx1() << ", "
120 << "nu: " << stage.nu() << ", "
121 << "ndx2:" << stage.ndx2();
122 }
123
124 if (stage.numConstraints() > 0) {
125 oss << ", ";
126 oss << "nc: " << stage.numConstraints();
127 }
128
129 oss << " }";
130 return oss;
131 }
132
133protected:
134 StageModelTpl(ManifoldPtr space, const int nu);
135 virtual StageModelTpl *clone_impl() const override {
136 return new StageModelTpl(*this);
137 }
138};
139
140} // namespace aligator
141
142template <typename Scalar>
143struct fmt::formatter<aligator::StageModelTpl<Scalar>>
144 : fmt::ostream_formatter {};
145
146#include "aligator/core/stage-model.hxx"
147
148#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
149#include "aligator/core/stage-model.txx"
150#endif
Defines the constraint object and constraint stack manager for this library.
Base definitions for ternary functions.
Main package namespace.
Mixin which makes a class/class hierarchy cloneable.
Definition clone.hpp:12
A stage in the control problem.
shared_ptr< Cost > CostPtr
virtual ~StageModelTpl()=default
friend std::ostream & operator<<(std::ostream &oss, const StageModelTpl &stage)
virtual void computeFirstOrderDerivatives(const ConstVectorRef &x, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Compute the first-order derivatives of the StageModelTpl.
virtual void computeSecondOrderDerivatives(const ConstVectorRef &x, const ConstVectorRef &u, Data &data) const
Compute the second-order derivatives of the StageModelTpl.
const Manifold & xspace_next() const
StageModelTpl(CostPtr cost, DynamicsPtr dynamics)
shared_ptr< ConstraintSetBase< Scalar > > ConstraintSetPtr
CostPtr cost_
Stage cost function.
ManifoldAbstractTpl< Scalar > Manifold
ManifoldPtr xspace_
State space for the current state .
shared_ptr< Dynamics > DynamicsPtr
ManifoldPtr xspace_next_
State space for the next state .
ConstraintStackTpl< Scalar > constraints_
Constraint manager.
virtual StageModelTpl * clone_impl() const override
virtual bool has_dyn_model() const
DynamicsPtr dynamics_
Dynamics model.
StageModelTpl(ManifoldPtr space, const int nu)
const Cost & cost() const
DynamicsModelTpl< Scalar > Dynamics
void addConstraint(T &&cstr)
Add a constraint to the stage.
virtual shared_ptr< Data > createData() const
Create a StageData object.
virtual ALIGATOR_DEPRECATED const Dynamics & dyn_model() const
const Manifold & uspace() const
shared_ptr< Manifold > ManifoldPtr
int numDual() const
Number of dual variables, i.e. Lagrange multipliers.
shared_ptr< StageFunctionTpl< Scalar > > FunctionPtr
void addConstraint(FunctionPtr func, ConstraintSetPtr cstr_set)
Add a constraint to the stage.
StageConstraintTpl< Scalar > Constraint
std::size_t numConstraints() const
Number of constraint objects.
int numPrimal() const
Number of primal optimization variables.
const Manifold & xspace() const
ManifoldPtr uspace_
Control vector space – by default, a simple Euclidean space.
virtual void evaluate(const ConstVectorRef &x, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Evaluate all the functions (cost, dynamics, constraints) at this node.
int nc() const
Total number of constraints.