ROL
ROL_Bounds.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ROL_BOUNDS_H
11#define ROL_BOUNDS_H
12
14
22namespace ROL {
23
24template<typename Real>
25class Bounds : public BoundConstraint<Real> {
26private:
27 const Real scale_;
28 const Real feasTol_;
29
30 using BoundConstraint<Real>::lower_;
31 using BoundConstraint<Real>::upper_;
32
33 Ptr<Vector<Real>> mask_;
34
36
37 Elementwise::ReductionMin<Real> minimum_;
38 Elementwise::ReductionMax<Real> maximum_;
39
40 class isGreater : public Elementwise::BinaryFunction<Real> {
41 public:
43 Real apply(const Real &x, const Real &y) const {
44 return (x > y) ? static_cast<Real>(1) : static_cast<Real>(0);
45 }
47
48 class Active : public Elementwise::BinaryFunction<Real> {
49 public:
50 Active(Real offset) : offset_(offset) {}
51 Real apply( const Real &x, const Real &y ) const {
52 return ((y <= offset_) ? 0 : x);
53 }
54 private:
55 Real offset_;
56 };
57
58 class UpperBinding : public Elementwise::BinaryFunction<Real> {
59 public:
60 UpperBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
61 Real apply( const Real &x, const Real &y ) const {
62 return ((y < -geps_ && x <= xeps_) ? 0 : 1);
63 }
64 private:
65 Real xeps_, geps_;
66 };
67
68 class LowerBinding : public Elementwise::BinaryFunction<Real> {
69 public:
70 LowerBinding(Real xeps, Real geps) : xeps_(xeps), geps_(geps) {}
71 Real apply( const Real &x, const Real &y ) const {
72 return ((y > geps_ && x <= xeps_) ? 0 : 1);
73 }
74 private:
75 Real xeps_, geps_;
76 };
77
78 class PruneBinding : public Elementwise::BinaryFunction<Real> {
79 public:
80 Real apply( const Real &x, const Real &y ) const {
81 return ((y == 1) ? x : 0);
82 }
84
85 class BuildC : public Elementwise::UnaryFunction<Real> {
86 public:
87 Real apply( const Real &x ) const {
88 const Real zeta(0.5), kappa(1);
89 return std::min(zeta * x, kappa);
90 }
92
93 class SetZeroEntry : public Elementwise::BinaryFunction<Real> {
94 public:
95 Real apply(const Real &x, const Real &y) const {
96 const Real zero(0);
97 return (x==zero ? y : x);
98 }
100
101 void buildScalingFunction(Vector<Real> &d, const Vector<Real> &x, const Vector<Real> &g) const;
102
103public:
104
105 Bounds(const Vector<Real> &x,
106 bool isLower = true,
107 Real scale = 1,
108 Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
109
110 Bounds(const Ptr<Vector<Real>> &x_lo,
111 const Ptr<Vector<Real>> &x_up,
112 const Real scale = 1,
113 const Real feasTol = std::sqrt(ROL_EPSILON<Real>()));
114
115 void project( Vector<Real> &x ) override;
116
117 void projectInterior( Vector<Real> &x ) override;
118
119 void pruneUpperActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
120
121 void pruneUpperActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
122
123 void pruneLowerActive( Vector<Real> &v, const Vector<Real> &x, Real eps = Real(0) ) override;
124
125 void pruneLowerActive( Vector<Real> &v, const Vector<Real> &g, const Vector<Real> &x, Real xeps = Real(0), Real geps = Real(0) ) override;
126
127 bool isFeasible( const Vector<Real> &v ) override;
128
129 void applyInverseScalingFunction(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
130
131 void applyScalingFunctionJacobian(Vector<Real> &dv, const Vector<Real> &v, const Vector<Real> &x, const Vector<Real> &g) const override;
132}; // class Bounds
133
134} // namespace ROL
135
136#include "ROL_Bounds_Def.hpp"
137
138#endif
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_
Ptr< Vector< Real > > lower_
Active(Real offset)
Real apply(const Real &x, const Real &y) const
Real apply(const Real &x) const
LowerBinding(Real xeps, Real geps)
Real apply(const Real &x, const Real &y) const
Real apply(const Real &x, const Real &y) const
Real apply(const Real &x, const Real &y) const
UpperBinding(Real xeps, Real geps)
Real apply(const Real &x, const Real &y) const
Real apply(const Real &x, const Real &y) const
Provides the elementwise interface to apply upper and lower bound constraints.
Elementwise::ReductionMin< Real > minimum_
const Real feasTol_
ROL::Bounds::isGreater isGreater_
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.
const Real scale_
ROL::Bounds::SetZeroEntry setZeroEntry_
void project(Vector< Real > &x) override
Project optimization variables onto the bounds.
ROL::Bounds::BuildC buildC_
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.
ROL::Bounds::PruneBinding prune_
bool isFeasible(const Vector< Real > &v) override
Check if the vector, v, is feasible.
Elementwise::ReductionMax< Real > maximum_
Defines the linear algebra or vector space interface.