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 
73  class Active : public Elementwise::BinaryFunction<Real> {
74  public:
75  Active(Real offset) : offset_(offset) {}
76  Real apply( const Real &x, const Real &y ) const {
77  return ((y <= offset_) ? 0 : x);
78  }
79  private:
80  Real offset_;
81  };
82 
83  class UpperBinding : public Elementwise::BinaryFunction<Real> {
84  public:
85  UpperBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
86  Real apply( const Real &x, const Real &y ) const {
87  return ((y < -geps_ && x <= xeps_) ? 0 : 1);
88  }
89  private:
90  Real xeps_, geps_;
91  };
92 
93  class LowerBinding : public Elementwise::BinaryFunction<Real> {
94  public:
95  LowerBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
96  Real apply( const Real &x, const Real &y ) const {
97  return ((y > geps_ && x <= xeps_) ? 0 : 1);
98  }
99  private:
100  Real xeps_, geps_;
101  };
102 
103  class PruneBinding : public Elementwise::BinaryFunction<Real> {
104  public:
105  Real apply( const Real &x, const Real &y ) const {
106  return ((y == 1) ? x : 0);
107  }
108  } prune_;
109 
110  class BuildC : public Elementwise::UnaryFunction<Real> {
111  public:
112  Real apply( const Real &x ) const {
113  const Real zeta(0.5), kappa(1);
114  return std::min(zeta * x, kappa);
115  }
116  } buildC_;
117 
118  class SetZeroEntry : public Elementwise::BinaryFunction<Real> {
119  public:
120  Real apply(const Real &x, const Real &y) const {
121  const Real zero(0);
122  return (x==zero ? y : x);
123  }
124  } setZeroEntry_;
125 
126  void buildScalingFunction(Vector<Real> &d, const Vector<Real> &x, const Vector<Real> &g) const;
127 
128 public:
129 
130  Bounds(const Vector<Real> &x,
131  bool isLower = true,
132  Real scale = 1,
133  Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
134 
135  Bounds(const Ptr<Vector<Real>> &x_lo,
136  const Ptr<Vector<Real>> &x_up,
137  const Real scale = 1,
138  const Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
139 
140  void project( Vector<Real> &x ) override;
141 
142  void projectInterior( Vector<Real> &x ) override;
143 
144  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
145 
146  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
147 
148  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
149 
150  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
151 
152  bool isFeasible( const Vector<Real> &v ) override;
153 
154  void applyInverseScalingFunction(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
155 
156  void applyScalingFunctionJacobian(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
157 }; // class Bounds
158 
159 } // namespace ROL
160 
161 #include "ROL_Bounds_Def.hpp"
162 
163 #endif
LowerBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:95
UpperBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:85
void buildScalingFunction(Vector< Real > &d, const Vector< Real > &x, const Vector< Real > &g) const
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.
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:76
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_
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:105
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=std::sqrt(ROL_EPSILON< Real >()))
Provides the elementwise interface to apply upper and lower bound constraints.
Definition: ROL_Bounds.hpp:59
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:96
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
Definition: ROL_Bounds.hpp:112
ROL::Bounds::SetZeroEntry setZeroEntry_
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:86
Real min_diff_
Definition: ROL_Bounds.hpp:69
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:120
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
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:75