4#include "proxsuite-nlp/python/polymorphic.hpp" 
    6#include <eigenpy/std-vector.hpp> 
   14using context::C2Function;
 
   15using context::Constraint;
 
   16using context::ConstraintSet;
 
   17using context::ConstVectorRef;
 
   19using eigenpy::StdVectorPythonVisitor;
 
   20using L1Penalty = NonsmoothPenaltyL1Tpl<Scalar>;
 
   21using ConstraintSetProduct = ConstraintSetProductTpl<Scalar>;
 
   22using BoxConstraint = BoxConstraintTpl<Scalar>;
 
   25auto exposeSpecificConstraintSet(
const char *name, 
const char *docstring) {
 
   26  return bp::class_<T, bp::bases<ConstraintSet>>(name, docstring, bp::no_init)
 
   30template <
typename Constra
intType>
 
   31context::Constraint make_constraint(
const shared_ptr<context::C2Function> &f) {
 
   32  return context::Constraint(f, ConstraintType{});
 
   35static void exposeConstraintTypes();
 
   42      bp::class_<ConstraintSet, boost::noncopyable>(
 
   44          "Base class for constraint sets or nonsmooth penalties.", bp::no_init)
 
   47              "Evaluate the constraint indicator function or nonsmooth penalty " 
   48              "on the projection/prox map of :math:`z`.")
 
   50               (
"self"_a, 
"z", 
"zout"))
 
   53              +[](
const ConstraintSet &c, 
const ConstVectorRef &z) {
 
   54                context::VectorXs zout(z.size());
 
   60               (
"self"_a, 
"z", 
"zout"))
 
   62              "normalConeProjection",
 
   63              +[](
const ConstraintSet &c, 
const ConstVectorRef &z) {
 
   64                context::VectorXs zout(z.size());
 
   69          .def(
"applyProjectionJacobian",
 
   71               "Apply the projection Jacobian.")
 
   72          .def(
"applyNormalProjectionJacobian",
 
   74               (
"self"_a, 
"z", 
"Jout"),
 
   75               "Apply the normal cone projection Jacobian.")
 
   77               (
"self"_a, 
"z", 
"out"))
 
   79               (
"self"_a, 
"zin", 
"zproj"),
 
   80               "Evaluate the Moreau envelope with parameter :math:`\\mu`.")
 
   82               (
"self"_a, 
"mu"), 
"Set proximal parameter.")
 
   83          .add_property(
"mu", &ConstraintSet::mu, 
"Current proximal parameter.")
 
   84          .def(bp::self == bp::self);
 
   85  bp::scope current_scope;
 
   86  current_scope.attr(
"ConstraintBase") = cls;
 
   88  bp::class_<Constraint>(
 
   89      "ConstraintObject", 
"Packs a constraint set together with a function.",
 
   90      bp::init<shared_ptr<C2Function>, 
const polymorphic<ConstraintSet> &>(
 
   91          (
"self"_a, 
"func", 
"constraint_set")))
 
   92      .add_property(
"nr", &Constraint::nr, 
"Constraint dimension.")
 
   93      .def_readonly(
"func", &Constraint::func_, 
"Underlying function.")
 
   94      .def_readonly(
"set", &Constraint::set_, 
"Constraint set.");
 
   96  StdVectorPythonVisitor<std::vector<context::Constraint>, 
true>::expose(
 
   97      "StdVec_ConstraintObject");
 
   99  exposeConstraintTypes();
 
 
  102static void exposeConstraintTypes() {
 
  103  exposeSpecificConstraintSet<EqualityConstraintTpl<Scalar>>(
 
  104      "EqualityConstraintSet", 
"Cast a function into an equality constraint")
 
  105      .def(bp::init<>(
"self"_a));
 
  107  exposeSpecificConstraintSet<NegativeOrthantTpl<Scalar>>(
 
  109      "Cast a function into a negative inequality constraint h(x) \\leq 0")
 
  110      .def(bp::init<>(
"self"_a));
 
  112  exposeSpecificConstraintSet<BoxConstraint>(
 
  114      "Box constraint of the form :math:`z \\in [z_\\min, z_\\max]`.")
 
  115      .def(bp::init<context::ConstVectorRef, context::ConstVectorRef>(
 
  116          (
"self"_a, 
"lower_limit", 
"upper_limit")))
 
  117      .def_readwrite(
"upper_limit", &BoxConstraint::upper_limit)
 
  118      .def_readwrite(
"lower_limit", &BoxConstraint::lower_limit);
 
  120  bp::def(
"createEqualityConstraint",
 
  122          "Convenience function to create an equality constraint from a " 
  124  bp::def(
"createInequalityConstraint",
 
  126          "Convenience function to create an inequality constraint from a " 
  129  exposeSpecificConstraintSet<L1Penalty>(
"NonsmoothPenaltyL1",
 
  130                                         "1-norm penalty function.")
 
  131      .def(bp::init<>((
"self"_a)));
 
  133  exposeSpecificConstraintSet<ConstraintSetProduct>(
 
  134      "ConstraintSetProduct", 
"Cartesian product of constraint sets.")
 
  135      .def(bp::init<std::vector<polymorphic<ConstraintSet>>,
 
  136                    std::vector<Eigen::Index>>(
 
  137          (
"self"_a, 
"components", 
"blockSizes")))
 
  138      .add_property(
"components",
 
  139                    bp::make_function(&ConstraintSetProduct::components,
 
  140                                      bp::return_internal_reference<>()))
 
  141      .add_property(
"blockSizes",
 
  142                    bp::make_function(&ConstraintSetProduct::blockSizes,
 
  143                                      bp::return_internal_reference<>()),
 
  144                    "Dimensions of each component of the cartesian product.");
 
  146  StdVectorPythonVisitor<std::vector<polymorphic<ConstraintSet>>>::expose(
 
  147      "StdVec_ConstraintObject",
 
  148      eigenpy::details::overload_base_get_item_for_std_vector<
 
  149          std::vector<polymorphic<ConstraintSet>>>());
 
void register_polymorphic_to_python()
Expose a polymorphic value type, e.g. xyz::polymorphic<T, A>.
 
virtual Scalar evaluate(const ConstVectorRef &) const
 
virtual void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
 
virtual void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const=0
 
virtual void projection(const ConstVectorRef &z, VectorRef zout) const=0
 
Scalar evaluateMoreauEnvelope(const ConstVectorRef &zin, const ConstVectorRef &zproj) const
 
void setProxParameter(const Scalar mu) const
 
virtual void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
 
virtual void normalConeProjection(const ConstVectorRef &z, VectorRef zout) const=0
 
Negative orthant, for constraints .