proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
constraint-set.hpp
Go to the documentation of this file.
1
3#pragma once
4
7
8namespace proxsuite {
9namespace nlp {
10
18template <typename _Scalar> struct ConstraintSetTpl {
19public:
20 using Scalar = _Scalar;
22 using ActiveType = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
23
24 ConstraintSetTpl() = default;
25
28 virtual bool disableGaussNewton() const { return true; }
29
33 virtual Scalar evaluate(const ConstVectorRef & /*zproj*/) const { return 0.; }
34
39 virtual void projection(const ConstVectorRef &z, VectorRef zout) const = 0;
40
46 virtual void normalConeProjection(const ConstVectorRef &z,
47 VectorRef zout) const = 0;
48
56 virtual void applyProjectionJacobian(const ConstVectorRef &z,
57 MatrixRef Jout) const;
58
65 virtual void applyNormalConeProjectionJacobian(const ConstVectorRef &z,
66 MatrixRef Jout) const;
67
70 void setProxParameter(const Scalar mu) const {
71 mu_ = mu;
72 mu_inv_ = 1. / mu;
73 };
74
77 virtual void computeActiveSet(const ConstVectorRef &z,
78 Eigen::Ref<ActiveType> out) const = 0;
79
80 virtual ~ConstraintSetTpl<Scalar>() = default;
81
82 bool operator==(const ConstraintSetTpl<Scalar> &rhs) { return this == &rhs; }
83
95 Scalar evaluateMoreauEnvelope(const ConstVectorRef &zin,
96 const ConstVectorRef &zproj) const {
97 Scalar res = evaluate(zin - zproj);
98 res += static_cast<Scalar>(0.5) * mu_inv_ * zproj.squaredNorm();
99 return res;
100 }
101
104 Scalar computeMoreauEnvelope(const ConstVectorRef &zin,
105 VectorRef zprojout) const {
106 normalConeProjection(zin, zprojout);
107 return evaluateMoreauEnvelope(zin, zprojout);
108 }
109
110 Scalar mu() const { return mu_; }
111 Scalar mu_inv() const { return mu_inv_; }
112
113protected:
114 mutable Scalar mu_ = 0.;
116};
117
121template <typename _Scalar> struct ConstraintObjectTpl {
122 using Scalar = _Scalar;
124
127
128 shared_ptr<FunctionType> func_;
130
131 const FunctionType &func() const { return *func_; }
132 int nr() const { return func_->nr(); }
133
134 // Must be defined because of MSVC explicit template instantiation
139
140 ConstraintObjectTpl(shared_ptr<FunctionType> func,
142 : func_(func), set_(set) {}
143
144 bool operator==(const ConstraintObjectTpl &other) const {
145 return func_ == other.func_;
146 }
147};
148
149#ifdef PROXSUITE_NLP_ENABLE_TEMPLATE_INSTANTIATION
150extern template struct PROXSUITE_NLP_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
151 ConstraintSetTpl<context::Scalar>;
152extern template struct PROXSUITE_NLP_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
153 ConstraintObjectTpl<context::Scalar>;
154#endif
155
156} // namespace nlp
157} // namespace proxsuite
158
159#include "proxsuite-nlp/constraint-set.hxx"
Base definitions for function classes.
#define PROXSUITE_NLP_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:26
Main package namespace.
Definition bcl-params.hpp:5
Twice-differentiable function, with method Jacobian and vector-hessian product evaluation.
Definition fwd.hpp:76
Packs a ConstraintSetTpl and C2FunctionTpl together.
Definition fwd.hpp:112
const FunctionType & func() const
ConstraintObjectTpl(const ConstraintObjectTpl &)=default
polymorphic< ConstraintSet > set_
ConstraintObjectTpl(shared_ptr< FunctionType > func, const polymorphic< ConstraintSet > &set)
ConstraintObjectTpl & operator=(const ConstraintObjectTpl &)=default
shared_ptr< FunctionType > func_
ConstraintObjectTpl & operator=(ConstraintObjectTpl &&)=default
ConstraintObjectTpl(ConstraintObjectTpl &&)=default
bool operator==(const ConstraintObjectTpl &other) const
Base constraint set type.
Definition fwd.hpp:104
virtual void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const =0
virtual Scalar evaluate(const ConstVectorRef &) const
virtual void projection(const ConstVectorRef &z, VectorRef zout) const =0
Compute projection of variable z onto the constraint set.
Eigen::Matrix< bool, Eigen::Dynamic, 1 > ActiveType
Scalar evaluateMoreauEnvelope(const ConstVectorRef &zin, const ConstVectorRef &zproj) const
Evaluate the Moreau envelope with parameter mu for the given contraint set or nonsmooth penalty at p...
Scalar computeMoreauEnvelope(const ConstVectorRef &zin, VectorRef zprojout) const
Evaluate the Moreau envelope with parameter mu for the given contraint set or nonsmooth penalty at p...
void setProxParameter(const Scalar mu) const
Update proximal parameter; this applies to when this class is a proximal operator that isn't a projec...
virtual bool disableGaussNewton() const
virtual void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
Apply the jacobian of the projection on the normal cone.
bool operator==(const ConstraintSetTpl< Scalar > &rhs)
virtual ~ConstraintSetTpl()=default
virtual void normalConeProjection(const ConstVectorRef &z, VectorRef zout) const =0
Compute projection of z onto the normal cone to the set. The default implementation is just .
virtual void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
Apply a jacobian of the projection/proximal operator to a matrix.