ROL
ROL_BoundConstraint_Def.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_BOUND_CONSTRAINT_DEF_H
45#define ROL_BOUND_CONSTRAINT_DEF_H
46
47namespace ROL {
48
49template<typename Real>
51 : Lactivated_(true), Uactivated_(true) {}
52
53template<typename Real>
55 : Lactivated_(false), Uactivated_(false) {
56 try {
57 lower_ = x.clone(); lower_->setScalar(ROL_NINF<Real>());
58 upper_ = x.clone(); upper_->setScalar(ROL_INF<Real>());
59 }
60 catch(std::exception &e) {
61 // Do nothing. If someone calls getLowerBound or getUpperBound,
62 // an exception will be thrown.
63 }
64}
65
66template<typename Real>
68 if (isActivated()) {
69 throw Exception::NotImplemented(">>> ROL::BoundConstraint::project: Not Implemented!");
70 }
71}
72
73template<typename Real>
75 if (isActivated()) {
76 throw Exception::NotImplemented(">>> ROL::BoundConstraint::projectInterior: Not Implemented!");
77 }
78}
79
80template<typename Real>
82 if (isUpperActivated()) {
83 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneUpperActive: Not Implemented!");
84 }
85}
86
87template<typename Real>
88void BoundConstraint<Real>::pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
89 if (isUpperActivated()) {
90 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneUpperActive: Not Implemented!");
91 }
92}
93
94template<typename Real>
96 if (isLowerActivated()) {
97 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneLowerActive: Not Implemented!");
98 }
99}
100
101template<typename Real>
102void BoundConstraint<Real>::pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
103 if (isLowerActivated()) {
104 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneLowerActive: Not Implemented!");
105 }
106}
107
108template<typename Real>
109const Ptr<const Vector<Real>> BoundConstraint<Real>::getLowerBound( void ) const {
110 if (lower_ != nullPtr) {
111 return lower_;
112 }
113 throw Exception::NotImplemented(">>> ROL::BoundConstraint::getLowerBound: Lower bound not provided!");
114}
115
116template<typename Real>
117const Ptr<const Vector<Real>> BoundConstraint<Real>::getUpperBound( void ) const {
118 if (upper_ != nullPtr) {
119 return upper_;
120 }
121 throw Exception::NotImplemented(">>> ROL::BoundConstraint::getUpperBound: Upper bound not provided!");
122}
123
124template<typename Real>
126 if (isActivated()) {
127 Ptr<Vector<Real>> Pv = v.clone();
128 Pv->set(v);
129 project(*Pv);
130 Pv->axpy(static_cast<Real>(-1),v);
131 Real diff = Pv->norm();
132 return (diff <= ROL_EPSILON<Real>());
133 }
134 return true;
135}
136
137template<typename Real>
139 Lactivated_ = true;
140}
141
142template<typename Real>
144 Uactivated_ = true;
145}
146
147template<typename Real>
149 activateLower();
150 activateUpper();
151}
152
153template<typename Real>
155 Lactivated_ = false;
156}
157
158template<typename Real>
160 Uactivated_ = false;
161}
162
163template<typename Real>
165 deactivateLower();
166 deactivateUpper();
167}
168
169template<typename Real>
171 return Lactivated_;
172}
173
174template<typename Real>
176 return Uactivated_;
177}
178
179template<typename Real>
181 return (isLowerActivated() || isUpperActivated());
182}
183
184template<typename Real>
186 if (isActivated()) {
187 pruneUpperActive(v,x,eps);
188 pruneLowerActive(v,x,eps);
189 }
190}
191
192template<typename Real>
193void BoundConstraint<Real>::pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
194 if (isActivated()) {
195 pruneUpperActive(v,g,x,xeps,geps);
196 pruneLowerActive(v,g,x,xeps,geps);
197 }
198}
199
200template<typename Real>
202 if (isLowerActivated()) {
203 const Real one(1);
204 Ptr<Vector<Real>> tmp = v.clone();
205 tmp->set(v);
206 pruneLowerActive(*tmp,x,eps);
207 v.axpy(-one,*tmp);
208 }
209}
210
211template<typename Real>
213 if (isUpperActivated()) {
214 const Real one(1);
215 Ptr<Vector<Real>> tmp = v.clone();
216 tmp->set(v);
217 pruneUpperActive(*tmp,x,eps);
218 v.axpy(-one,*tmp);
219 }
220}
221
222template<typename Real>
223void BoundConstraint<Real>::pruneLowerInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
224 if (isLowerActivated()) {
225 const Real one(1);
226 Ptr<Vector<Real>> tmp = v.clone();
227 tmp->set(v);
228 pruneLowerActive(*tmp,g,x,xeps,geps);
229 v.axpy(-one,*tmp);
230 }
231}
232
233template<typename Real>
234void BoundConstraint<Real>::pruneUpperInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
235 if (isUpperActivated()) {
236 const Real one(1);
237 Ptr<Vector<Real>> tmp = v.clone();
238 tmp->set(v);
239 pruneUpperActive(*tmp,g,x,xeps,geps);
240 v.axpy(-one,*tmp);
241 }
242}
243
244template<typename Real>
246 if (isActivated()) {
247 const Real one(1);
248 Ptr<Vector<Real>> tmp = v.clone();
249 tmp->set(v);
250 pruneActive(*tmp,x,eps);
251 v.axpy(-one,*tmp);
252 }
253}
254
255template<typename Real>
256void BoundConstraint<Real>::pruneInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
257 if (isActivated()) {
258 const Real one(1);
259 Ptr<Vector<Real>> tmp = v.clone();
260 tmp->set(v);
261 pruneActive(*tmp,g,x,xeps,geps);
262 v.axpy(-one,*tmp);
263 }
264}
265
266template<typename Real>
268 if (isActivated()) {
269 Ptr<Vector<Real>> tmp = g.clone();
270 tmp->set(g);
271 pruneActive(g,*tmp,x);
272 }
273}
274
275template<typename Real>
277 if (isActivated()) {
278 const Real one(1);
279 v.plus(x);
280 project(v);
281 v.axpy(-one,x);
282 }
283}
284
285} // namespace ROL
286
287#endif
virtual const Ptr< const Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
virtual bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
void computeProjectedStep(Vector< Real > &v, const Vector< Real > &x)
Compute projected step.
void pruneLowerInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -inactive set.
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -inactive set.
bool isLowerActivated(void) const
Check if lower bound are on.
void pruneUpperInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -inactive set.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -active set.
Ptr< Vector< Real > > upper_
virtual void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the upper -active set.
bool isActivated(void) const
Check if bounds are on.
virtual void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
void deactivateLower(void)
Turn off lower bound.
void activateLower(void)
Turn on lower bound.
void deactivateUpper(void)
Turn off upper bound.
void deactivate(void)
Turn off bounds.
virtual void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the lower -active set.
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
Ptr< Vector< Real > > lower_
void activate(void)
Turn on bounds.
void activateUpper(void)
Turn on upper bound.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
bool isUpperActivated(void) const
Check if upper bound are on.
virtual const Ptr< const Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153