15 #ifndef ROL_STDBOUNDCONSTRAINT_DEF_HPP
16 #define ROL_STDBOUNDCONSTRAINT_DEF_HPP
22 : scale_(scale), feasTol_(feasTol), min_diff_(
ROL_INF<Real>()){
26 x_lo_.assign(x.begin(),x.end());
32 x_up_.assign(x.begin(),x.end());
36 lower_ = makePtr<StdVector<Real>>(makePtrFromRef(
x_lo_));
37 upper_ = makePtr<StdVector<Real>>(makePtrFromRef(
x_up_));
42 : x_lo_(l), x_up_(u), scale_(scale), feasTol_(feasTol) {
45 for (
int i = 0; i <
dim_; i++ ) {
55 lower_ = makePtr<StdVector<Real>>(makePtrFromRef(
x_lo_));
56 upper_ = makePtr<StdVector<Real>>(makePtrFromRef(
x_up_));
62 Ptr<std::vector<Real>> ex =
65 for (
int i = 0; i < dim_; ++i ) {
66 (*ex)[i] = std::max(x_lo_[i],(*ex)[i]);
70 for (
int i = 0; i < dim_; ++i ) {
71 (*ex)[i] = std::min(x_up_[i],(*ex)[i]);
80 Ptr<std::vector<Real>> ex =
82 const Real eps = feasTol_;
83 const Real tol = 100.0*ROL_EPSILON<Real>();
86 for (
int i = 0; i < dim_; ++i ) {
87 Real val = ((x_lo_[i] < -tol) ? (one-eps)*x_lo_[i]
88 : ((x_lo_[i] > tol) ? (one+eps)*x_lo_[i]
90 val = std::min(x_lo_[i]+eps*min_diff_, val);
91 (*ex)[i] = ((*ex)[i] < val) ? val : (*ex)[i];
95 for (
int i = 0; i < dim_; ++i ) {
96 Real val = ((x_up_[i] < -tol) ? (one+eps)*x_up_[i]
97 : ((x_up_[i] > tol) ? (one-eps)*x_up_[i]
99 val = std::max(x_up_[i]-eps*min_diff_, val);
100 (*ex)[i] = ((*ex)[i] > val) ? val : (*ex)[i];
109 Ptr<const std::vector<Real>> ex =
111 Ptr<std::vector<Real>> ev =
113 Real epsn = std::min(scale_*eps,min_diff_);
114 for (
int i = 0; i < dim_; ++i ) {
115 if ( ((*ex)[i] >= x_up_[i]-epsn) ) {
116 (*ev)[i] =
static_cast<Real
>(0);
125 Ptr<const std::vector<Real>> ex =
127 Ptr<const std::vector<Real>> eg =
129 Ptr<std::vector<Real>> ev =
131 Real epsn = std::min(scale_*xeps,min_diff_);
132 for (
int i = 0; i < dim_; ++i ) {
133 if ( (*ex)[i] >= x_up_[i]-epsn && (*eg)[i] < -geps ) {
134 (*ev)[i] =
static_cast<Real
>(0);
143 Ptr<const std::vector<Real>> ex =
145 Ptr<std::vector<Real>> ev =
147 Real epsn = std::min(scale_*eps,min_diff_);
148 for (
int i = 0; i < dim_; ++i ) {
149 if ( ((*ex)[i] <= x_lo_[i]+epsn) ) {
150 (*ev)[i] =
static_cast<Real
>(0);
159 Ptr<const std::vector<Real>> ex =
161 Ptr<const std::vector<Real>> eg =
163 Ptr<std::vector<Real>> ev =
165 Real epsn = std::min(scale_*xeps,this->min_diff_);
166 for (
int i = 0; i < dim_; ++i ) {
167 if ( (*ex)[i] <= x_lo_[i]+epsn && (*eg)[i] > geps ) {
168 (*ev)[i] =
static_cast<Real
>(0);
176 bool lflag =
true, uflag =
true;
178 Ptr<const std::vector<Real>> ex =
181 for (
int i = 0; i < dim_; ++i ) {
182 if ( (*ex)[i] < x_lo_[i] ) {
189 for (
int i = 0; i < dim_; ++i ) {
190 if ( (*ex)[i] > x_up_[i] ) {
197 return (lflag && uflag);
202 Ptr<std::vector<Real>> ed =
204 Ptr<const std::vector<Real>> ex =
206 Ptr<const std::vector<Real>> eg =
209 Real grad, lodiff, updiff, c;
211 for (
int i = 0; i < dim_; ++i ) {
213 lodiff = (*ex)[i] - x_lo_[i];
214 updiff = x_up_[i] - (*ex)[i];
216 if (-grad > lodiff) {
217 if (lodiff <= updiff) {
218 (*ed)[i] = std::min(std::abs(grad), c);
222 if (+grad > updiff) {
223 if (updiff <= lodiff) {
224 (*ed)[i] = std::min(std::abs(grad), c);
228 (*ed)[i] = std::min({lodiff, updiff, c});
234 buildScalingFunction(dv, x, g);
236 Ptr<std::vector<Real>> edv =
238 Ptr<const std::vector<Real>> ev =
241 for (
int i = 0; i < dim_; ++i ) {
242 (*edv)[i] = (*ev)[i]/(*edv)[i];
248 buildScalingFunction(dv, x, g);
250 Ptr<std::vector<Real>> edv =
252 Ptr<const std::vector<Real>> ev =
254 Ptr<const std::vector<Real>> ex =
256 Ptr<const std::vector<Real>> eg =
259 Real
zero(0), one(1), indicator, d1prime;
261 for (
int i = 0; i < dim_; ++i ) {
262 indicator = (*edv)[i] < buildC(i) ? one :
zero;
264 if (indicator ==
zero) {
271 d1prime = sgn((*eg)[i]);
272 if (d1prime ==
zero) {
274 if (x_up_[i] - (*ex)[i] < (*ex)[i] - x_lo_[i])
277 (*edv)[i] = d1prime*(*eg)[i]*(*ev)[i];
Ptr< Vector< Real > > upper_
void projectInterior(Vector< Real > &x) override
Project optimization variables into the interior of the feasible set.
void activateLower(void)
Turn on lower bound.
void activate(void)
Turn on bounds.
std::vector< Real > x_lo_
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.
Defines the linear algebra or vector space interface.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void activateUpper(void)
Turn on upper bound.
Ptr< Vector< Real > > lower_
void applyInverseScalingFunction(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply inverse scaling function.
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 project(Vector< Real > &x) override
Project optimization variables onto the bounds.
StdBoundConstraint(std::vector< Real > &x, bool isLower=false, Real scale=Real(1), const Real feasTol=std::sqrt(ROL_EPSILON< Real >()))
Provides the interface to apply upper and lower bound constraints.
void applyScalingFunctionJacobian(Vector< Real > &dv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g) const override
Apply scaling function Jacobian.
void pruneLowerActive(Vector< Real > &v, const Vector< Real > &g, const Vector< Real > &x, Real xeps=Real(0), Real geps=Real(0)) override
Set variables to zero if they correspond to the -binding set.
std::vector< Real > x_up_