aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-constraint-set.cpp
Go to the documentation of this file.
3
4namespace aligator::python {
5
7using context::ConstVectorRef;
9
15
17
18template <typename T>
19auto exposeSpecificConstraintSet(const char *name, const char *docstring) {
20 return bp::class_<T, bp::bases<ConstraintSet>>(name, docstring, bp::no_init)
22}
23
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",
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
68 "EqualityConstraintSet", "Cast a function into an equality constraint")
69 .def(bp::init<>("self"_a));
70
72 "NegativeOrthant",
73 "Cast a function into a negative inequality constraint h(x) \\leq 0")
74 .def(bp::init<>("self"_a));
75
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
89 "ConstraintSetProduct", "Cartesian product of constraint sets.")
90 .def(bp::init<std::vector<PolySet>, std::vector<Eigen::Index>>(
91 ("self"_a, "components", "blockSizes")))
92 .add_property("components",
93 bp::make_function(&ConstraintSetProduct::components,
94 bp::return_internal_reference<>()))
95 .add_property("blockSizes",
96 bp::make_function(&ConstraintSetProduct::blockSizes,
97 bp::return_internal_reference<>()),
98 "Dimensions of each component of the cartesian product.");
99
100 StdVectorPythonVisitor<std::vector<PolySet>>::expose(
101 "StdVec_ConstraintObject",
102 eigenpy::details::overload_base_get_item_for_std_vector<
103 std::vector<PolySet>>());
104}
105
106} // namespace aligator::python
Omnibus header which includes all supported constraint sets.
ConstraintSetTpl< Scalar > ConstraintSet
Definition context.hpp:22
The Python bindings.
Definition blk-matrix.hpp:5
BoxConstraintTpl< Scalar > BoxConstraint
EqualityConstraintTpl< Scalar > EqualityConstraint
void register_polymorphic_to_python()
Expose a polymorphic value type, e.g. xyz::polymorphic<T, A>.
NegativeOrthantTpl< Scalar > NegativeOrthant
ConstraintSetProductTpl< Scalar > ConstraintSetProduct
xyz::polymorphic< ConstraintSet > PolySet
auto exposeSpecificConstraintSet(const char *name, const char *docstring)
NonsmoothPenaltyL1Tpl< Scalar > L1Penalty
Cartesian product of multiple constraint sets. This class makes computing multipliers and Jacobian ma...
const std::vector< xyz::polymorphic< Base > > & components() const
const std::vector< Eigen::Index > & blockSizes() const
virtual void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
virtual void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const=0
virtual void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
virtual Scalar evaluate(const ConstVectorRef &) const
virtual void normalConeProjection(const ConstVectorRef &z, VectorRef zout) const=0
Scalar evaluateMoreauEnvelope(const ConstVectorRef &zin, const ConstVectorRef &zproj) const
void setProxParameter(const Scalar mu) const
virtual void projection(const ConstVectorRef &z, VectorRef zout) const=0
Negative orthant, for constraints .
Composite -penalty function .