ROL
ROL_Bounds.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_BOUNDS_H
11 #define ROL_BOUNDS_H
12 
13 #include "ROL_BoundConstraint.hpp"
14 
22 namespace ROL {
23 
24 template<typename Real>
25 class Bounds : public BoundConstraint<Real> {
26 private:
27  const Real scale_;
28  const Real feasTol_;
29 
32 
33  Ptr<Vector<Real>> mask_;
34 
35  Real min_diff_;
36 
37  Elementwise::ReductionMin<Real> minimum_;
38  Elementwise::ReductionMax<Real> maximum_;
39 
40  class isGreater : public Elementwise::BinaryFunction<Real> {
41  public:
42  isGreater() {}
43  Real apply(const Real &x, const Real &y) const {
44  return (x > y) ? static_cast<Real>(1) : static_cast<Real>(0);
45  }
46  } isGreater_;
47 
48  class Active : public Elementwise::BinaryFunction<Real> {
49  public:
50  Active(Real offset) : offset_(offset) {}
51  Real apply( const Real &x, const Real &y ) const {
52  return ((y <= offset_) ? 0 : x);
53  }
54  private:
55  Real offset_;
56  };
57 
58  class UpperBinding : public Elementwise::BinaryFunction<Real> {
59  public:
60  UpperBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
61  Real apply( const Real &x, const Real &y ) const {
62  return ((y < -geps_ && x <= xeps_) ? 0 : 1);
63  }
64  private:
65  Real xeps_, geps_;
66  };
67 
68  class LowerBinding : public Elementwise::BinaryFunction<Real> {
69  public:
70  LowerBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
71  Real apply( const Real &x, const Real &y ) const {
72  return ((y > geps_ && x <= xeps_) ? 0 : 1);
73  }
74  private:
75  Real xeps_, geps_;
76  };
77 
78  class PruneBinding : public Elementwise::BinaryFunction<Real> {
79  public:
80  Real apply( const Real &x, const Real &y ) const {
81  return ((y == 1) ? x : 0);
82  }
83  } prune_;
84 
85  class BuildC : public Elementwise::UnaryFunction<Real> {
86  public:
87  Real apply( const Real &x ) const {
88  const Real zeta(0.5), kappa(1);
89  return std::min(zeta * x, kappa);
90  }
91  } buildC_;
92 
93  class SetZeroEntry : public Elementwise::BinaryFunction<Real> {
94  public:
95  Real apply(const Real &x, const Real &y) const {
96  const Real zero(0);
97  return (x==zero ? y : x);
98  }
99  } setZeroEntry_;
100 
101  void buildScalingFunction(Vector<Real> &d, const Vector<Real> &x, const Vector<Real> &g) const;
102 
103 public:
104 
105  Bounds(const Vector<Real> &x,
106  bool isLower = true,
107  Real scale = 1,
108  Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
109 
110  Bounds(const Ptr<Vector<Real>> &x_lo,
111  const Ptr<Vector<Real>> &x_up,
112  const Real scale = 1,
113  const Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
114 
115  void project( Vector<Real> &x ) override;
116 
117  void projectInterior( Vector<Real> &x ) override;
118 
119  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
120 
121  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
122 
123  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
124 
125  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
126 
127  bool isFeasible( const Vector<Real> &v ) override;
128 
129  void applyInverseScalingFunction(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
130 
131  void applyScalingFunctionJacobian(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
132 }; // class Bounds
133 
134 } // namespace ROL
135 
136 #include "ROL_Bounds_Def.hpp"
137 
138 #endif
LowerBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:70
UpperBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:60
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:71
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0)) override
Set variables to zero if they correspond to the upper -active set.
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:61
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:95
ROL::Bounds::isGreater isGreater_
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void project(Vector< Real > &x) override
Project optimization variables onto the bounds.
Elementwise::ReductionMin< Real > minimum_
Definition: ROL_Bounds.hpp:37
const Real feasTol_
Definition: ROL_Bounds.hpp:28
ROL::Bounds::BuildC buildC_
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=std::sqrt(ROL_EPSILON< Real >()))
Real apply(const Real &x) const
Definition: ROL_Bounds.hpp:87
Provides the elementwise interface to apply upper and lower bound constraints.
Definition: ROL_Bounds.hpp:25
void buildScalingFunction(Vector< Real > &d, const Vector< Real > &x, const Vector< Real > &g) const
bool isFeasible(const Vector< Real > &v) override
Check if the vector, v, is feasible.
ROL::Bounds::PruneBinding prune_
const Real scale_
Definition: ROL_Bounds.hpp:27
Provides the interface to apply upper and lower bound constraints.
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:80
ROL::Bounds::SetZeroEntry setZeroEntry_
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:51
Real min_diff_
Definition: ROL_Bounds.hpp:35
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:43
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
Elementwise::ReductionMax< Real > maximum_
Definition: ROL_Bounds.hpp:38
Ptr< Vector< Real > > mask_
Definition: ROL_Bounds.hpp:33
void projectInterior(Vector< Real > &x) override
Project optimization variables into the interior of the feasible set.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0)) override
Set variables to zero if they correspond to the lower -active set.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply scaling function Jacobian.
Active(Real offset)
Definition: ROL_Bounds.hpp:50