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 
47 #include "ROL_BoundConstraint.hpp"
48 #include "ROL_Vector_SimOpt.hpp"
49 #include "ROL_Types.hpp"
50 #include <iostream>
51 
70 namespace ROL {
71 
72 template <class Real>
74 private:
75  ROL::Ptr<BoundConstraint<Real> > bnd1_;
76  ROL::Ptr<BoundConstraint<Real> > bnd2_;
77 
78 public:
80 
86  const ROL::Ptr<BoundConstraint<Real> > &bnd2)
87  : bnd1_(bnd1), bnd2_(bnd2) {
88  if ( bnd1_->isActivated() || bnd2_->isActivated() ) {
90  }
91  else {
93  }
94  }
95 
103  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
104  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
105  dynamic_cast<const ROL::Vector<Real>&>(x));
106  if ( bnd1_->isActivated() ) {
107  bnd1_->update(*(xs.get_1()),flag,iter);
108  }
109  if ( bnd2_->isActivated() ) {
110  bnd2_->update(*(xs.get_2()),flag,iter);
111  }
112  }
113 
122  void project( Vector<Real> &x ) {
124  dynamic_cast<ROL::Vector<Real>&>(x));
125  if ( bnd1_->isActivated() ) {
126  ROL::Ptr<Vector<Real> > x1 = xs.get_1()->clone(); x1->set(*(xs.get_1()));
127  bnd1_->project(*x1);
128  xs.set_1(*x1);
129  }
130  if ( bnd2_->isActivated() ) {
131  ROL::Ptr<Vector<Real> > x2 = xs.get_2()->clone(); x2->set(*(xs.get_2()));
132  bnd2_->project(*x2);
133  xs.set_2(*x2);
134  }
135  }
136 
149  dynamic_cast<ROL::Vector<Real>&>(x));
150  if ( bnd1_->isActivated() ) {
151  ROL::Ptr<Vector<Real> > x1 = xs.get_1()->clone(); x1->set(*(xs.get_1()));
152  bnd1_->projectInterior(*x1);
153  xs.set_1(*x1);
154  }
155  if ( bnd2_->isActivated() ) {
156  ROL::Ptr<Vector<Real> > x2 = xs.get_2()->clone(); x2->set(*(xs.get_2()));
157  bnd2_->projectInterior(*x2);
158  xs.set_2(*x2);
159  }
160  }
161 
168  bool checkMultipliers( const Vector<Real> &l, const Vector<Real> &x ) {
169  const ROL::Vector_SimOpt<Real> &ls = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
170  dynamic_cast<const ROL::Vector<Real>&>(l));
171  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
172  dynamic_cast<const ROL::Vector<Real>&>(x));
173  bool nn1 = true;
174  if ( bnd1_->isActivated() ) {
175  nn1 = bnd1_->checkMultipliers(*(ls.get_1()),*(xs.get_1()));
176  }
177  bool nn2 = true;
178  if ( bnd2_->isActivated() ) {
179  nn2 = bnd2_->checkMultipliers(*(ls.get_2()),*(xs.get_2()));
180  }
181  return (nn1 && nn2);
182  }
183 
195  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
197  dynamic_cast<ROL::Vector<Real>&>(v));
198  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
199  dynamic_cast<const ROL::Vector<Real>&>(x));
200  if ( bnd1_->isActivated() ) {
201  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
202  bnd1_->pruneUpperActive(*v1,*(xs.get_1()),eps);
203  vs.set_1(*v1);
204  }
205  if ( bnd2_->isActivated() ) {
206  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
207  bnd2_->pruneUpperActive(*v2,*(xs.get_2()),eps);
208  vs.set_2(*v2);
209  }
210  }
211 
225  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
227  dynamic_cast<ROL::Vector<Real>&>(v));
228  const ROL::Vector_SimOpt<Real> &gs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
229  dynamic_cast<const ROL::Vector<Real>&>(g));
230  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
231  dynamic_cast<const ROL::Vector<Real>&>(x));
232  if ( bnd1_->isActivated() ) {
233  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
234  bnd1_->pruneUpperActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
235  vs.set_1(*v1);
236  }
237  if ( bnd2_->isActivated() ) {
238  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
239  bnd2_->pruneUpperActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
240  vs.set_2(*v2);
241  }
242  }
243 
255  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
257  dynamic_cast<ROL::Vector<Real>&>(v));
258  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
259  dynamic_cast<const ROL::Vector<Real>&>(x));
260  if ( bnd1_->isActivated() ) {
261  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
262  bnd1_->pruneLowerActive(*v1,*(xs.get_1()),eps);
263  vs.set_1(*v1);
264  }
265  if ( bnd2_->isActivated() ) {
266  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
267  bnd2_->pruneLowerActive(*v2,*(xs.get_2()),eps);
268  vs.set_2(*v2);
269  }
270  }
271 
285  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
287  dynamic_cast<ROL::Vector<Real>&>(v));
288  const ROL::Vector_SimOpt<Real> &gs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
289  dynamic_cast<const ROL::Vector<Real>&>(g));
290  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
291  dynamic_cast<const ROL::Vector<Real>&>(x));
292  if ( bnd1_->isActivated() ) {
293  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
294  bnd1_->pruneLowerActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
295  vs.set_1(*v1);
296  }
297  if ( bnd2_->isActivated() ) {
298  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
299  bnd2_->pruneLowerActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
300  vs.set_2(*v2);
301  }
302  }
303 
304  const ROL::Ptr<const Vector<Real>> getLowerBound( void ) const {
305  const ROL::Ptr<const Vector<Real>> l1 = bnd1_->getLowerBound();
306  const ROL::Ptr<const Vector<Real>> l2 = bnd2_->getLowerBound();
307  return ROL::makePtr<Vector_SimOpt<Real>>( ROL::constPtrCast<Vector<Real>>(l1),
308  ROL::constPtrCast<Vector<Real>>(l2) );
309  }
310 
311  const ROL::Ptr<const Vector<Real>> getUpperBound(void) const {
312  const ROL::Ptr<const Vector<Real>> u1 = bnd1_->getUpperBound();
313  const ROL::Ptr<const Vector<Real>> u2 = bnd2_->getUpperBound();
314  return ROL::makePtr<Vector_SimOpt<Real>>( ROL::constPtrCast<Vector<Real>>(u1),
315  ROL::constPtrCast<Vector<Real>>(u2) );
316  }
317 
329  void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
331  dynamic_cast<ROL::Vector<Real>&>(v));
332  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(
333  dynamic_cast<const ROL::Vector<Real>&>(x));
334  if ( bnd1_->isActivated() ) {
335  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
336  bnd1_->pruneActive(*v1,*(xs.get_1()),eps);
337  vs.set_1(*v1);
338  }
339  if ( bnd2_->isActivated() ) {
340  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
341  bnd2_->pruneActive(*v2,*(xs.get_2()),eps);
342  vs.set_2(*v2);
343  }
344  }
345 
358  void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
359  ROL::Vector_SimOpt<Real> &vs = dynamic_cast<ROL::Vector_SimOpt<Real>&>(v);
360  const ROL::Vector_SimOpt<Real> &gs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(g);
361  const ROL::Vector_SimOpt<Real> &xs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(x);
362  if ( bnd1_->isActivated() ) {
363  ROL::Ptr<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
364  bnd1_->pruneActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
365  vs.set_1(*v1);
366  }
367  if ( bnd2_->isActivated() ) {
368  ROL::Ptr<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
369  bnd2_->pruneActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
370  vs.set_2(*v2);
371  }
372  }
373 
379  bool isFeasible( const Vector<Real> &v ) {
380  const ROL::Vector_SimOpt<Real> &vs = dynamic_cast<const ROL::Vector_SimOpt<Real>&>(v);
381  return (bnd1_->isFeasible(*(vs.get_1()))) && (bnd2_->isFeasible(*(vs.get_2())));
382  }
383 
384 }; // class BoundConstraint
385 
386 } // namespace ROL
387 
388 #endif
Contains definitions of custom data types in ROL.
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.
bool checkMultipliers(const Vector< Real > &l, const Vector< Real > &x)
Determine if a vector of Lagrange multipliers is nonnegative components.
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -active set.
ROL::Ptr< BoundConstraint< Real > > bnd2_
const ROL::Ptr< const Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
ROL::Ptr< BoundConstraint< Real > > bnd1_
BoundConstraint_SimOpt(const ROL::Ptr< BoundConstraint< Real > > &bnd1, const ROL::Ptr< BoundConstraint< Real > > &bnd2)
Default constructor.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
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 update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
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.
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 projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
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.
const ROL::Ptr< const Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower bound vector.
Provides the interface to apply upper and lower bound constraints.
void deactivate(void)
Turn off bounds.
void activate(void)
Turn on bounds.
Defines the linear algebra or vector space interface for simulation-based optimization.
ROL::Ptr< const Vector< Real > > get_1() const
ROL::Ptr< const Vector< Real > > get_2() const
void set_1(const Vector< Real > &vec)
void set_2(const Vector< Real > &vec)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84