ROL
src
status
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
19
20
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
ROL_Types.hpp
Contains definitions of custom data types in ROL.
ROL::StatusTest::stol_
Real stol_
Definition
ROL_StatusTest.hpp:28
ROL::StatusTest::StatusTest
StatusTest(Real gtol=1.e-6, Real stol=1.e-12, int max_iter=100, bool use_rel=false)
Definition
ROL_StatusTest.hpp:46
ROL::StatusTest::stol0_
Real stol0_
Definition
ROL_StatusTest.hpp:28
ROL::StatusTest::check
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.
Definition
ROL_StatusTest.hpp:55
ROL::StatusTest::max_iter_
int max_iter_
Definition
ROL_StatusTest.hpp:29
ROL::StatusTest::gtol_
Real gtol_
Definition
ROL_StatusTest.hpp:27
ROL::StatusTest::gtol0_
Real gtol0_
Definition
ROL_StatusTest.hpp:27
ROL::StatusTest::~StatusTest
virtual ~StatusTest()
Definition
ROL_StatusTest.hpp:34
ROL::StatusTest::StatusTest
StatusTest(ParameterList &parlist)
Definition
ROL_StatusTest.hpp:36
ROL::StatusTest::use_rel_
bool use_rel_
Definition
ROL_StatusTest.hpp:30
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::EXITSTATUS_STEPTOL
@ EXITSTATUS_STEPTOL
Definition
ROL_Types.hpp:86
ROL::EXITSTATUS_MAXITER
@ EXITSTATUS_MAXITER
Definition
ROL_Types.hpp:85
ROL::EXITSTATUS_CONVERGED
@ EXITSTATUS_CONVERGED
Definition
ROL_Types.hpp:84
ROL::EXITSTATUS_NAN
@ EXITSTATUS_NAN
Definition
ROL_Types.hpp:87
ROL::EXITSTATUS_LAST
@ EXITSTATUS_LAST
Definition
ROL_Types.hpp:89
ROL::AlgorithmState
State for algorithm class. Will be used for restarts.
Definition
ROL_Types.hpp:109
ROL::AlgorithmState::gnorm
Real gnorm
Definition
ROL_Types.hpp:117
ROL::AlgorithmState::snorm
Real snorm
Definition
ROL_Types.hpp:119
ROL::AlgorithmState::statusFlag
EExitStatus statusFlag
Definition
ROL_Types.hpp:126
ROL::AlgorithmState::iter
int iter
Definition
ROL_Types.hpp:110
Generated by
1.15.0