ROL
ROL_BoundConstraint_SimOpt.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_SIMOPT_H
45#define ROL_BOUND_CONSTRAINT_SIMOPT_H
46
48#include "ROL_Vector_SimOpt.hpp"
49#include "ROL_Types.hpp"
50#include <iostream>
51
68
69
70namespace ROL {
71
72template <class Real>
74private:
75 Ptr<BoundConstraint<Real>> bnd1_;
76 Ptr<BoundConstraint<Real>> bnd2_;
77
78public:
80
86 const Ptr<BoundConstraint<Real>> &bnd2)
87 : bnd1_(bnd1), bnd2_(bnd2) {
88 if ( bnd1_->isActivated() || bnd2_->isActivated() ) {
89 BoundConstraint<Real>::activate();
90 }
91 else {
92 BoundConstraint<Real>::deactivate();
93 }
94 }
95
105 Vector_SimOpt<Real> &xs = dynamic_cast<Vector_SimOpt<Real>&>(
106 dynamic_cast<Vector<Real>&>(x));
107 if ( bnd1_->isActivated() ) {
108 bnd1_->project(*(xs.get_1()));
109 }
110 if ( bnd2_->isActivated() ) {
111 bnd2_->project(*(xs.get_2()));
112 }
113 }
114
126 Vector_SimOpt<Real> &xs = dynamic_cast<Vector_SimOpt<Real>&>(
127 dynamic_cast<Vector<Real>&>(x));
128 if ( bnd1_->isActivated() ) {
129 bnd1_->projectInterior(*(xs.get_1()));
130 }
131 if ( bnd2_->isActivated() ) {
132 bnd2_->projectInterior(*(xs.get_2()));
133 }
134 }
135
147 void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
148 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(
149 dynamic_cast<Vector<Real>&>(v));
150 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(
151 dynamic_cast<const Vector<Real>&>(x));
152 if ( bnd1_->isActivated() ) {
153 bnd1_->pruneUpperActive(*(vs.get_1()),*(xs.get_1()),eps);
154 }
155 if ( bnd2_->isActivated() ) {
156 bnd2_->pruneUpperActive(*(vs.get_2()),*(xs.get_2()),eps);
157 }
158 }
159
173 void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
174 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(
175 dynamic_cast<Vector<Real>&>(v));
176 const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(
177 dynamic_cast<const Vector<Real>&>(g));
178 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(
179 dynamic_cast<const Vector<Real>&>(x));
180 if ( bnd1_->isActivated() ) {
181 bnd1_->pruneUpperActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
182 }
183 if ( bnd2_->isActivated() ) {
184 bnd2_->pruneUpperActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
185 }
186 }
187
199 void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
200 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(
201 dynamic_cast<Vector<Real>&>(v));
202 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(
203 dynamic_cast<const Vector<Real>&>(x));
204 if ( bnd1_->isActivated() ) {
205 bnd1_->pruneLowerActive(*(vs.get_1()),*(xs.get_1()),eps);
206 }
207 if ( bnd2_->isActivated() ) {
208 bnd2_->pruneLowerActive(*(vs.get_2()),*(xs.get_2()),eps);
209 }
210 }
211
225 void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
226 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(
227 dynamic_cast<Vector<Real>&>(v));
228 const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(
229 dynamic_cast<const Vector<Real>&>(g));
230 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(
231 dynamic_cast<const Vector<Real>&>(x));
232 if ( bnd1_->isActivated() ) {
233 bnd1_->pruneLowerActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
234 }
235 if ( bnd2_->isActivated() ) {
236 bnd2_->pruneLowerActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
237 }
238 }
239
240 const Ptr<const Vector<Real>> getLowerBound( void ) const {
241 const Ptr<const Vector<Real>> l1 = bnd1_->getLowerBound();
242 const Ptr<const Vector<Real>> l2 = bnd2_->getLowerBound();
243 return makePtr<Vector_SimOpt<Real>>( constPtrCast<Vector<Real>>(l1),
244 constPtrCast<Vector<Real>>(l2) );
245 }
246
247 const Ptr<const Vector<Real>> getUpperBound(void) const {
248 const Ptr<const Vector<Real>> u1 = bnd1_->getUpperBound();
249 const Ptr<const Vector<Real>> u2 = bnd2_->getUpperBound();
250 return makePtr<Vector_SimOpt<Real>>( constPtrCast<Vector<Real>>(u1),
251 constPtrCast<Vector<Real>>(u2) );
252 }
253
265 void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
266 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(
267 dynamic_cast<Vector<Real>&>(v));
268 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(
269 dynamic_cast<const Vector<Real>&>(x));
270 if ( bnd1_->isActivated() ) {
271 bnd1_->pruneActive(*(vs.get_1()),*(xs.get_1()),eps);
272 }
273 if ( bnd2_->isActivated() ) {
274 bnd2_->pruneActive(*(vs.get_2()),*(xs.get_2()),eps);
275 }
276 }
277
290 void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
291 Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
292 const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
293 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
294 if ( bnd1_->isActivated() ) {
295 bnd1_->pruneActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
296 }
297 if ( bnd2_->isActivated() ) {
298 bnd2_->pruneActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
299 }
300 }
301
307 bool isFeasible( const Vector<Real> &v ) {
308 const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
309 return (bnd1_->isFeasible(*(vs.get_1()))) && (bnd2_->isFeasible(*(vs.get_2())));
310 }
311
326 Vector_SimOpt<Real> &dvs = dynamic_cast<Vector_SimOpt<Real>&>(dv);
327 const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
328 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
329 const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
330 if ( bnd1_->isActivated() ) {
331 bnd1_->applyInverseScalingFunction(*(dvs.get_1()),*(vs.get_1()),*(xs.get_1()),*(gs.get_1()));
332 }
333 if ( bnd2_->isActivated() ) {
334 bnd2_->applyInverseScalingFunction(*(dvs.get_2()),*(vs.get_2()),*(xs.get_2()),*(gs.get_2()));
335 }
336 }
337
352 Vector_SimOpt<Real> &dvs = dynamic_cast<Vector_SimOpt<Real>&>(dv);
353 const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
354 const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
355 const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
356 if ( bnd1_->isActivated() ) {
357 bnd1_->applyScalingFunctionJacobian(*(dvs.get_1()),*(vs.get_1()),*(xs.get_1()),*(gs.get_1()));
358 }
359 if ( bnd2_->isActivated() ) {
360 bnd2_->applyScalingFunctionJacobian(*(dvs.get_2()),*(vs.get_2()),*(xs.get_2()),*(gs.get_2()));
361 }
362 }
363
364}; // class BoundConstraint
365
366} // namespace ROL
367
368#endif
Contains definitions of custom data types in ROL.
Ptr< BoundConstraint< Real > > bnd1_
const Ptr< const Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
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.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -active set.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
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.
Ptr< BoundConstraint< Real > > bnd2_
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply inverse scaling function.
void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
const Ptr< const Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the upper -binding set.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply scaling function Jacobian.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the lower -binding set.
void pruneActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0))
Set variables to zero if they correspond to the -binding set.
BoundConstraint_SimOpt(const Ptr< BoundConstraint< Real > > &bnd1, const Ptr< BoundConstraint< Real > > &bnd2)
Default constructor.
Defines the linear algebra or vector space interface for simulation-based optimization.
ROL::Ptr< const Vector< Real > > get_2() const
ROL::Ptr< const Vector< Real > > get_1() const
Defines the linear algebra or vector space interface.