44 #ifndef ROL_ScalarMinimizationLineSearch_H
45 #define ROL_ScalarMinimizationLineSearch_H
53 #include "ROL_BrentsScalarMinimization.hpp"
54 #include "ROL_BisectionScalarMinimization.hpp"
55 #include "ROL_GoldenSectionScalarMinimization.hpp"
56 #include "ROL_ScalarFunction.hpp"
57 #include "ROL_Bracketing.hpp"
65 ROL::Ptr<Vector<Real> >
g_;
66 ROL::Ptr<ScalarMinimization<Real> >
sm_;
67 ROL::Ptr<Bracketing<Real> >
br_;
68 ROL::Ptr<ScalarFunction<Real> >
sf_;
76 class Phi :
public ScalarFunction<Real> {
78 const ROL::Ptr<Vector<Real> >
xnew_;
79 const ROL::Ptr<Vector<Real> >
g_;
80 const ROL::Ptr<const Vector<Real> >
x_;
81 const ROL::Ptr<const Vector<Real> >
s_;
82 const ROL::Ptr<Objective<Real> >
obj_;
83 const ROL::Ptr<BoundConstraint<Real> >
con_;
88 if (
con_->isActivated() ) {
110 return s_->dot(
g_->dual());
116 ROL::Ptr<ScalarFunction<Real> >
phi_;
130 const Real c1,
const Real c2,
const Real c3,
132 const ROL::Ptr<ScalarFunction<Real> > &phi)
136 bool check(Real &x, Real &fx, Real &gx,
137 int &nfval,
int &ngval,
const bool deriv =
false) {
141 bool curvcond =
false;
145 curvcond = (fx >=
f0_ + (one-
c1_)*x*
g0_);
152 gx =
phi_->deriv(x); ngval++;
155 curvcond = (gx >=
c2_*
g0_);
158 curvcond = (std::abs(gx) <=
c2_*std::abs(
g0_));
164 curvcond = (
c2_*
g0_ <= gx && gx <= (two*
c1_ - one)*
g0_);
169 return (armijo && curvcond);
176 const ROL::Ptr<ScalarMinimization<Real> > &sm = ROL::nullPtr,
177 const ROL::Ptr<Bracketing<Real> > &br = ROL::nullPtr,
178 const ROL::Ptr<ScalarFunction<Real> > &sf = ROL::nullPtr )
180 Real
zero(0), p4(0.4), p6(0.6), p9(0.9), oem4(1.e-4), oem10(1.e-10), one(1);
181 ROL::ParameterList &list0 = parlist.sublist(
"Step").sublist(
"Line Search");
182 ROL::ParameterList &list = list0.sublist(
"Line-Search Method");
184 if( br == ROL::nullPtr ) {
185 br_ = ROL::makePtr<Bracketing<Real>>();
191 std::string type = list.get(
"Type",
"Brent's");
192 Real tol = list.sublist(type).get(
"Tolerance",oem10);
193 int niter = list.sublist(type).get(
"Iteration Limit",1000);
194 ROL::ParameterList plist;
195 plist.sublist(
"Scalar Minimization").set(
"Type",type);
196 plist.sublist(
"Scalar Minimization").sublist(type).set(
"Tolerance",tol);
197 plist.sublist(
"Scalar Minimization").sublist(type).set(
"Iteration Limit",niter);
199 if( sm == ROL::nullPtr ) {
201 if ( type ==
"Brent's" ) {
202 sm_ = ROL::makePtr<BrentsScalarMinimization<Real>>(plist);
204 else if ( type ==
"Bisection" ) {
205 sm_ = ROL::makePtr<BisectionScalarMinimization<Real>>(plist);
207 else if ( type ==
"Golden Section" ) {
208 sm_ = ROL::makePtr<GoldenSectionScalarMinimization<Real>>(plist);
211 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
212 ">>> (ROL::ScalarMinimizationLineSearch): Undefined ScalarMinimization type!");
224 max_nfval_ = list0.get(
"Function Evaluation Limit",20);
225 c1_ = list0.get(
"Sufficient Decrease Tolerance",oem4);
226 c2_ = list0.sublist(
"Curvature Condition").get(
"General Parameter",p9);
227 c3_ = list0.sublist(
"Curvature Condition").get(
"Generalized Wolfe Parameter",p6);
251 void run( Real &alpha, Real &fval,
int &ls_neval,
int &ls_ngrad,
254 ls_neval = 0; ls_ngrad = 0;
260 ROL::Ptr<const Vector<Real> > x_ptr = ROL::makePtrFromRef(x);
261 ROL::Ptr<const Vector<Real> > s_ptr = ROL::makePtrFromRef(s);
262 ROL::Ptr<Objective<Real> > obj_ptr = ROL::makePtrFromRef(obj);
263 ROL::Ptr<BoundConstraint<Real> > bnd_ptr = ROL::makePtrFromRef(con);
266 ROL::Ptr<ScalarFunction<Real> > phi;
268 if(
sf_ == ROL::nullPtr ) {
269 phi = ROL::makePtr<Phi>(
xnew_,
g_,x_ptr,s_ptr,obj_ptr,bnd_ptr);
275 ROL::Ptr<ScalarMinimizationStatusTest<Real> > test
279 int nfval = 0, ngrad = 0;
280 Real A(0), fA = fval;
281 Real B = alpha, fB = phi->value(B);
282 br_->run(alpha,fval,A,fA,B,fB,nfval,ngrad,*phi,*test);
284 ls_neval += nfval; ls_ngrad += ngrad;
287 nfval = 0, ngrad = 0;
288 sm_->run(fval, alpha, nfval, ngrad, *phi, A, B, *test);
289 ls_neval += nfval; ls_ngrad += ngrad;