10 #ifndef ROL_DAIFLETCHERPROJECTION_DEF_H
11 #define ROL_DAIFLETCHERPROJECTION_DEF_H
15 template<
typename Real>
26 DEFAULT_maxit_ (5000),
27 DEFAULT_verbosity_ (0),
28 atol_ (DEFAULT_atol_),
29 rtol_ (DEFAULT_rtol_),
30 ltol_ (DEFAULT_ltol_),
31 maxit_ (DEFAULT_maxit_),
32 verbosity_ (DEFAULT_verbosity_) {
36 template<
typename Real>
48 DEFAULT_maxit_ (5000),
49 DEFAULT_verbosity_ (0),
50 atol_ (DEFAULT_atol_),
51 rtol_ (DEFAULT_rtol_),
52 ltol_ (DEFAULT_ltol_),
53 maxit_ (DEFAULT_maxit_),
54 verbosity_ (DEFAULT_verbosity_) {
55 atol_ = list.sublist(
"General").sublist(
"Polyhedral Projection").get(
"Absolute Tolerance",
DEFAULT_atol_);
56 rtol_ = list.sublist(
"General").sublist(
"Polyhedral Projection").get(
"Relative Tolerance",
DEFAULT_rtol_);
57 ltol_ = list.sublist(
"General").sublist(
"Polyhedral Projection").get(
"Multiplier Tolerance",
DEFAULT_ltol_);
58 maxit_ = list.sublist(
"General").sublist(
"Polyhedral Projection").get(
"Iteration Limit",
DEFAULT_maxit_);
63 template<
typename Real>
71 ROL_TEST_FOR_EXCEPTION(dim_!=1,std::logic_error,
72 ">>> ROL::DaiFletcherProjection : The range of the linear constraint must be one dimensional!");
73 xnew_ = xprim.
clone();
75 mul1_ =
static_cast<Real
>(0);
76 dlam1_ =
static_cast<Real
>(2);
78 Real tol(std::sqrt(ROL_EPSILON<Real>()));
81 con_->value(*res_,*xprim_,tol);
82 b_ = res_->dot(*res_->basis(0));
83 mul_->setScalar(static_cast<Real>(1));
84 con_->applyAdjointJacobian(*xdual_,*mul_,xprim,tol);
85 xprim_->set(xdual_->dual());
86 cdot_ = xprim_->dot(*xprim_);
91 Real resl = ROL_INF<Real>(), resu = ROL_INF<Real>();
92 if (bnd_->isLowerActivated()) resl = residual(*bnd_->getLowerBound());
93 if (bnd_->isUpperActivated()) resu = residual(*bnd_->getUpperBound());
94 Real res0 = std::max(resl,resu);
95 if (res0 < atol_) res0 =
static_cast<Real
>(1);
96 ctol_ = std::min(atol_,rtol_*res0);
99 template<
typename Real>
101 if (con_ == nullPtr) {
105 Px_->set(x); bnd_->project(*Px_);
106 mul1_ = -residual(*Px_)/cdot_;
109 dlam1_ =
static_cast<Real
>(2);
111 project_df(x, mul1_, dlam1_, stream);
112 mul_->setScalar(mul1_);
116 template<
typename Real>
118 return xprim_->dot(x) + b_;
121 template<
typename Real>
128 template<
typename Real>
130 const Real
zero(0), one(1), two(2), c1(0.1), c2(0.75), c3(0.25);
131 Real lamLower(0), lamUpper(0), lamNew(0), res(0), resLower(0), resUpper(0), s(0);
135 update_primal(*xnew_,x,lam);
136 res = residual(*xnew_);
141 std::ios_base::fmtflags streamFlags(stream.flags());
142 if (verbosity_ > 2) {
143 stream << std::scientific << std::setprecision(6);
145 stream <<
" Polyhedral Projection using the Dai-Fletcher Algorithm" << std::endl;
146 stream <<
" Bracketing Phase" << std::endl;
153 update_primal(*xnew_,x,lam);
154 res = residual(*xnew_);
155 if (verbosity_ > 2) {
157 stream << std::setw(6) << std::left <<
"iter";
158 stream << std::setw(15) << std::left <<
"lam";
159 stream << std::setw(15) << std::left <<
"res";
160 stream << std::setw(15) << std::left <<
"lower lam";
161 stream << std::setw(15) << std::left <<
"lower res";
164 stream << std::setw(6) << std::left << cnt;
165 stream << std::setw(15) << std::left << lam;
166 stream << std::setw(15) << std::left << res;
167 stream << std::setw(15) << std::left << lamLower;
168 stream << std::setw(15) << std::left << resLower;
171 while ( res <
zero && std::abs(res) > rtol && cnt < maxit_ ) {
172 s = std::max(resLower/res-one,c1);
177 update_primal(*xnew_,x,lam);
178 res = residual(*xnew_);
180 if (verbosity_ > 2) {
182 stream << std::setw(6) << std::left << cnt;
183 stream << std::setw(15) << std::left << lam;
184 stream << std::setw(15) << std::left << res;
185 stream << std::setw(15) << std::left << lamLower;
186 stream << std::setw(15) << std::left << resLower;
197 update_primal(*xnew_,x,lam);
198 res = residual(*xnew_);
199 if (verbosity_ > 2) {
201 stream << std::setw(6) << std::left <<
"iter";
202 stream << std::setw(15) << std::left <<
"lam";
203 stream << std::setw(15) << std::left <<
"res";
204 stream << std::setw(15) << std::left <<
"upper lam";
205 stream << std::setw(15) << std::left <<
"upper res";
208 stream << std::setw(6) << std::left << cnt;
209 stream << std::setw(15) << std::left << lam;
210 stream << std::setw(15) << std::left << res;
211 stream << std::setw(15) << std::left << lamUpper;
212 stream << std::setw(15) << std::left << resUpper;
215 while ( res >
zero && std::abs(res) > rtol && cnt < maxit_ ) {
216 s = std::max(resUpper/res-one,c1);
221 update_primal(*xnew_,x,lam);
222 res = residual(*xnew_);
224 if (verbosity_ > 2) {
226 stream << std::setw(6) << std::left << cnt;
227 stream << std::setw(15) << std::left << lam;
228 stream << std::setw(15) << std::left << res;
229 stream << std::setw(15) << std::left << lamUpper;
230 stream << std::setw(15) << std::left << resUpper;
237 if (verbosity_ > 2) {
238 stream <<
" Bracket: ";
239 stream << std::setw(15) << std::left << lamLower;
240 stream << std::setw(15) << std::left << lamUpper;
245 rtol = ctol_*std::max(one,std::min(std::abs(resLower),std::abs(resUpper)));
249 s = (resUpper - resLower) / resUpper;
250 lam = (resUpper * lamLower - resLower * lamUpper) / (resUpper - resLower);
251 dlam = lamUpper - lam;
252 update_primal(*xnew_,x,lam);
253 res = residual(*xnew_);
255 if (verbosity_ > 2) {
257 stream <<
" Secant Phase" << std::endl;
259 stream << std::setw(6) << std::left <<
"iter";
260 stream << std::setw(15) << std::left <<
"lam";
261 stream << std::setw(15) << std::left <<
"res";
262 stream << std::setw(15) << std::left <<
"stepsize";
263 stream << std::setw(15) << std::left <<
"rtol";
264 stream << std::setw(15) << std::left <<
"lbnd";
265 stream << std::setw(15) << std::left <<
"lres";
266 stream << std::setw(15) << std::left <<
"ubnd";
267 stream << std::setw(15) << std::left <<
"ures";
270 stream << std::setw(6) << std::left << cnt;
271 stream << std::setw(15) << std::left << lam;
272 stream << std::setw(15) << std::left << res;
273 stream << std::setw(15) << std::left << dlam;
274 stream << std::setw(15) << std::left << rtol;
275 stream << std::setw(15) << std::left << lamLower;
276 stream << std::setw(15) << std::left << resLower;
277 stream << std::setw(15) << std::left << lamUpper;
278 stream << std::setw(15) << std::left << resUpper;
281 for (cnt = 1; cnt < maxit_; cnt++) {
283 if ( std::abs(res) <= rtol ||
284 std::abs(lamUpper-lamLower) < ltol_*std::max(std::abs(lamUpper),std::abs(lamLower)) ) {
295 s = (resUpper - resLower) / resUpper;
296 lam = (lamLower * resUpper - lamUpper * resLower) / (resUpper - resLower);
297 dlam = lamUpper - lam;
303 if (resUpper <= (c1+one)*res) {
304 dlam = (lamUpper - lam) / c1;
305 lamNew = std::max(lam - dlam, c2*lamLower + c3*lam);
308 lamNew = std::max((lam * resUpper - lamUpper * res) / (resUpper - res),
309 c2*lamLower + c3*lam);
315 s = (lamUpper - lamLower) / (lamUpper - lam);
325 s = (resUpper - resLower) / resUpper;
326 lam = (lamLower * resUpper - lamUpper * resLower) / (resUpper - resLower);
327 dlam = lamUpper - lam;
333 if (resLower >= (c1+one)*res) {
334 dlam = (lam - lamLower) / c1;
335 lamNew = std::max(lam + dlam, c2*lamUpper + c3*lam);
338 lamNew = std::max((lamLower * res - lam * resLower) / (res - resLower),
339 c2*lamUpper + c3*lam);
340 dlam = lamNew - lamLower;
345 s = (lamUpper - lamLower) / (lamUpper - lam);
348 update_primal(*xnew_,x,lam);
349 res = residual(*xnew_);
351 if (verbosity_ > 2) {
353 stream << std::setw(6) << std::left << cnt;
354 stream << std::setw(15) << std::left << lam;
355 stream << std::setw(15) << std::left << res;
356 stream << std::setw(15) << std::left << dlam;
357 stream << std::setw(15) << std::left << rtol;
358 stream << std::setw(15) << std::left << lamLower;
359 stream << std::setw(15) << std::left << resLower;
360 stream << std::setw(15) << std::left << lamUpper;
361 stream << std::setw(15) << std::left << resUpper;
365 if (verbosity_ > 2) {
370 if (std::abs(res) > rtol ) {
372 stream <<
">>> ROL::PolyhedralProjection::project : Projection may be inaccurate! rnorm = ";
373 stream << std::abs(res) <<
" rtol = " << rtol << std::endl;
375 stream.flags(streamFlags);
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual int dimension() const
Return dimension of the vector space.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Real residual(const Vector< Real > &x) const
Defines the linear algebra or vector space interface.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
DaiFletcherProjection(const Vector< Real > &xprim, const Vector< Real > &xdual, const Ptr< BoundConstraint< Real >> &bnd, const Ptr< Constraint< Real >> &con, const Vector< Real > &mul, const Vector< Real > &res)
void project(Vector< Real > &x, std::ostream &stream=std::cout) override
void initialize(const Vector< Real > &xprim, const Vector< Real > &xdual, const Ptr< BoundConstraint< Real >> &bnd, const Ptr< Constraint< Real >> &con, const Vector< Real > &mul, const Vector< Real > &res)
void project_df(Vector< Real > &x, Real &lam, Real &dlam, std::ostream &stream=std::cout) const
void update_primal(Vector< Real > &y, const Vector< Real > &x, const Real lam) const
Provides the interface to apply upper and lower bound constraints.
virtual void set(const Vector &x)
Set where .
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Defines the general constraint operator interface.