44 #ifndef ROL_BOUND_CONSTRAINT_H 45 #define ROL_BOUND_CONSTRAINT_H 75 Teuchos::RCP<Vector<Real> >
x_lo_;
76 Teuchos::RCP<Vector<Real> >
x_up_;
84 class Shift :
public Elementwise::UnaryFunction<Real> {
92 class LogicalOr :
public Elementwise::BinaryFunction<Real> {
94 Real
apply(
const Real &x,
const Real &y )
const {
95 return (x==0.0 && y==0.0) ? 0.0 : 1.0;
99 class Product :
public Elementwise::BinaryFunction<Real> {
101 Real
apply(
const Real &x,
const Real &y )
const {
return x*y; }
118 x_lo_(x_lo), x_up_(x_up),scale_(scale),activated_(true) {
121 Teuchos::RCP<Vector<Real> > diff = x_up_->clone();
123 diff->axpy(-1.0,*x_lo_);
126 min_diff_ = diff->reduce(minimum_);
150 struct Lesser :
public Elementwise::BinaryFunction<Real> {
151 Real
apply(
const Real &x,
const Real &y)
const {
return x<y ? x : y; }
154 struct Greater :
public Elementwise::BinaryFunction<Real> {
155 Real
apply(
const Real &x,
const Real &y)
const {
return x>y ? x : y; }
176 Real epsn = std::min(scale_*eps,this->min_diff_);
182 Teuchos::RCP<Vector<Real> > mask = x.
clone();
184 mask->axpy(-1.0,*x_up_);
185 mask->applyUnary(shift);
187 struct Condition :
public Elementwise::UnaryFunction<Real> {
188 Real
apply(
const Real &x)
const {
189 return x>=0 ? 0.0 : 1.0;
193 mask->applyUnary(condition);
213 Real epsn = std::min(scale_*eps,this->min_diff_);
219 Teuchos::RCP<Vector<Real> > mask1 = x.
clone();
221 mask1->axpy(-1.0,*x_up_);
222 mask1->applyUnary(shift);
224 struct Condition1 :
public Elementwise::UnaryFunction<Real> {
225 Real
apply(
const Real &x)
const {
226 return x>=0 ? 0.0 : 1.0;
230 mask1->applyUnary(condition1);
232 struct Condition2 :
public Elementwise::UnaryFunction<Real> {
233 Real
apply(
const Real &x)
const {
234 return x < 0.0 ? 0.0 : 1.0;
238 Teuchos::RCP<Vector<Real> > mask2 = g.
clone();
241 mask2->applyUnary(condition2);
245 mask1->applyBinary(logicalOr,*mask2);
264 Real epsn = std::min(scale_*eps,this->min_diff_);
270 Teuchos::RCP<Vector<Real> > mask = x_lo_->clone();
273 mask->applyUnary(shift);
275 struct Condition:
public Elementwise::UnaryFunction<Real> {
276 Real
apply(
const Real &x)
const {
277 return x>=0 ? 0.0 : 1.0;
281 mask->applyUnary(condition);
302 Real epsn = std::min(scale_*eps,this->min_diff_);
308 Teuchos::RCP<Vector<Real> > mask1 = x_lo_->clone();
311 mask1->applyUnary(shift);
313 struct Condition1:
public Elementwise::UnaryFunction<Real> {
314 Real
apply(
const Real &x)
const {
315 return x>=0 ? 0.0 : 1.0;
319 mask1->applyUnary(condition1);
321 struct Condition2 :
public Elementwise::UnaryFunction<Real> {
322 Real
apply(
const Real &x)
const {
323 return x > 0.0 ? 0.0 : 1.0;
327 Teuchos::RCP<Vector<Real> > mask2 = g.
clone();
330 mask2->applyUnary(condition2);
334 mask1->applyBinary(logicalOr,*mask2);
397 if ( this->activated_ ) {
398 Teuchos::RCP<Vector<Real> > s = v.
clone();
403 Real uminusv = s->reduce(minimum_);
406 s->axpy(-1.0,*x_lo_);
408 Real vminusl = s->reduce(minimum_);
410 if( (uminusv<0) || (vminusl<0) ) {
449 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
455 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
461 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
477 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
483 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
489 Teuchos::RCP<Vector<Real> > tmp = v.
clone();
502 Teuchos::RCP<Vector<Real> > tmp = g.
clone();
bool activated_
Flag that determines whether or not the constraints are being used.
Elementwise::ReductionMin< Real > minimum_
Real apply(const Real &x) const
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
void activate(void)
Turn on bounds.
void pruneLowerInactive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
Real apply(const Real &x, const Real &y) const
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
Contains definitions of custom data types in ROL.
virtual 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.
void pruneLowerInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update bounds.
Teuchos::RCP< Vector< Real > > x_lo_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real apply(const Real &x, const Real &y) const
virtual void setVectorToUpperBound(Vector< Real > &u)
Set the input vector to the upper bound.
Defines the linear algebra or vector space interface.
virtual 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.
bool isActivated(void)
Check if bounds are on.
void pruneUpperInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
virtual 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 computeProjectedStep(Vector< Real > &v, const Vector< Real > &x)
Compute projected step.
void pruneInactive(Vector< Real > &v, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -inactive set.
virtual void setVectorToLowerBound(Vector< Real > &l)
Set the input vector to the lower bound.
Provides the interface to apply upper and lower bound constraints.
virtual ~BoundConstraint()
void computeProjectedGradient(Vector< Real > &g, const Vector< Real > &x)
Compute projected gradient.
BoundConstraint(const Teuchos::RCP< Vector< Real > > &x_lo, const Teuchos::RCP< Vector< Real > > &x_up, Real scale=1.0)
Default constructor.
virtual 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.
virtual 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.
virtual void set(const Vector &x)
Set where .
virtual 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 pruneUpperInactive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
void deactivate(void)
Turn off bounds.
Teuchos::RCP< Vector< Real > > x_up_
void pruneInactive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real eps=0.0)
Set variables to zero if they correspond to the -nonbinding set.
virtual bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
ROL::BoundConstraint::Product product