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  Teuchos::RCP<BoundConstraint<Real> > bnd1_;
76  Teuchos::RCP<BoundConstraint<Real> > bnd2_;
77 
78 public:
80 
85  BoundConstraint_SimOpt(const Teuchos::RCP<BoundConstraint<Real> > &bnd1,
86  const Teuchos::RCP<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 = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
105  Teuchos::dyn_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 ) {
123  ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
124  Teuchos::dyn_cast<ROL::Vector<Real> >(x));
125  if ( bnd1_->isActivated() ) {
126  Teuchos::RCP<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  Teuchos::RCP<Vector<Real> > x2 = xs.get_2()->clone(); x2->set(*(xs.get_2()));
132  bnd2_->project(*x2);
133  xs.set_2(*x2);
134  }
135  }
136 
143  bool checkMultipliers( const Vector<Real> &l, const Vector<Real> &x ) {
144  const ROL::Vector_SimOpt<Real> &ls = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
145  Teuchos::dyn_cast<const ROL::Vector<Real> >(l));
146  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
147  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
148  bool nn1 = true;
149  if ( bnd1_->isActivated() ) {
150  nn1 = bnd1_->checkMultipliers(*(ls.get_1()),*(xs.get_1()));
151  }
152  bool nn2 = true;
153  if ( bnd2_->isActivated() ) {
154  nn2 = bnd2_->checkMultipliers(*(ls.get_2()),*(xs.get_2()));
155  }
156  return (nn1 && nn2);
157  }
158 
170  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
171  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
172  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
173  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
174  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
175  if ( bnd1_->isActivated() ) {
176  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
177  bnd1_->pruneUpperActive(*v1,*(xs.get_1()),eps);
178  vs.set_1(*v1);
179  }
180  if ( bnd2_->isActivated() ) {
181  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
182  bnd2_->pruneUpperActive(*v2,*(xs.get_2()),eps);
183  vs.set_2(*v2);
184  }
185  }
186 
200  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
201  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
202  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
203  const ROL::Vector_SimOpt<Real> &gs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
204  Teuchos::dyn_cast<const ROL::Vector<Real> >(g));
205  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
206  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
207  if ( bnd1_->isActivated() ) {
208  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
209  bnd1_->pruneUpperActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
210  vs.set_1(*v1);
211  }
212  if ( bnd2_->isActivated() ) {
213  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
214  bnd2_->pruneUpperActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
215  vs.set_2(*v2);
216  }
217  }
218 
230  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
231  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
232  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
233  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
234  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
235  if ( bnd1_->isActivated() ) {
236  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
237  bnd1_->pruneLowerActive(*v1,*(xs.get_1()),eps);
238  vs.set_1(*v1);
239  }
240  if ( bnd2_->isActivated() ) {
241  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
242  bnd2_->pruneLowerActive(*v2,*(xs.get_2()),eps);
243  vs.set_2(*v2);
244  }
245  }
246 
260  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
261  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
262  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
263  const ROL::Vector_SimOpt<Real> &gs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
264  Teuchos::dyn_cast<const ROL::Vector<Real> >(g));
265  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
266  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
267  if ( bnd1_->isActivated() ) {
268  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
269  bnd1_->pruneLowerActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
270  vs.set_1(*v1);
271  }
272  if ( bnd2_->isActivated() ) {
273  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
274  bnd2_->pruneLowerActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
275  vs.set_2(*v2);
276  }
277  }
278 
279  const Teuchos::RCP<const Vector<Real> > getLowerVectorRCP( void ) const {
280  const Teuchos::RCP<const Vector<Real> > l1 = bnd1_->getLowerVectorRCP();
281  const Teuchos::RCP<const Vector<Real> > l2 = bnd2_->getLowerVectorRCP();
282  return Teuchos::rcp( new Vector_SimOpt<Real>( Teuchos::rcp_const_cast<Vector<Real> >(l1),
283  Teuchos::rcp_const_cast<Vector<Real> >(l2) ) );
284  }
285 
286  const Teuchos::RCP<const Vector<Real> > getUpperVectorRCP( void ) const {
287  const Teuchos::RCP<const Vector<Real> > u1 = bnd1_->getUpperVectorRCP();
288  const Teuchos::RCP<const Vector<Real> > u2 = bnd2_->getUpperVectorRCP();
289  return Teuchos::rcp( new Vector_SimOpt<Real>( Teuchos::rcp_const_cast<Vector<Real> >(u1),
290  Teuchos::rcp_const_cast<Vector<Real> >(u2) ) );
291  }
292 
293 
294 
301  ROL::Vector_SimOpt<Real> &us = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
302  Teuchos::dyn_cast<ROL::Vector<Real> >(u));
303  Teuchos::RCP<Vector<Real> > u1 = us.get_1()->clone();
304  Teuchos::RCP<Vector<Real> > u2 = us.get_2()->clone();
305  bnd1_->setVectorToUpperBound(*u1);
306  bnd2_->setVectorToUpperBound(*u2);
307  us.set_1(*u1);
308  us.set_2(*u2);
309  }
310 
317  ROL::Vector_SimOpt<Real> &ls = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
318  Teuchos::dyn_cast<ROL::Vector<Real> >(l));
319  Teuchos::RCP<Vector<Real> > l1 = ls.get_1()->clone();
320  Teuchos::RCP<Vector<Real> > l2 = ls.get_2()->clone();
321  bnd1_->setVectorToLowerBound(*l1);
322  bnd2_->setVectorToLowerBound(*l2);
323  ls.set_1(*l1);
324  ls.set_2(*l2);
325  }
326 
338  void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = 0.0 ) {
339  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
340  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
341  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
342  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
343  if ( bnd1_->isActivated() ) {
344  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
345  bnd1_->pruneActive(*v1,*(xs.get_1()),eps);
346  vs.set_1(*v1);
347  }
348  if ( bnd2_->isActivated() ) {
349  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
350  bnd2_->pruneActive(*v2,*(xs.get_2()),eps);
351  vs.set_2(*v2);
352  }
353  }
354 
367  void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real eps = 0.0 ) {
368  ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<ROL::Vector_SimOpt<Real> >(
369  Teuchos::dyn_cast<ROL::Vector<Real> >(v));
370  const ROL::Vector_SimOpt<Real> &gs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
371  Teuchos::dyn_cast<const ROL::Vector<Real> >(g));
372  const ROL::Vector_SimOpt<Real> &xs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
373  Teuchos::dyn_cast<const ROL::Vector<Real> >(x));
374  if ( bnd1_->isActivated() ) {
375  Teuchos::RCP<Vector<Real> > v1 = vs.get_1()->clone(); v1->set(*(vs.get_1()));
376  bnd1_->pruneActive(*v1,*(gs.get_1()),*(xs.get_1()),eps);
377  vs.set_1(*v1);
378  }
379  if ( bnd2_->isActivated() ) {
380  Teuchos::RCP<Vector<Real> > v2 = vs.get_2()->clone(); v2->set(*(vs.get_2()));
381  bnd2_->pruneActive(*v2,*(gs.get_2()),*(xs.get_2()),eps);
382  vs.set_2(*v2);
383  }
384  }
385 
391  bool isFeasible( const Vector<Real> &v ) {
392  const ROL::Vector_SimOpt<Real> &vs = Teuchos::dyn_cast<const ROL::Vector_SimOpt<Real> >(
393  Teuchos::dyn_cast<const ROL::Vector<Real> >(v));
394  return bnd1_->isFeasible(*(vs.get_1()))*bnd2_->isFeasible(*(vs.get_2()));
395  }
396 
397 }; // class BoundConstraint
398 
399 } // namespace ROL
400 
401 #endif
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
void setVectorToLowerBound(Vector< Real > &l)
Set the input vector to the lower bound.
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.
Defines the linear algebra or vector space interface for simulation-based optimization.
void activate(void)
Turn on 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.
Teuchos::RCP< const Vector< Real > > get_2() const
Contains definitions of custom data types in ROL.
void set_1(const Vector< Real > &vec)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
void setVectorToUpperBound(Vector< Real > &u)
Set the input vector to the upper bound.
bool checkMultipliers(const Vector< Real > &l, const Vector< Real > &x)
Determine if a vector of Lagrange multipliers is nonnegative components.
Teuchos::RCP< BoundConstraint< Real > > bnd1_
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 pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the upper -active set.
Teuchos::RCP< const Vector< Real > > get_1() const
BoundConstraint_SimOpt(const Teuchos::RCP< BoundConstraint< Real > > &bnd1, const Teuchos::RCP< BoundConstraint< Real > > &bnd2)
Default constructor.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
Provides the interface to apply upper and lower bound constraints.
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.
const Teuchos::RCP< const Vector< Real > > getUpperVectorRCP(void) const
Return the ref count pointer to the upper bound vector.
Teuchos::RCP< BoundConstraint< Real > > bnd2_
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 deactivate(void)
Turn off bounds.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
const Teuchos::RCP< const Vector< Real > > getLowerVectorRCP(void) const
Return the ref count pointer to the lower bound vector.
void set_2(const Vector< Real > &vec)