aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
constraint.hpp
Go to the documentation of this file.
1
5#pragma once
6
8
9#include <proxsuite-nlp/third-party/polymorphic_cxx14.hpp>
10
11namespace aligator {
12
15template <typename Scalar> struct ALIGATOR_DEPRECATED StageConstraintTpl {
16 xyz::polymorphic<StageFunctionTpl<Scalar>> func;
17 xyz::polymorphic<ConstraintSetTpl<Scalar>> set;
18};
19
21template <typename Scalar> struct ConstraintStackTpl {
23 using PolyFunc = xyz::polymorphic<StageFunctionTpl<Scalar>>;
24 using PolySet = xyz::polymorphic<ConstraintSetTpl<Scalar>>;
25
31
32 std::size_t size() const { return funcs.size(); }
33 bool empty() const { return size() == 0; }
34 void clear();
35
36 template <typename Cstr> ALIGATOR_DEPRECATED void pushBack(Cstr &&el) {
37 assert(!el.func.valueless_after_move() &&
38 "constraint must have non-null underlying function.");
39 assert(!el.set.valueless_after_move() &&
40 "constraint must have non-null underlying set.");
41 funcs.emplace_back(el.func);
42 sets.emplace_back(el.set);
43 addDim(el.func->nr);
44 }
45
46 void pushBack(const PolyFunc &func, const PolySet &cstr_set) {
47 assert(!func.valueless_after_move() &&
48 "constraint must have non-null underlying function.");
49 assert(!cstr_set.valueless_after_move() &&
50 "constraint must have non-null underlying set.");
51 funcs.emplace_back(func);
52 sets.emplace_back(cstr_set);
53 addDim(func->nr);
54 }
55
57 const std::vector<long> &dims() const { return dims_; }
58
59 long totalDim() const { return total_dim_; }
60
62 template <typename Derived> Derived *getConstraint(const size_t id) {
63 return dynamic_cast<Derived *>(&*funcs[id]);
64 }
65
67 template <typename Derived>
68 const Derived *getConstraint(const size_t id) const {
69 return dynamic_cast<const Derived *>(&*funcs[id]);
70 }
71
72 std::vector<PolyFunc> funcs;
73 std::vector<PolySet> sets;
74
75protected:
76 std::vector<long> indices_;
77 std::vector<long> dims_;
78 long total_dim_ = 0;
79
80private:
81 void addDim(const long nr) {
82 const long last_cursor = indices_.back();
83 indices_.push_back(last_cursor + nr);
84 dims_.push_back(nr);
85 total_dim_ += nr;
86 }
87};
88
89} // namespace aligator
90
91#include "aligator/core/constraint.hxx"
92
93#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
94#include "aligator/core/constraint.txx"
95#endif
Base definitions for ternary functions.
StageConstraintTpl< Scalar > ALIGATOR_DEPRECATED
Definition context.hpp:19
Main package namespace.
Convenience class to manage a stack of constraints.
Definition fwd.hpp:101
const std::vector< long > & dims() const
Get the set of dimensions for each constraint in the stack.
xyz::polymorphic< StageFunctionTpl< Scalar > > PolyFunc
ConstraintStackTpl & operator=(const ConstraintStackTpl &)=default
ConstraintStackTpl & operator=(ConstraintStackTpl &&)=default
std::vector< PolyFunc > funcs
std::size_t size() const
std::vector< PolySet > sets
std::vector< long > indices_
ALIGATOR_DEPRECATED void pushBack(Cstr &&el)
void pushBack(const PolyFunc &func, const PolySet &cstr_set)
ConstraintStackTpl(ConstraintStackTpl &&)=default
const Derived * getConstraint(const size_t id) const
Get constraint function, cast down to the specified type.
std::vector< long > dims_
ConstraintStackTpl(const ConstraintStackTpl &)=default
Derived * getConstraint(const size_t id)
Get constraint function, cast down to the specified type.
xyz::polymorphic< ConstraintSetTpl< Scalar > > PolySet
xyz::polymorphic< ConstraintSetTpl< Scalar > > set
xyz::polymorphic< StageFunctionTpl< Scalar > > func