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
21namespace ROL {
22
23template <class Real>
25private:
26
31
32public:
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
69 : std::isnan(state.gnorm)||std::isnan(state.snorm) ? EXITSTATUS_NAN
71 return false;
72 }
73 }
74
75}; // class StatusTest
76
77} // namespace ROL
78
79#endif
Contains definitions of custom data types in ROL.
Provides an interface to check status of optimization algorithms.
StatusTest(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100, bool use_rel=false)
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.
StatusTest(ParameterList &parlist)
@ EXITSTATUS_STEPTOL
Definition ROL_Types.hpp:86
@ EXITSTATUS_MAXITER
Definition ROL_Types.hpp:85
@ EXITSTATUS_CONVERGED
Definition ROL_Types.hpp:84
@ EXITSTATUS_NAN
Definition ROL_Types.hpp:87
@ EXITSTATUS_LAST
Definition ROL_Types.hpp:89
State for algorithm class. Will be used for restarts.
EExitStatus statusFlag