ROL
ROL_CVaRBoundConstraint.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_CVAR_BOUND_CONSTRAINT_H
45 #define ROL_CVAR_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 CVaRBoundConstraint : public BoundConstraint<Real> {
54 private:
55  Teuchos::RCP<BoundConstraint<Real> > bc_;
56 
57 public:
58  CVaRBoundConstraint(Teuchos::RCP<BoundConstraint<Real> > &bc) : BoundConstraint<Real>(), bc_(bc) {}
59 
60  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
61  Teuchos::RCP<const Vector<Real> > xv =
62  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
63  bc_->update(*xv,flag,iter);
64  }
65 
66  void project( Vector<Real> &x ) {
67  Teuchos::RCP<Vector<Real> > xv = Teuchos::rcp_const_cast<Vector<Real> >(
68  (Teuchos::dyn_cast<CVaRVector<Real> >(x)).getVector());
69  bc_->project(*xv);
70  }
71 
72  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
73  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
74  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
75  Teuchos::RCP<const Vector<Real> > xv =
76  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
77  bc_->pruneUpperActive(*vv,*xv,eps);
78  }
79 
80  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
81  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
82  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
83  Teuchos::RCP<const Vector<Real> > gv =
84  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
85  Teuchos::RCP<const Vector<Real> > xv =
86  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
87  bc_->pruneUpperActive(*vv,*gv,*xv,eps);
88  }
89 
90  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
91  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
92  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
93  Teuchos::RCP<const Vector<Real> > xv =
94  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
95  bc_->pruneLowerActive(*vv,*xv,eps);
96  }
97 
98  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
99  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
100  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
101  Teuchos::RCP<const Vector<Real> > gv =
102  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
103  Teuchos::RCP<const Vector<Real> > xv =
104  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
105  bc_->pruneLowerActive(*vv,*gv,*xv,eps);
106 }
107 
109  Teuchos::RCP<Vector<Real> > uv = Teuchos::rcp_const_cast<Vector<Real> >(
110  (Teuchos::dyn_cast<CVaRVector<Real> >(u)).getVector());
111  bc_->setVectorToUpperBound(*uv);
112  Real uvar = 0.1*ROL_OVERFLOW;
113  (Teuchos::dyn_cast<CVaRVector<Real> >(u)).setVaR(uvar);
114  }
115 
117  Teuchos::RCP<Vector<Real> > lv = Teuchos::rcp_const_cast<Vector<Real> >(
118  (Teuchos::dyn_cast<CVaRVector<Real> >(l)).getVector());
119  bc_->setVectorToLowerBound(*lv);
120  Real lvar = -0.1*ROL_OVERFLOW;
121  (Teuchos::dyn_cast<CVaRVector<Real> >(l)).setVaR(lvar);
122  }
123 
124  void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
125  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
126  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
127  Teuchos::RCP<const Vector<Real> > xv =
128  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
129  bc_->pruneActive(*vv,*xv,eps);
130  }
131 
132  void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
133  Teuchos::RCP<Vector<Real> > vv = Teuchos::rcp_const_cast<Vector<Real> >(
134  (Teuchos::dyn_cast<CVaRVector<Real> >(v)).getVector());
135  Teuchos::RCP<const Vector<Real> > gv =
136  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(g))).getVector();
137  Teuchos::RCP<const Vector<Real> > xv =
138  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(x))).getVector();
139  bc_->pruneActive(*vv,*gv,*xv,eps);
140  }
141 
142  bool isFeasible( const Vector<Real> &v ) {
143  Teuchos::RCP<const Vector<Real> > vv =
144  (Teuchos::dyn_cast<CVaRVector<Real> >(const_cast<Vector<Real> &>(v))).getVector();
145  if ( bc_->isActivated() ) {
146  return bc_->isFeasible(*vv);
147  }
148  else {
149  return false;
150  }
151  }
152 
153 }; // class CVaRBoundConstraint
154 
155 } // namespace ROL
156 
157 #endif
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.
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.
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
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.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
Teuchos::RCP< BoundConstraint< Real > > bc_
Provides the interface to apply upper and lower bound constraints.
CVaRBoundConstraint(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 > &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.
static const double ROL_OVERFLOW
Platform-dependent maximum double.
Definition: ROL_Types.hpp:123
void setVectorToLowerBound(Vector< Real > &l)
Set the input vector to the lower bound.