44 #ifndef ROL_BOUNDS_DEF_H 45 #define ROL_BOUNDS_DEF_H 58 template<
typename Real>
60 : scale_(scale), feasTol_(feasTol), mask_(x.clone()), min_diff_(
ROL_INF<Real>()) {
65 upper_->applyUnary(Elementwise::Fill<Real>(ROL_INF<Real>()));
69 lower_->applyUnary(Elementwise::Fill<Real>(ROL_NINF<Real>()));
75 template<
typename Real>
77 const Real scale,
const Real feasTol)
78 : scale_(scale), feasTol_(feasTol), mask_(x_lo->clone()) {
81 const Real half(0.5), one(1);
90 template<
typename Real>
92 struct Lesser :
public Elementwise::BinaryFunction<Real> {
93 Real
apply(
const Real &xc,
const Real &yc)
const {
return xc<yc ? xc : yc; }
96 struct Greater :
public Elementwise::BinaryFunction<Real> {
97 Real
apply(
const Real &xc,
const Real &yc)
const {
return xc>yc ? xc : yc; }
108 template<
typename Real>
113 class LowerFeasible :
public Elementwise::BinaryFunction<Real> {
118 LowerFeasible(
const Real eps,
const Real diff)
119 : eps_(eps), diff_(diff) {}
120 Real
apply(
const Real &x,
const Real &y )
const {
121 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
123 Real val = ((y <-tol) ? y*(one-eps_)
124 : ((y > tol) ? y*(one+eps_)
126 val = std::min(y+eps_*diff_, val);
127 return (x < y+tol) ? val : x;
130 x.
applyBinary(LowerFeasible(feasTol_,min_diff_), *lower_);
134 class UpperFeasible :
public Elementwise::BinaryFunction<Real> {
139 UpperFeasible(
const Real eps,
const Real diff)
140 : eps_(eps), diff_(diff) {}
141 Real
apply(
const Real &x,
const Real &y )
const {
142 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
144 Real val = ((y <-tol) ? y*(one+eps_)
145 : ((y > tol) ? y*(one-eps_)
147 val = std::max(y-eps_*diff_, val);
148 return (x > y-tol) ? val : x;
151 x.
applyBinary(UpperFeasible(feasTol_,min_diff_), *upper_);
155 template<
typename Real>
158 Real one(1), epsn(std::min(scale_*eps,static_cast<Real>(0.1)*min_diff_));
168 template<
typename Real>
171 Real one(1), epsn(std::min(scale_*xeps,static_cast<Real>(0.1)*min_diff_));
177 mask_->applyBinary(op,g);
183 template<
typename Real>
186 Real one(1), epsn(std::min(scale_*eps,static_cast<Real>(0.1)*min_diff_));
189 mask_->axpy(-one,*lower_);
196 template<
typename Real>
199 Real one(1), epsn(std::min(scale_*xeps,static_cast<Real>(0.1)*min_diff_));
202 mask_->axpy(-one,*lower_);
205 mask_->applyBinary(op,g);
211 template<
typename Real>
214 bool flagU =
false, flagL =
false;
218 Real uminusv = mask_->reduce(minimum_);
219 flagU = ((uminusv<0) ?
true :
false);
223 mask_->axpy(-one,*lower_);
224 Real vminusl = mask_->reduce(minimum_);
226 flagL = ((vminusl<0) ?
true :
false);
228 return ((flagU || flagL) ? false :
true);
Ptr< Vector< Real > > upper_
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void activateLower(void)
Turn on lower bound.
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
void pruneUpperActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0)) override
Set variables to zero if they correspond to the upper -active set.
Defines the linear algebra or vector space interface.
void project(Vector< Real > &x) override
Project optimization variables onto the bounds.
Elementwise::ReductionMin< Real > minimum_
void activateUpper(void)
Turn on upper bound.
Ptr< Vector< Real > > lower_
bool isFeasible(const Vector< Real > &v) override
Check if the vector, v, is feasible.
Provides the interface to apply upper and lower bound constraints.
ROL::DiagonalOperator apply
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=1e-2)
Ptr< Vector< Real > > mask_
void projectInterior(Vector< Real > &x) override
Project optimization variables into the interior of the feasible set.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &x, Real eps=Real(0)) override
Set variables to zero if they correspond to the lower -active set.