44#ifndef ROL_BOUNDS_DEF_H
45#define ROL_BOUNDS_DEF_H
58template<
typename Real>
60 : scale_(scale), feasTol_(feasTol), mask_(x.clone()), min_diff_(
ROL_INF<Real>()) {
75template<
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);
90template<
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; }
108template<
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 < val ? 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 > val ? val : x;
151 x.
applyBinary(UpperFeasible(feasTol_,min_diff_), *upper_);
155template<
typename Real>
158 Real one(1), epsn(std::min(scale_*eps,
static_cast<Real
>(0.1)*min_diff_));
168template<
typename Real>
171 Real one(1), epsn(std::min(scale_*xeps,
static_cast<Real
>(0.1)*min_diff_));
177 mask_->applyBinary(op,g);
183template<
typename Real>
186 Real one(1), epsn(std::min(scale_*eps,
static_cast<Real
>(0.1)*min_diff_));
189 mask_->axpy(-one,*lower_);
196template<
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);
211template<
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);
231template<
typename Real>
235 const Real
zero(0), one(1);
247 d.
axpy(-one,*upper_);
250 d.
axpy(-one,*lower_);
253 mask_->axpy(-one,*lower_);
254 mask_->applyBinary(Elementwise::Min<Real>(),g);
256 mask_->axpy(-one,*upper_);
259 mask_->applyBinary(Elementwise::Min<Real>(),d);
263 mask_->setScalar(one);
268 mask_->applyUnary(Elementwise::AbsoluteValue<Real>());
269 d.
applyBinary(Elementwise::Multiply<Real>(),*mask_);
276 mask_->axpy(-one,*lower_);
278 mask_->applyBinary(Elementwise::Min<Real>(),*upper_);
286 mask_->axpy(-one,*lower_);
287 mask_->applyUnary(buildC_);
291template<
typename Real>
294 dv.
applyBinary(Elementwise::DivideAndInvert<Real>(),v);
297template<
typename Real>
299 const Real one(1), two(2), three(3);
306 mask_->axpy(-one,*lower_);
307 mask_->applyUnary(buildC_);
308 mask_->axpy(-one,dv);
312 mask_->setScalar(three);
313 dv.
applyBinary(Elementwise::Multiply<Real>(),*mask_);
314 dv.
axpy(-one,*mask_);
318 mask_->applyUnary(Elementwise::Sign<Real>());
323 mask_->plus(*lower_);
325 mask_->applyUnary(Elementwise::Sign<Real>());
329 mask_->setScalar(one);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides the interface to apply upper and lower bound constraints.
Ptr< Vector< Real > > upper_
void activateLower(void)
Turn on lower bound.
Ptr< Vector< Real > > lower_
void activateUpper(void)
Turn on upper bound.
Elementwise::ReductionMin< Real > minimum_
void buildScalingFunction(Vector< Real > &d, const Vector< Real > &x, const Vector< Real > &g) const
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
void project(Vector< Real > &x) override
Project optimization variables onto the bounds.
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.
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.
Ptr< Vector< Real > > mask_
void projectInterior(Vector< Real > &x) override
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 override
Apply scaling function Jacobian.
Bounds(const Vector< Real > &x, bool isLower=true, Real scale=1, Real feasTol=std::sqrt(ROL_EPSILON< Real >()))
bool isFeasible(const Vector< Real > &v) override
Check if the vector, v, is feasible.
Defines the linear algebra or vector space interface.
virtual void set(const Vector &x)
Set where .
virtual void setScalar(const Real C)
Set where .
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
virtual void plus(const Vector &x)=0
Compute , where .
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
ROL::BlockOperator2Diagonal BlockOperator2 apply(V &Hv, const V &v, Real &tol) const