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 int dim = x.dimension();
52 Real denom = (dim > 0 ? static_cast<Real>(dim) : 1e15);
53 return std::sqrt(ROL_INF<Real>() / denom);
54}
55
56template<typename Real>
58 : Lactivated_(true), Uactivated_(true) {}
59
60template<typename Real>
62 : Lactivated_(false), Uactivated_(false) {
63 try {
64 lower_ = x.clone(); lower_->setScalar(-computeInf(x));
65 upper_ = x.clone(); upper_->setScalar( computeInf(x));
66 }
67 catch(std::exception &e) {
68 // Do nothing. If someone calls getLowerBound or getUpperBound,
69 // an exception will be thrown.
70 }
71}
72
73template<typename Real>
75 if (isActivated()) {
76 throw Exception::NotImplemented(">>> ROL::BoundConstraint::project: Not Implemented!");
77 }
78}
79
80template<typename Real>
82 if (isActivated()) {
83 throw Exception::NotImplemented(">>> ROL::BoundConstraint::projectInterior: Not Implemented!");
84 }
85}
86
87template<typename Real>
89 if (isUpperActivated()) {
90 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneUpperActive: Not Implemented!");
91 }
92}
93
94template<typename Real>
95void BoundConstraint<Real>::pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
96 if (isUpperActivated()) {
97 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneUpperActive: Not Implemented!");
98 }
99}
100
101template<typename Real>
103 if (isLowerActivated()) {
104 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneLowerActive: Not Implemented!");
105 }
106}
107
108template<typename Real>
109void BoundConstraint<Real>::pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
110 if (isLowerActivated()) {
111 throw Exception::NotImplemented(">>> ROL::BoundConstraint::pruneLowerActive: Not Implemented!");
112 }
113}
114
115template<typename Real>
116const Ptr<const Vector<Real>> BoundConstraint<Real>::getLowerBound( void ) const {
117 if (lower_ != nullPtr) {
118 return lower_;
119 }
120 throw Exception::NotImplemented(">>> ROL::BoundConstraint::getLowerBound: Lower bound not provided!");
121}
122
123template<typename Real>
124const Ptr<const Vector<Real>> BoundConstraint<Real>::getUpperBound( void ) const {
125 if (upper_ != nullPtr) {
126 return upper_;
127 }
128 throw Exception::NotImplemented(">>> ROL::BoundConstraint::getUpperBound: Upper bound not provided!");
129}
130
131template<typename Real>
133 if (isActivated()) {
134 Ptr<Vector<Real>> Pv = v.clone();
135 Pv->set(v);
136 project(*Pv);
137 Pv->axpy(static_cast<Real>(-1),v);
138 Real diff = Pv->norm();
139 return (diff <= ROL_EPSILON<Real>());
140 }
141 return true;
142}
143
144template<typename Real>
146 throw Exception::NotImplemented(">>> BoundConstraint::applyInverseScalingFunction : This function has not been implemeted!");
147}
148
149template<typename Real>
151 throw Exception::NotImplemented(">>> BoundConstraint::applyScalingFunctionJacobian : This function has not been implemeted!");
152}
153
154template<typename Real>
156 Lactivated_ = true;
157}
158
159template<typename Real>
161 Uactivated_ = true;
162}
163
164template<typename Real>
166 activateLower();
167 activateUpper();
168}
169
170template<typename Real>
172 Lactivated_ = false;
173}
174
175template<typename Real>
177 Uactivated_ = false;
178}
179
180template<typename Real>
182 deactivateLower();
183 deactivateUpper();
184}
185
186template<typename Real>
188 return Lactivated_;
189}
190
191template<typename Real>
193 return Uactivated_;
194}
195
196template<typename Real>
198 return (isLowerActivated() || isUpperActivated());
199}
200
201template<typename Real>
203 if (isActivated()) {
204 pruneUpperActive(v,x,eps);
205 pruneLowerActive(v,x,eps);
206 }
207}
208
209template<typename Real>
210void BoundConstraint<Real>::pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
211 if (isActivated()) {
212 pruneUpperActive(v,g,x,xeps,geps);
213 pruneLowerActive(v,g,x,xeps,geps);
214 }
215}
216
217template<typename Real>
219 if (isLowerActivated()) {
220 const Real one(1);
221 Ptr<Vector<Real>> tmp = v.clone();
222 tmp->set(v);
223 pruneLowerActive(*tmp,x,eps);
224 v.axpy(-one,*tmp);
225 }
226}
227
228template<typename Real>
230 if (isUpperActivated()) {
231 const Real one(1);
232 Ptr<Vector<Real>> tmp = v.clone();
233 tmp->set(v);
234 pruneUpperActive(*tmp,x,eps);
235 v.axpy(-one,*tmp);
236 }
237}
238
239template<typename Real>
240void BoundConstraint<Real>::pruneLowerInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
241 if (isLowerActivated()) {
242 const Real one(1);
243 Ptr<Vector<Real>> tmp = v.clone();
244 tmp->set(v);
245 pruneLowerActive(*tmp,g,x,xeps,geps);
246 v.axpy(-one,*tmp);
247 }
248}
249
250template<typename Real>
251void BoundConstraint<Real>::pruneUpperInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
252 if (isUpperActivated()) {
253 const Real one(1);
254 Ptr<Vector<Real>> tmp = v.clone();
255 tmp->set(v);
256 pruneUpperActive(*tmp,g,x,xeps,geps);
257 v.axpy(-one,*tmp);
258 }
259}
260
261template<typename Real>
263 if (isActivated()) {
264 const Real one(1);
265 Ptr<Vector<Real>> tmp = v.clone();
266 tmp->set(v);
267 pruneActive(*tmp,x,eps);
268 v.axpy(-one,*tmp);
269 }
270}
271
272template<typename Real>
273void BoundConstraint<Real>::pruneInactive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps, Real geps ) {
274 if (isActivated()) {
275 const Real one(1);
276 Ptr<Vector<Real>> tmp = v.clone();
277 tmp->set(v);
278 pruneActive(*tmp,g,x,xeps,geps);
279 v.axpy(-one,*tmp);
280 }
281}
282
283template<typename Real>
285 if (isActivated()) {
286 Ptr<Vector<Real>> tmp = g.clone();
287 tmp->set(g);
288 pruneActive(g,*tmp,x);
289 }
290}
291
292template<typename Real>
294 if (isActivated()) {
295 const Real one(1);
296 v.plus(x);
297 project(v);
298 v.axpy(-one,x);
299 }
300}
301
302} // namespace ROL
303
304#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 applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply inverse scaling function.
Real computeInf(const Vector< Real > &x) const
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.
virtual void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply scaling function Jacobian.
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.
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual int dimension() const
Return dimension of the vector space.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
constexpr auto dim