ROL
ROL_Bounds.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_BOUNDS_H
45 #define ROL_BOUNDS_H
46 
47 #include "ROL_BoundConstraint.hpp"
48 
56 namespace ROL {
57 
58 template<typename Real>
59 class Bounds : public BoundConstraint<Real> {
60 private:
61  const Real scale_;
62  const Real feasTol_;
63 
66 
67  Ptr<Vector<Real>> mask_;
68 
69  Real min_diff_;
70 
71  Elementwise::ReductionMin<Real> minimum_;
72  Elementwise::ReductionMax<Real> maximum_;
73 
74  class isGreater : public Elementwise::BinaryFunction<Real> {
75  public:
76  isGreater() {}
77  Real apply(const Real &x, const Real &y) const {
78  return (x > y) ? static_cast<Real>(1) : static_cast<Real>(0);
79  }
80  } isGreater_;
81 
82  class Active : public Elementwise::BinaryFunction<Real> {
83  public:
84  Active(Real offset) : offset_(offset) {}
85  Real apply( const Real &x, const Real &y ) const {
86  return ((y <= offset_) ? 0 : x);
87  }
88  private:
89  Real offset_;
90  };
91 
92  class UpperBinding : public Elementwise::BinaryFunction<Real> {
93  public:
94  UpperBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
95  Real apply( const Real &x, const Real &y ) const {
96  return ((y < -geps_ && x <= xeps_) ? 0 : 1);
97  }
98  private:
99  Real xeps_, geps_;
100  };
101 
102  class LowerBinding : public Elementwise::BinaryFunction<Real> {
103  public:
104  LowerBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
105  Real apply( const Real &x, const Real &y ) const {
106  return ((y > geps_ && x <= xeps_) ? 0 : 1);
107  }
108  private:
109  Real xeps_, geps_;
110  };
111 
112  class PruneBinding : public Elementwise::BinaryFunction<Real> {
113  public:
114  Real apply( const Real &x, const Real &y ) const {
115  return ((y == 1) ? x : 0);
116  }
117  } prune_;
118 
119  class BuildC : public Elementwise::UnaryFunction<Real> {
120  public:
121  Real apply( const Real &x ) const {
122  const Real zeta(0.5), kappa(1);
123  return std::min(zeta * x, kappa);
124  }
125  } buildC_;
126 
127  class SetZeroEntry : public Elementwise::BinaryFunction<Real> {
128  public:
129  Real apply(const Real &x, const Real &y) const {
130  const Real zero(0);
131  return (x==zero ? y : x);
132  }
133  } setZeroEntry_;
134 
135  void buildScalingFunction(Vector<Real> &d, const Vector<Real> &x, const Vector<Real> &g) const;
136 
137 public:
138 
139  Bounds(const Vector<Real> &x,
140  bool isLower = true,
141  Real scale = 1,
142  Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
143 
144  Bounds(const Ptr<Vector<Real>> &x_lo,
145  const Ptr<Vector<Real>> &x_up,
146  const Real scale = 1,
147  const Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
148 
149  void project( Vector<Real> &x ) override;
150 
151  void projectInterior( Vector<Real> &x ) override;
152 
153  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
154 
155  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
156 
157  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
158 
159  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
160 
161  bool isFeasible( const Vector<Real> &v ) override;
162 
163  void applyInverseScalingFunction(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
164 
165  void applyScalingFunctionJacobian(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
166 }; // class Bounds
167 
168 } // namespace ROL
169 
170 #include "ROL_Bounds_Def.hpp"
171 
172 #endif
LowerBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:104
UpperBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:94
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:105
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:95
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:129
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:71
const Real feasTol_
Definition: ROL_Bounds.hpp:62
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:121
Provides the elementwise interface to apply upper and lower bound constraints.
Definition: ROL_Bounds.hpp:59
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:61
Provides the interface to apply upper and lower bound constraints.
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:114
ROL::Bounds::SetZeroEntry setZeroEntry_
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:85
Real min_diff_
Definition: ROL_Bounds.hpp:69
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:77
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:72
Ptr< Vector< Real > > mask_
Definition: ROL_Bounds.hpp:67
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:84