ROL
ROL_StatusTest.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_STATUSTEST_H
11 #define ROL_STATUSTEST_H
12 
13 #include "ROL_Types.hpp"
14 #include "ROL_ParameterList.hpp"
15 
21 namespace ROL {
22 
23 template <class Real>
24 class StatusTest {
25 private:
26 
27  Real gtol_, gtol0_;
28  Real stol_, stol0_;
29  int max_iter_;
30  bool use_rel_;
31 
32 public:
33 
34  virtual ~StatusTest() {}
35 
36  StatusTest( ParameterList &parlist ) {
37  Real em6(1e-6);
38  gtol_ = parlist.sublist("Status Test").get("Gradient Tolerance", em6);
39  stol_ = parlist.sublist("Status Test").get("Step Tolerance", em6*gtol_);
40  max_iter_ = parlist.sublist("Status Test").get("Iteration Limit", 100);
41  use_rel_ = parlist.sublist("Status Test").get("Use Relative Tolerances", false);
42  gtol0_ = gtol_;
43  stol0_ = stol_;
44  }
45 
46  StatusTest( Real gtol = 1.e-6, Real stol = 1.e-12, int max_iter = 100, bool use_rel = false ) :
47  gtol_(gtol), gtol0_(gtol), stol_(stol), stol0_(stol), max_iter_(max_iter), use_rel_(use_rel) {}
48 
55  virtual bool check( AlgorithmState<Real> &state ) {
56  if (state.iter==0 && use_rel_) {
57  gtol_ = gtol0_*state.gnorm;
58  stol_ = stol0_*state.gnorm;
59  }
60  if ( (state.gnorm > gtol_) &&
61  (state.snorm > stol_) &&
62  (state.iter < max_iter_) ) {
63  return true;
64  }
65  else {
66  state.statusFlag = (state.gnorm <= gtol_ ? EXITSTATUS_CONVERGED
67  : state.snorm <= stol_ ? EXITSTATUS_STEPTOL
68  : state.iter >= max_iter_ ? EXITSTATUS_MAXITER
69  : std::isnan(state.gnorm)||std::isnan(state.snorm) ? EXITSTATUS_NAN
70  : EXITSTATUS_LAST);
71  return false;
72  }
73  }
74 
75 }; // class StatusTest
76 
77 } // namespace ROL
78 
79 #endif
StatusTest(ParameterList &parlist)
EExitStatus statusFlag
Definition: ROL_Types.hpp:126
Contains definitions of custom data types in ROL.
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.
StatusTest(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100, bool use_rel=false)
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:109
virtual ~StatusTest()
Provides an interface to check status of optimization algorithms.