aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
constraint.hpp
Go to the documentation of this file.
1
5
#pragma once
6
7
#include "
aligator/core/function-abstract.hpp
"
8
9
#include "
aligator/third-party/polymorphic_cxx14.h
"
10
11
namespace
aligator
{
12
14
template
<
typename
Scalar>
struct
ConstraintStackTpl
{
15
ALIGATOR_DYNAMIC_TYPEDEFS
(Scalar);
16
using
PolyFunc
= xyz::polymorphic<StageFunctionTpl<Scalar>>;
17
using
PolySet
= xyz::polymorphic<ConstraintSetTpl<Scalar>>;
18
19
ConstraintStackTpl
()
20
:
indices_
({0}) {};
21
ConstraintStackTpl
(
const
ConstraintStackTpl
&) =
default
;
22
ConstraintStackTpl
&
operator=
(
const
ConstraintStackTpl
&) =
default
;
23
ConstraintStackTpl
(
ConstraintStackTpl
&&) =
default
;
24
ConstraintStackTpl
&
operator=
(
ConstraintStackTpl
&&) =
default
;
25
26
std::size_t
size
()
const
{
return
funcs
.size(); }
27
bool
empty
()
const
{
return
size
() == 0; }
28
void
clear
();
29
30
template
<
typename
Cstr> ALIGATOR_DEPRECATED
void
pushBack
(Cstr &&el) {
31
assert(!el.func.valueless_after_move() &&
32
"constraint must have non-null underlying function."
);
33
assert(!el.set.valueless_after_move() &&
34
"constraint must have non-null underlying set."
);
35
funcs
.emplace_back(el.func);
36
sets
.emplace_back(el.set);
37
addDim(el.func->nr);
38
}
39
40
void
pushBack
(
const
PolyFunc
&func,
const
PolySet
&cstr_set) {
41
assert(!func.valueless_after_move() &&
42
"constraint must have non-null underlying function."
);
43
assert(!cstr_set.valueless_after_move() &&
44
"constraint must have non-null underlying set."
);
45
funcs
.emplace_back(func);
46
sets
.emplace_back(cstr_set);
47
addDim(func->nr);
48
}
49
51
const
std::vector<long> &
dims
()
const
{
return
dims_
; }
52
53
long
totalDim
()
const
{
return
total_dim_
; }
54
56
template
<
typename
Derived> Derived *
getConstraint
(
const
size_t
id
) {
57
return
dynamic_cast<
Derived *
>
(&*
funcs
[id]);
58
}
59
61
template
<
typename
Derived>
62
const
Derived *
getConstraint
(
const
size_t
id
)
const
{
63
return
dynamic_cast<
const
Derived *
>
(&*
funcs
[id]);
64
}
65
66
std::vector<PolyFunc>
funcs
;
67
std::vector<PolySet>
sets
;
68
69
protected
:
70
std::vector<long>
indices_
;
71
std::vector<long>
dims_
;
72
long
total_dim_
= 0;
73
74
private
:
75
void
addDim(
const
long
nr) {
76
const
long
last_cursor =
indices_
.back();
77
indices_
.push_back(last_cursor + nr);
78
dims_
.push_back(nr);
79
total_dim_
+= nr;
80
}
81
};
82
83
template
<
typename
Scalar>
void
ConstraintStackTpl<Scalar>::clear
() {
84
funcs
.clear();
85
sets
.clear();
86
indices_
= {0};
87
dims_
.clear();
88
total_dim_
= 0;
89
}
90
91
#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
92
extern
template
struct
ConstraintStackTpl<context::Scalar>
;
93
#endif
94
}
// namespace aligator
function-abstract.hpp
Base definitions for ternary functions.
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
polymorphic_cxx14.h
aligator::ConstraintStackTpl
Convenience class to manage a stack of constraints.
Definition
constraint.hpp:14
aligator::ConstraintStackTpl::totalDim
long totalDim() const
Definition
constraint.hpp:53
aligator::ConstraintStackTpl::dims
const std::vector< long > & dims() const
Get the set of dimensions for each constraint in the stack.
Definition
constraint.hpp:51
aligator::ConstraintStackTpl::PolyFunc
xyz::polymorphic< StageFunctionTpl< Scalar > > PolyFunc
Definition
constraint.hpp:16
aligator::ConstraintStackTpl::total_dim_
long total_dim_
Definition
constraint.hpp:72
aligator::ConstraintStackTpl::empty
bool empty() const
Definition
constraint.hpp:27
aligator::ConstraintStackTpl::operator=
ConstraintStackTpl & operator=(const ConstraintStackTpl &)=default
aligator::ConstraintStackTpl::operator=
ConstraintStackTpl & operator=(ConstraintStackTpl &&)=default
aligator::ConstraintStackTpl::ConstraintStackTpl
ConstraintStackTpl()
Definition
constraint.hpp:19
aligator::ConstraintStackTpl::funcs
std::vector< PolyFunc > funcs
Definition
constraint.hpp:66
aligator::ConstraintStackTpl::size
std::size_t size() const
Definition
constraint.hpp:26
aligator::ConstraintStackTpl::sets
std::vector< PolySet > sets
Definition
constraint.hpp:67
aligator::ConstraintStackTpl::indices_
std::vector< long > indices_
Definition
constraint.hpp:70
aligator::ConstraintStackTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::ConstraintStackTpl::pushBack
ALIGATOR_DEPRECATED void pushBack(Cstr &&el)
Definition
constraint.hpp:30
aligator::ConstraintStackTpl::pushBack
void pushBack(const PolyFunc &func, const PolySet &cstr_set)
Definition
constraint.hpp:40
aligator::ConstraintStackTpl::ConstraintStackTpl
ConstraintStackTpl(ConstraintStackTpl &&)=default
aligator::ConstraintStackTpl::getConstraint
const Derived * getConstraint(const size_t id) const
Get constraint function, cast down to the specified type.
Definition
constraint.hpp:62
aligator::ConstraintStackTpl::dims_
std::vector< long > dims_
Definition
constraint.hpp:71
aligator::ConstraintStackTpl::ConstraintStackTpl
ConstraintStackTpl(const ConstraintStackTpl &)=default
aligator::ConstraintStackTpl::getConstraint
Derived * getConstraint(const size_t id)
Get constraint function, cast down to the specified type.
Definition
constraint.hpp:56
aligator::ConstraintStackTpl::PolySet
xyz::polymorphic< ConstraintSetTpl< Scalar > > PolySet
Definition
constraint.hpp:17
aligator::ConstraintStackTpl::clear
void clear()
Definition
constraint.hpp:83
include
aligator
core
constraint.hpp
Generated by
1.17.0