9#include <fmt/ostream.h>
13#define ALIGATOR_CHECK_DERIVED_CLASS(Base, Derived) \
14 static_assert((std::is_base_of_v<Base, Derived>), \
15 "Failed check for derived class.")
24template <
typename _Scalar>
struct StageModelTpl {
37#pragma GCC diagnostic push
38#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
40#pragma GCC diagnostic pop
59 return dynamic_cast<U *
>(&*
cost_);
63 template <
typename U>
const U *
getCost()
const {
65 return dynamic_cast<const U *
>(&*
cost_);
77 return dynamic_cast<const U *
>(&*
dynamics_);
112 template <
typename Cstr,
typename = std::enable_if_t<std::is_same_v<
113 std::decay_t<Cstr>, StageConstraint>>>
125 virtual void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
126 const ConstVectorRef &y,
Data &data)
const;
130 const ConstVectorRef &u,
131 const ConstVectorRef &y,
136 const ConstVectorRef &u,
144 oss <<
"StageModel { ";
145 if (stage.ndx1() == stage.ndx2()) {
146 oss <<
"ndx: " << stage.ndx1() <<
", "
147 <<
"nu: " << stage.nu();
149 oss <<
"ndx1:" << stage.ndx1() <<
", "
150 <<
"nu: " << stage.nu() <<
", "
151 <<
"ndx2:" << stage.ndx2();
154 if (stage.numConstraints() > 0) {
156 oss <<
"nc: " << stage.numConstraints();
164template <
typename Scalar>
165template <
typename Cstr,
typename>
167 const int c_nu = cstr.func->nu;
168 if (c_nu != this->nu()) {
170 "Function has the wrong dimension for u: got {:d}, expected {:d}", c_nu,
173 constraints_.pushBack(std::forward<Cstr>(cstr));
178template <
typename Scalar>
179struct fmt::formatter<
aligator::StageModelTpl<Scalar>>
180 : fmt::ostream_formatter {};
182#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
183#include "aligator/core/stage-model.txx"
Defines the constraint object and constraint stack manager for this library.
#define ALIGATOR_RUNTIME_ERROR(...)
Base definitions for ternary functions.
#define ALIGATOR_CHECK_DERIVED_CLASS(Base, Derived)
Convenience class to manage a stack of constraints.
Stage costs for control problems.
Dynamics model: describes system dynamics through an implicit relation .
Simple struct holding together a function and set, to describe a constraint.
Data struct for stage models StageModelTpl.
A stage in the control problem.
PolyDynamics dynamics_
Dynamics model.
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.
ConstraintStackTpl< Scalar > constraints_
Constraint manager.
friend std::ostream & operator<<(std::ostream &oss, const StageModelTpl &stage)
U * getCost()
Get a pointer to an expected concrete type for the cost function.
ManifoldAbstractTpl< Scalar > Manifold
const U * getDynamics() const
const Manifold & xspace_next() const
virtual bool hasDynModel() const
xyz::polymorphic< Manifold > PolyManifold
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
PolyCost cost_
Stage cost function.
const Cost & cost() const
void addConstraint(const PolyFunction &func, const PolyConstraintSet &cstr_set)
Add a constraint to the stage.
int numDual() const
Number of dual variables, i.e. Lagrange multipliers.
const U * getCost() const
virtual void computeSecondOrderDerivatives(const ConstVectorRef &x, const ConstVectorRef &u, Data &data) const
Compute the second-order derivatives of the StageModelTpl.
const Manifold & uspace() const
int nc() const
Total number of constraints.
ALIGATOR_DEPRECATED void addConstraint(Cstr &&cstr)
Add a constraint to the stage.
xyz::polymorphic< ConstraintSetTpl< Scalar > > PolyConstraintSet
virtual shared_ptr< Data > createData() const
Create a StageData object.
virtual ~StageModelTpl()=default
StageModelTpl(const PolyCost &cost, const PolyDynamics &dynamics)
virtual void computeFirstOrderDerivatives(const ConstVectorRef &x, const ConstVectorRef &u, const ConstVectorRef &y, Data &data) const
Compute the first-order derivatives of the StageModelTpl.
const Manifold & xspace() const
xyz::polymorphic< StageFunctionTpl< Scalar > > PolyFunction
std::size_t numConstraints() const
Number of constraint objects.
PolyManifold xspace_next_
State space for the next state .
U * getDynamics()
Get a pointer to an expected concrete type for the dynamics class.
int numPrimal() const
Number of primal optimization variables.
xyz::polymorphic< Dynamics > PolyDynamics
PolyManifold uspace_
Control vector space – by default, a simple Euclidean space.
PolyManifold xspace_
State space for the current state .
xyz::polymorphic< Cost > PolyCost