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 public:
111 
112  Bounds(const Vector<Real> &x,
113  bool isLower = true,
114  Real scale = 1,
115  Real feasTol = 1e-2);
116 
117  Bounds(const Ptr<Vector<Real>> &x_lo,
118  const Ptr<Vector<Real>> &x_up,
119  const Real scale = 1,
120  const Real feasTol = 1e-2);
121 
122  void project( Vector<Real> &x ) override;
123 
124  void projectInterior( Vector<Real> &x ) override;
125 
126  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
127 
128  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
129 
130  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
131 
132  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
133 
134  bool isFeasible( const Vector<Real> &v ) override;
135 
136 }; // class Bounds
137 
138 } // namespace ROL
139 
140 #include "ROL_Bounds_Def.hpp"
141 
142 #endif
LowerBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:95
UpperBinding(Real xeps, Real geps)
Definition: ROL_Bounds.hpp:85
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
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
Real apply(const Real &x, const Real &y) const
Definition: ROL_Bounds.hpp:105
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 Real &y) const
Definition: ROL_Bounds.hpp:86
Real min_diff_
Definition: ROL_Bounds.hpp:69
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=1e-2)
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.
Active(Real offset)
Definition: ROL_Bounds.hpp:75