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  const Ptr<BoundConstraint<Real>> bnd1_, bnd2_;
76 
77 public:
79 
85  const Ptr<BoundConstraint<Real>> &bnd2)
86  : bnd1_(bnd1), bnd2_(bnd2) {
87  if ( bnd1_->isActivated() || bnd2_->isActivated() )
89  else
91  }
92 
101  bool optBnd = true)
102  : bnd1_(optBnd ? makePtr<BoundConstraint<Real>>() : bnd),
103  bnd2_(optBnd ? bnd : makePtr<BoundConstraint<Real>>()) {
104  if ( bnd1_->isActivated() || bnd2_->isActivated() )
106  else
108  }
109 
119  const Vector<Real> &x,
120  bool optBnd = true)
121  : bnd1_(optBnd ? makePtr<BoundConstraint<Real>>(x) : bnd),
122  bnd2_(optBnd ? bnd : makePtr<BoundConstraint<Real>>(x)) {
123  if ( bnd1_->isActivated() || bnd2_->isActivated() )
125  else
127  }
128 
137  void project( Vector<Real> &x ) {
138  Vector_SimOpt<Real> &xs = dynamic_cast<Vector_SimOpt<Real>&>(x);
139  if (bnd1_->isActivated()) bnd1_->project(*(xs.get_1()));
140  if (bnd2_->isActivated()) bnd2_->project(*(xs.get_2()));
141  }
142 
154  Vector_SimOpt<Real> &xs = dynamic_cast<Vector_SimOpt<Real>&>(x);
155  if (bnd1_->isActivated()) bnd1_->projectInterior(*(xs.get_1()));
156  if (bnd2_->isActivated()) bnd2_->projectInterior(*(xs.get_2()));
157  }
158 
170  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
171  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
172  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
173  if (bnd1_->isActivated()) bnd1_->pruneUpperActive(*(vs.get_1()),*(xs.get_1()),eps);
174  if (bnd2_->isActivated()) bnd2_->pruneUpperActive(*(vs.get_2()),*(xs.get_2()),eps);
175  }
176 
190  void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
191  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
192  const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
193  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
194  if (bnd1_->isActivated()) bnd1_->pruneUpperActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
195  if (bnd2_->isActivated()) bnd2_->pruneUpperActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
196  }
197 
209  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
210  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
211  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
212  if (bnd1_->isActivated()) bnd1_->pruneLowerActive(*(vs.get_1()),*(xs.get_1()),eps);
213  if (bnd2_->isActivated()) bnd2_->pruneLowerActive(*(vs.get_2()),*(xs.get_2()),eps);
214  }
215 
229  void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
230  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
231  const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
232  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
233  if (bnd1_->isActivated()) bnd1_->pruneLowerActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
234  if (bnd2_->isActivated()) bnd2_->pruneLowerActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
235  }
236 
237  const Ptr<const Vector<Real>> getLowerBound( void ) const {
238  const Ptr<const Vector<Real>> l1 = bnd1_->getLowerBound();
239  const Ptr<const Vector<Real>> l2 = bnd2_->getLowerBound();
240  return makePtr<Vector_SimOpt<Real>>( constPtrCast<Vector<Real>>(l1),
241  constPtrCast<Vector<Real>>(l2) );
242  }
243 
244  const Ptr<const Vector<Real>> getUpperBound(void) const {
245  const Ptr<const Vector<Real>> u1 = bnd1_->getUpperBound();
246  const Ptr<const Vector<Real>> u2 = bnd2_->getUpperBound();
247  return makePtr<Vector_SimOpt<Real>>( constPtrCast<Vector<Real>>(u1),
248  constPtrCast<Vector<Real>>(u2) );
249  }
250 
262  void pruneActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) {
263  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
264  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
265  if (bnd1_->isActivated()) bnd1_->pruneActive(*(vs.get_1()),*(xs.get_1()),eps);
266  if (bnd2_->isActivated()) bnd2_->pruneActive(*(vs.get_2()),*(xs.get_2()),eps);
267  }
268 
281  void pruneActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) {
282  Vector_SimOpt<Real> &vs = dynamic_cast<Vector_SimOpt<Real>&>(v);
283  const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
284  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
285  if (bnd1_->isActivated()) bnd1_->pruneActive(*(vs.get_1()),*(gs.get_1()),*(xs.get_1()),xeps,geps);
286  if (bnd2_->isActivated()) bnd2_->pruneActive(*(vs.get_2()),*(gs.get_2()),*(xs.get_2()),xeps,geps);
287  }
288 
294  bool isFeasible( const Vector<Real> &v ) {
295  const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
296  return (bnd1_->isFeasible(*(vs.get_1()))) && (bnd2_->isFeasible(*(vs.get_2())));
297  }
298 
312  void applyInverseScalingFunction(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const{
313  Vector_SimOpt<Real> &dvs = dynamic_cast<Vector_SimOpt<Real>&>(dv);
314  const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
315  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
316  const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
317  if (bnd1_->isActivated()) bnd1_->applyInverseScalingFunction(*(dvs.get_1()),*(vs.get_1()),*(xs.get_1()),*(gs.get_1()));
318  if (bnd2_->isActivated()) bnd2_->applyInverseScalingFunction(*(dvs.get_2()),*(vs.get_2()),*(xs.get_2()),*(gs.get_2()));
319  }
320 
334  void applyScalingFunctionJacobian(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const {
335  Vector_SimOpt<Real> &dvs = dynamic_cast<Vector_SimOpt<Real>&>(dv);
336  const Vector_SimOpt<Real> &vs = dynamic_cast<const Vector_SimOpt<Real>&>(v);
337  const Vector_SimOpt<Real> &xs = dynamic_cast<const Vector_SimOpt<Real>&>(x);
338  const Vector_SimOpt<Real> &gs = dynamic_cast<const Vector_SimOpt<Real>&>(g);
339  if (bnd1_->isActivated()) bnd1_->applyScalingFunctionJacobian(*(dvs.get_1()),*(vs.get_1()),*(xs.get_1()),*(gs.get_1()));
340  if (bnd2_->isActivated()) bnd2_->applyScalingFunctionJacobian(*(dvs.get_2()),*(vs.get_2()),*(xs.get_2()),*(gs.get_2()));
341  }
342 
343 }; // class BoundConstraint_SimOpt
344 
345 } // namespace ROL
346 
347 #endif
void pruneActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the -active set.
bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
ROL::Ptr< const Vector< Real > > get_2() const
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 pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0))
Set variables to zero if they correspond to the lower -active set.
BoundConstraint_SimOpt(const Ptr< BoundConstraint< Real >> &bnd, bool optBnd=true)
Constructor for single bound constraint.
Defines the linear algebra or vector space interface for simulation-based optimization.
Contains definitions of custom data types in ROL.
BoundConstraint_SimOpt(const Ptr< BoundConstraint< Real >> &bnd1, const Ptr< BoundConstraint< Real >> &bnd2)
Default constructor.
const Ptr< BoundConstraint< Real > > bnd2_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
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.
const Ptr< BoundConstraint< Real > > bnd1_
void projectInterior(Vector< Real > &x)
Project optimization variables into the interior of the feasible set.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply scaling function Jacobian.
const Ptr< const Vector< Real > > getLowerBound(void) const
Return the ref count pointer to the lower 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.
Provides the interface to apply upper and lower bound constraints.
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 applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const
Apply inverse scaling function.
void deactivate(void)
Turn off bounds.
void project(Vector< Real > &x)
Project optimization variables onto the bounds.
const Ptr< const Vector< Real > > getUpperBound(void) const
Return the ref count pointer to the upper bound vector.
ROL::Ptr< const Vector< Real > > get_1() const
BoundConstraint_SimOpt(const Ptr< BoundConstraint< Real >> &bnd, const Vector< Real > &x, bool optBnd=true)
Constructor for single bound constraint.