aligator  0.14.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
10
11namespace aligator {
12
19
21template <typename Scalar> struct ConstraintStackTpl {
25
32
33 std::size_t size() const { return funcs.size(); }
34 bool empty() const { return size() == 0; }
35 void clear();
36
37 template <typename Cstr> ALIGATOR_DEPRECATED void pushBack(Cstr &&el) {
38 assert(!el.func.valueless_after_move() &&
39 "constraint must have non-null underlying function.");
40 assert(!el.set.valueless_after_move() &&
41 "constraint must have non-null underlying set.");
42 funcs.emplace_back(el.func);
43 sets.emplace_back(el.set);
44 addDim(el.func->nr);
45 }
46
47 void pushBack(const PolyFunc &func, const PolySet &cstr_set) {
48 assert(!func.valueless_after_move() &&
49 "constraint must have non-null underlying function.");
50 assert(!cstr_set.valueless_after_move() &&
51 "constraint must have non-null underlying set.");
52 funcs.emplace_back(func);
53 sets.emplace_back(cstr_set);
54 addDim(func->nr);
55 }
56
58 const std::vector<long> &dims() const { return dims_; }
59
60 long totalDim() const { return total_dim_; }
61
63 template <typename Derived> Derived *getConstraint(const size_t id) {
64 return dynamic_cast<Derived *>(&*funcs[id]);
65 }
66
68 template <typename Derived>
69 const Derived *getConstraint(const size_t id) const {
70 return dynamic_cast<const Derived *>(&*funcs[id]);
71 }
72
73 std::vector<PolyFunc> funcs;
74 std::vector<PolySet> sets;
75
76protected:
77 std::vector<long> indices_;
78 std::vector<long> dims_;
79 long total_dim_ = 0;
80
81private:
82 void addDim(const long nr) {
83 const long last_cursor = indices_.back();
84 indices_.push_back(last_cursor + nr);
85 dims_.push_back(nr);
86 total_dim_ += nr;
87 }
88};
89
90template <typename Scalar> void ConstraintStackTpl<Scalar>::clear() {
91 funcs.clear();
92 sets.clear();
93 indices_ = {0};
94 dims_.clear();
95 total_dim_ = 0;
96}
97
98} // namespace aligator
99
100#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
101#include "aligator/core/constraint.txx"
102#endif
bool valueless_after_move() const noexcept
Base definitions for ternary functions.
Main package namespace.
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
Simple struct holding together a function and set, to describe a constraint.
xyz::polymorphic< ConstraintSetTpl< Scalar > > set
xyz::polymorphic< StageFunctionTpl< Scalar > > func