aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
expose-constraint-set.cpp
Go to the documentation of this file.
1
#include "
aligator/python/fwd.hpp
"
2
#include "
aligator/modelling/constraints.hpp
"
3
4
namespace
aligator::python
{
5
6
using
context::ConstraintSet
;
7
using
context::ConstVectorRef;
8
using
context::Scalar
;
9
10
using
EqualityConstraint
=
EqualityConstraintTpl<Scalar>
;
11
using
NegativeOrthant
=
NegativeOrthantTpl<Scalar>
;
12
using
L1Penalty
=
NonsmoothPenaltyL1Tpl<Scalar>
;
13
using
ConstraintSetProduct
=
ConstraintSetProductTpl<Scalar>
;
14
using
BoxConstraint
=
BoxConstraintTpl<Scalar>
;
15
16
using
PolySet
= xyz::polymorphic<ConstraintSet>;
17
18
template
<
typename
T>
19
auto
exposeSpecificConstraintSet
(
const
char
*name,
const
char
*docstring) {
20
return
bp::class_<T, bp::bases<ConstraintSet>>(name, docstring, bp::no_init)
21
.def(
PolymorphicVisitor<PolySet>
{});
22
}
23
24
void
exposeConstraintSets
() {
25
register_polymorphic_to_python<PolySet>
();
26
bp::class_<ConstraintSet, boost::noncopyable>(
27
"ConstraintSet"
,
"Base class for constraint sets or nonsmooth penalties."
,
28
bp::no_init)
29
.def(
"evaluate"
, &
ConstraintSet::evaluate
, (
"self"
_a,
"z"
),
30
"Evaluate the constraint indicator function or nonsmooth penalty "
31
"on the projection/prox map of :math:`z`."
)
32
.def(
"projection"
, &
ConstraintSet::projection
, (
"self"
_a,
"z"
,
"zout"
))
33
.def(
34
"projection"
,
35
+[](
const
ConstraintSet
&c,
const
ConstVectorRef &z) {
36
context::VectorXs zout(z.size());
37
c.
projection
(z, zout);
38
return
zout;
39
},
40
(
"self"
_a,
"z"
))
41
.def(
"normalConeProjection"
, &
ConstraintSet::normalConeProjection
,
42
(
"self"
_a,
"z"
,
"zout"
))
43
.def(
44
"normalConeProjection"
,
45
+[](
const
ConstraintSet
&c,
const
ConstVectorRef &z) {
46
context::VectorXs zout(z.size());
47
c.
normalConeProjection
(z, zout);
48
return
zout;
49
},
50
(
"self"
_a,
"z"
))
51
.def(
"applyProjectionJacobian"
, &
ConstraintSet::applyProjectionJacobian
,
52
(
"self"
_a,
"z"
,
"Jout"
),
"Apply the projection Jacobian."
)
53
.def(
"applyNormalProjectionJacobian"
,
54
&
ConstraintSet::applyNormalConeProjectionJacobian
,
55
(
"self"
_a,
"z"
,
"Jout"
),
56
"Apply the normal cone projection Jacobian."
)
57
.def(
"computeActiveSet"
, &
ConstraintSet::computeActiveSet
,
58
(
"self"
_a,
"z"
,
"out"
))
59
.def(
"evaluateMoreauEnvelope"
, &
ConstraintSet::evaluateMoreauEnvelope
,
60
(
"self"
_a,
"zin"
,
"zproj"
),
61
"Evaluate the Moreau envelope with parameter :math:`\\mu`."
)
62
.def(
"setProxParameter"
, &
ConstraintSet::setProxParameter
,
63
(
"self"
_a,
"mu"
),
"Set proximal parameter."
)
64
.add_property(
"mu"
, &
ConstraintSet::mu
,
"Current proximal parameter."
)
65
.def(bp::self == bp::self);
66
67
exposeSpecificConstraintSet<EqualityConstraintTpl<Scalar>
>(
68
"EqualityConstraintSet"
,
"Cast a function into an equality constraint"
)
69
.def(bp::init<>(
"self"
_a));
70
71
exposeSpecificConstraintSet<NegativeOrthantTpl<Scalar>
>(
72
"NegativeOrthant"
,
73
"Cast a function into a negative inequality constraint h(x) \\leq 0"
)
74
.def(bp::init<>(
"self"
_a));
75
76
exposeSpecificConstraintSet<BoxConstraint>
(
77
"BoxConstraint"
,
78
"Box constraint of the form :math:`z \\in [z_\\min, z_\\max]`."
)
79
.def(bp::init<ConstVectorRef, ConstVectorRef>(
80
(
"self"
_a,
"lower_limit"
,
"upper_limit"
)))
81
.def_readwrite(
"upper_limit"
, &
BoxConstraint::upper_limit
)
82
.def_readwrite(
"lower_limit"
, &
BoxConstraint::lower_limit
);
83
84
exposeSpecificConstraintSet<L1Penalty>
(
"NonsmoothPenaltyL1"
,
85
"1-norm penalty function."
)
86
.def(bp::init<>((
"self"
_a)));
87
88
exposeSpecificConstraintSet<ConstraintSetProduct>
(
89
"ConstraintSetProduct"
,
"Cartesian product of constraint sets."
)
90
.def(bp::init<
const
std::vector<PolySet> &,
91
const
std::vector<Eigen::Index> &>(
92
(
"self"
_a,
"components"
,
"blockSizes"
)))
93
.add_property(
"components"
,
94
bp::make_function(&
ConstraintSetProduct::components
,
95
bp::return_internal_reference<>()))
96
.add_property(
"blockSizes"
,
97
bp::make_function(&
ConstraintSetProduct::blockSizes
,
98
bp::return_internal_reference<>()),
99
"Dimensions of each component of the cartesian product."
);
100
101
StdVectorPythonVisitor<std::vector<PolySet>>::expose(
102
"StdVec_ConstraintObject"
,
103
eigenpy::details::overload_base_get_item_for_std_vector<
104
std::vector<PolySet>>());
105
}
106
107
}
// namespace aligator::python
fwd.hpp
constraints.hpp
Omnibus header which includes all supported constraint sets.
aligator::context::Scalar
double Scalar
Definition
context.hpp:9
aligator::context::ConstraintSet
ConstraintSetTpl< Scalar > ConstraintSet
Definition
context.hpp:21
aligator::python
The Python bindings.
Definition
blk-matrix.hpp:7
aligator::python::BoxConstraint
BoxConstraintTpl< Scalar > BoxConstraint
Definition
expose-constraint-set.cpp:14
aligator::python::EqualityConstraint
EqualityConstraintTpl< Scalar > EqualityConstraint
Definition
expose-constraint-set.cpp:10
aligator::python::register_polymorphic_to_python
void register_polymorphic_to_python()
Expose a polymorphic value type, e.g. xyz::polymorphic<T, A>.
Definition
polymorphic.hpp:23
aligator::python::NegativeOrthant
NegativeOrthantTpl< Scalar > NegativeOrthant
Definition
expose-constraint-set.cpp:11
aligator::python::exposeConstraintSets
void exposeConstraintSets()
Definition
expose-constraint-set.cpp:24
aligator::python::ConstraintSetProduct
ConstraintSetProductTpl< Scalar > ConstraintSetProduct
Definition
expose-constraint-set.cpp:13
aligator::python::PolySet
xyz::polymorphic< ConstraintSet > PolySet
Definition
expose-constraint-set.cpp:16
aligator::python::exposeSpecificConstraintSet
auto exposeSpecificConstraintSet(const char *name, const char *docstring)
Definition
expose-constraint-set.cpp:19
aligator::python::L1Penalty
NonsmoothPenaltyL1Tpl< Scalar > L1Penalty
Definition
expose-constraint-set.cpp:12
aligator::BoxConstraintTpl
Box constraint set .
Definition
box-constraint.hpp:10
aligator::BoxConstraintTpl::lower_limit
VectorXs lower_limit
Definition
box-constraint.hpp:15
aligator::BoxConstraintTpl::upper_limit
VectorXs upper_limit
Definition
box-constraint.hpp:16
aligator::ConstraintSetProductTpl
Cartesian product of multiple constraint sets. This class makes computing multipliers and Jacobian ma...
Definition
constraint-set-product.hpp:40
aligator::ConstraintSetProductTpl::components
const std::vector< xyz::polymorphic< Base > > & components() const
Definition
constraint-set-product.hpp:113
aligator::ConstraintSetProductTpl::blockSizes
const std::vector< Eigen::Index > & blockSizes() const
Definition
constraint-set-product.hpp:116
aligator::ConstraintSetTpl< Scalar >::applyNormalConeProjectionJacobian
virtual void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
aligator::ConstraintSetTpl< Scalar >::computeActiveSet
virtual void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const=0
aligator::ConstraintSetTpl< Scalar >::applyProjectionJacobian
virtual void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
aligator::ConstraintSetTpl< Scalar >::evaluate
virtual Scalar evaluate(const ConstVectorRef &) const
Definition
constraint-set.hpp:31
aligator::ConstraintSetTpl< Scalar >::normalConeProjection
virtual void normalConeProjection(const ConstVectorRef &z, VectorRef zout) const=0
aligator::ConstraintSetTpl< Scalar >::evaluateMoreauEnvelope
Scalar evaluateMoreauEnvelope(const ConstVectorRef &zin, const ConstVectorRef &zproj) const
Definition
constraint-set.hpp:93
aligator::ConstraintSetTpl< Scalar >::mu
Scalar mu() const
Definition
constraint-set.hpp:108
aligator::ConstraintSetTpl< Scalar >::setProxParameter
void setProxParameter(const Scalar mu) const
Definition
constraint-set.hpp:68
aligator::ConstraintSetTpl< Scalar >::projection
virtual void projection(const ConstVectorRef &z, VectorRef zout) const=0
aligator::EqualityConstraintTpl
Equality constraints .
Definition
equality-constraint.hpp:17
aligator::NegativeOrthantTpl
Negative orthant, for constraints .
Definition
negative-orthant.hpp:19
aligator::NonsmoothPenaltyL1Tpl
Composite -penalty function .
Definition
l1-penalty.hpp:18
aligator::python::PolymorphicVisitor
Definition
polymorphic.hpp:30
bindings
python
src
expose-constraint-set.cpp
Generated by
1.17.0