10 #ifndef ROL_BOUNDS_DEF_H
11 #define ROL_BOUNDS_DEF_H
24 template<
typename Real>
26 : scale_(scale), feasTol_(feasTol), mask_(x.clone()), min_diff_(
ROL_INF<Real>()) {
41 template<
typename Real>
43 const Real scale,
const Real feasTol)
44 : scale_(scale), feasTol_(feasTol), mask_(x_lo->clone()) {
47 const Real half(0.5), one(1);
56 template<
typename Real>
58 struct Lesser :
public Elementwise::BinaryFunction<Real> {
59 Real
apply(
const Real &xc,
const Real &yc)
const {
return xc<yc ? xc : yc; }
62 struct Greater :
public Elementwise::BinaryFunction<Real> {
63 Real
apply(
const Real &xc,
const Real &yc)
const {
return xc>yc ? xc : yc; }
74 template<
typename Real>
79 class LowerFeasible :
public Elementwise::BinaryFunction<Real> {
84 LowerFeasible(
const Real eps,
const Real diff)
85 : eps_(eps), diff_(diff) {}
86 Real
apply(
const Real &xc,
const Real &yc )
const {
87 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
89 Real val = ((yc <-tol) ? yc*(one-eps_)
90 : ((yc > tol) ? yc*(one+eps_)
92 val = std::min(yc+eps_*diff_, val);
93 return xc < val ? val : xc;
96 x.
applyBinary(LowerFeasible(feasTol_,min_diff_), *lower_);
100 class UpperFeasible :
public Elementwise::BinaryFunction<Real> {
105 UpperFeasible(
const Real eps,
const Real diff)
106 : eps_(eps), diff_(diff) {}
107 Real
apply(
const Real &xc,
const Real &yc )
const {
108 const Real tol =
static_cast<Real
>(100)*ROL_EPSILON<Real>();
110 Real val = ((yc <-tol) ? yc*(one+eps_)
111 : ((yc > tol) ? yc*(one-eps_)
113 val = std::max(yc-eps_*diff_, val);
114 return xc > val ? val : xc;
117 x.
applyBinary(UpperFeasible(feasTol_,min_diff_), *upper_);
121 template<
typename Real>
124 Real one(1), epsn(std::min(scale_*eps,static_cast<Real>(0.1)*min_diff_));
134 template<
typename Real>
137 Real one(1), epsn(std::min(scale_*xeps,static_cast<Real>(0.1)*min_diff_));
143 mask_->applyBinary(op,g);
149 template<
typename Real>
152 Real one(1), epsn(std::min(scale_*eps,static_cast<Real>(0.1)*min_diff_));
155 mask_->axpy(-one,*lower_);
162 template<
typename Real>
165 Real one(1), epsn(std::min(scale_*xeps,static_cast<Real>(0.1)*min_diff_));
168 mask_->axpy(-one,*lower_);
171 mask_->applyBinary(op,g);
177 template<
typename Real>
179 const Real half(0.5);
180 bool flagU =
false, flagL =
false;
183 mask_->applyBinary(isGreater_,*upper_);
184 flagU = mask_->reduce(maximum_) > half ?
true :
false;
188 mask_->applyBinary(isGreater_,v);
189 flagL = mask_->reduce(maximum_) > half ?
true :
false;
191 return ((flagU || flagL) ?
false :
true);
194 template<
typename Real>
198 const Real
zero(0), one(1);
210 d.
axpy(-one,*upper_);
213 d.
axpy(-one,*lower_);
216 mask_->axpy(-one,*lower_);
217 mask_->applyBinary(Elementwise::Min<Real>(),g);
219 mask_->axpy(-one,*upper_);
222 mask_->applyBinary(Elementwise::Min<Real>(),d);
226 mask_->setScalar(one);
231 mask_->applyUnary(Elementwise::AbsoluteValue<Real>());
232 d.
applyBinary(Elementwise::Multiply<Real>(),*mask_);
239 mask_->axpy(-one,*lower_);
241 mask_->applyBinary(Elementwise::Min<Real>(),*upper_);
249 mask_->axpy(-one,*lower_);
250 mask_->applyUnary(buildC_);
254 template<
typename Real>
257 dv.
applyBinary(Elementwise::DivideAndInvert<Real>(),v);
260 template<
typename Real>
262 const Real one(1), two(2), three(3);
269 mask_->axpy(-one,*lower_);
270 mask_->applyUnary(buildC_);
271 mask_->axpy(-one,dv);
275 mask_->setScalar(three);
276 dv.
applyBinary(Elementwise::Multiply<Real>(),*mask_);
277 dv.
axpy(-one,*mask_);
281 mask_->applyUnary(Elementwise::Sign<Real>());
286 mask_->plus(*lower_);
288 mask_->applyUnary(Elementwise::Sign<Real>());
292 mask_->setScalar(one);
Ptr< Vector< Real > > upper_
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void plus(const Vector &x)=0
Compute , where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
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.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
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_
virtual void setScalar(const Real C)
Set where .
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=std::sqrt(ROL_EPSILON< Real >()))
void buildScalingFunction(Vector< Real > &d, const Vector< Real > &x, const Vector< Real > &g) const
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
virtual void set(const Vector &x)
Set where .
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
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.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply scaling function Jacobian.