ROL
ROL_BPOEBoundConstraint.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_BPOE_BOUND_CONSTRAINT_H
45 #define ROL_BPOE_BOUND_CONSTRAINT_H
46 
47 #include "ROL_BoundConstraint.hpp"
48 #include "ROL_CVaRVector.hpp"
49 
50 namespace ROL {
51 
52 template <class Real>
53 class BPOEBoundConstraint : public BoundConstraint<Real> {
54 private:
55  Teuchos::RCP<BoundConstraint<Real> > bc_;
56 
57 public:
58  BPOEBoundConstraint(void) : bc_(Teuchos::null) {}
59 
60  BPOEBoundConstraint(Teuchos::RCP<BoundConstraint<Real> > &bc) : BoundConstraint<Real>(), bc_(bc) {}
61 
62  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
63  if ( bc_ != Teuchos::null ) {
64  Teuchos::RCP<const Vector<Real> > xv
65  = (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
66  bc_->update(*xv,flag,iter);
67  }
68  }
69 
70  void project( Vector<Real> &x ) {
71  Real xvar = Teuchos::dyn_cast<CVaRVector<Real> >(x).getVaR();
72  xvar = ((xvar > 0.0) ? xvar : 0.0);
73  (Teuchos::dyn_cast<CVaRVector<Real> >(x)).setVaR(xvar);
74  if ( bc_ != Teuchos::null ) {
75  Teuchos::RCP<Vector<Real> > xvec = Teuchos::rcp_const_cast<Vector<Real> >(
76  (Teuchos::dyn_cast<CVaRVector<Real> >(x)).getVector());
77  bc_->project(*xvec);
78  (Teuchos::dyn_cast<CVaRVector<Real> >(x)).setVector(*xvec);
79  }
80  }
81 
82  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
83  if ( bc_ != Teuchos::null ) {
84  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
85  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
86  Teuchos::RCP<const Vector<Real> > xvec =
87  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
88  bc_->pruneUpperActive(*vvec,*xvec,eps);
89  }
90  }
91 
92  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
93  if ( bc_ != Teuchos::null ) {
94  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
95  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
96  Teuchos::RCP<const Vector<Real> > gvec =
97  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
98  Teuchos::RCP<const Vector<Real> > xvec =
99  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
100  bc_->pruneUpperActive(*vvec,*gvec,*xvec,eps);
101  }
102  }
103 
104  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
105  Real xvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x)).getVaR();
106  if ( xvar <= eps ) {
107  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).setVaR(0.0);
108  }
109  if ( bc_ != Teuchos::null ) {
110  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
111  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
112  Teuchos::RCP<const Vector<Real> > xvec
113  = (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
114  bc_->pruneLowerActive(*vvec,*xvec,eps);
115  }
116  }
117 
118  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
119  Real gvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g)).getVaR();
120  Real xvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x)).getVaR();
121  if ( xvar <= eps && gvar > 0.0 ) {
122  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).setVaR(0.0);
123  }
124  if ( bc_ != Teuchos::null ) {
125  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
126  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
127  Teuchos::RCP<const Vector<Real> > gvec
128  = (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
129  Teuchos::RCP<const Vector<Real> > xvec
130  = (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
131  bc_->pruneLowerActive(*vvec,*gvec,*xvec,eps);
132  }
133  }
134 
136  Real uvar = 0.1*ROL_OVERFLOW;
137  (Teuchos::dyn_cast<CVaRVector<Real> >(u)).setVaR(uvar);
138  if ( bc_ != Teuchos::null ) {
139  Teuchos::RCP<Vector<Real> > uvec = Teuchos::rcp_const_cast<Vector<Real> >(
140  (Teuchos::dyn_cast<CVaRVector<Real> >(u)).getVector());
141  bc_->setVectorToUpperBound(*uvec);
142  }
143  }
144 
146  (Teuchos::dyn_cast<CVaRVector<Real> >(l)).setVaR(0.0);
147  if ( bc_ != Teuchos::null ) {
148  Teuchos::RCP<Vector<Real> > lvec = Teuchos::rcp_const_cast<Vector<Real> >(
149  (Teuchos::dyn_cast<CVaRVector<Real> >(l)).getVector());
150  bc_->setVectorToLowerBound(*lvec);
151  }
152  }
153 
154  void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
155  Real xvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x)).getVaR();
156  if ( xvar <= eps ) {
157  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).setVaR(0.0);
158  }
159  if ( bc_ != Teuchos::null ) {
160  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
161  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
162  Teuchos::RCP<const Vector<Real> > xvec =
163  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
164  bc_->pruneActive(*vvec,*xvec,eps);
165  }
166  }
167 
168  void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
169  Real gvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g)).getVaR();
170  Real xvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x)).getVaR();
171  if ( xvar <= eps && gvar > 0.0 ) {
172  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).setVaR(0.0);
173  }
174  if ( bc_ != Teuchos::null ) {
175  Teuchos::RCP<Vector<Real> > vvec = Teuchos::rcp_const_cast<Vector<Real> >(
176  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
177  Teuchos::RCP<const Vector<Real> > gvec =
178  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
179  Teuchos::RCP<const Vector<Real> > xvec =
180  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
181  bc_->pruneActive(*vvec,*gvec,*xvec,eps);
182  }
183  }
184 
185  bool isFeasible( const Vector<Real> &v ) {
186  bool flag = false;
187  Real vvar = Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(v)).getVaR();
188  if ( bc_ != Teuchos::null ) {
189  Teuchos::RCP<const Vector<Real> > vvec
190  = (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(v))).getVector();
191  if ( bc_->isActivated() ) {
192  flag = ((bc_->isFeasible(*vvec)) && (vvar >= 0.0));
193  }
194  }
195  else {
196  if ( bc_->isActivated() ) {
197  flag = (vvar >= 0.0);
198  }
199  }
200  return flag;
201  }
202 
203 }; // class BPOEBoundConstraint
204 
205 } // namespace ROL
206 
207 #endif
void pruneActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -binding set.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the lower -binding set.
BPOEBoundConstraint(Teuchos::RCP< BoundConstraint< Real > > &bc)
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the upper -active set.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -active set.
void setVectorToUpperBound(Vector< Real > &u)
Set the input vector to the upper bound.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
const Real getVaR() const
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the upper -binding set.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
void setVectorToLowerBound(Vector< Real > &l)
Set the input vector to the lower bound.
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Provides the interface to apply upper and lower bound constraints.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the lower -active set.
static const double ROL_OVERFLOW
Platform-dependent maximum double.
Definition: ROL_Types.hpp:126
Teuchos::RCP< BoundConstraint< Real > > bc_