proxsuite-nlp  0.11.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
6#include "proxsuite-nlp/third-party/polymorphic_cxx14.hpp"
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() = 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.;
115 mutable Scalar mu_inv_;
116};
117
121template <typename _Scalar> struct ConstraintObjectTpl {
122 using Scalar = _Scalar;
124
125 using FunctionType = C2FunctionTpl<Scalar>;
126 using ConstraintSet = ConstraintSetTpl<Scalar>;
127
128 shared_ptr<FunctionType> func_;
129 polymorphic<ConstraintSet> set_;
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
135 ConstraintObjectTpl(ConstraintObjectTpl &&) = default;
136 ConstraintObjectTpl &operator=(ConstraintObjectTpl &&) = default;
137 ConstraintObjectTpl(const ConstraintObjectTpl &) = default;
138 ConstraintObjectTpl &operator=(const ConstraintObjectTpl &) = default;
139
140 ConstraintObjectTpl(shared_ptr<FunctionType> func,
141 const polymorphic<ConstraintSet> &set)
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
152extern template struct PROXSUITE_NLP_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
154#endif
155
156} // namespace nlp
157} // namespace proxsuite
158
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.
Packs a ConstraintSetTpl and C2FunctionTpl together.
Base constraint set type.
virtual Scalar evaluate(const ConstVectorRef &) const
virtual bool disableGaussNewton() const
virtual void applyProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
Apply a jacobian of the projection/proximal operator to a matrix.
virtual void computeActiveSet(const ConstVectorRef &z, Eigen::Ref< ActiveType > out) const =0
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...
virtual void projection(const ConstVectorRef &z, VectorRef zout) const =0
Compute projection of variable z onto the constraint set.
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...
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 void applyNormalConeProjectionJacobian(const ConstVectorRef &z, MatrixRef Jout) const
Apply the jacobian of the projection on the normal cone.
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 .