ROL
ROL_ConstraintStatusTest.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_CONSTRAINTSTATUSTEST_H
11#define ROL_CONSTRAINTSTATUSTEST_H
12
13#include "ROL_StatusTest.hpp"
14
21namespace ROL {
22
23template <class Real>
24class ConstraintStatusTest : public StatusTest<Real> {
25private:
26
32
33public:
34
36
37 ConstraintStatusTest( ROL::ParameterList &parlist ) {
38 Real em6(1e-6);
39 gtol_ = parlist.sublist("Status Test").get("Gradient Tolerance", em6);
40 ctol_ = parlist.sublist("Status Test").get("Constraint Tolerance", em6);
41 stol_ = parlist.sublist("Status Test").get("Step Tolerance", em6*gtol_);
42 max_iter_ = parlist.sublist("Status Test").get("Iteration Limit", 100);
43 use_rel_ = parlist.sublist("Status Test").get("Use Relative Tolerances", false);
44 gtol0_ = gtol_;
45 ctol0_ = ctol_;
46 stol0_ = stol_;
47 }
48
49 ConstraintStatusTest( Real gtol = 1e-6, Real ctol = 1e-6, Real stol = 1e-12, int max_iter = 100, bool use_rel = false ) :
50 gtol_(gtol), gtol0_(gtol), ctol_(ctol), ctol0_(ctol), stol_(stol), stol0_(stol), max_iter_(max_iter), use_rel_(use_rel) {}
51
54 virtual bool check( AlgorithmState<Real> &state ) {
55 if (state.iter==0 && use_rel_) {
56 gtol_ = gtol0_*std::max(state.gnorm,static_cast<Real>(1e-2));
57 ctol_ = ctol0_*std::max(state.cnorm,static_cast<Real>(1e-2));
58 stol_ = stol0_*std::max(std::min(state.gnorm,state.cnorm),static_cast<Real>(1e-2));
59 }
60 if ( ((state.gnorm > gtol_) || (state.cnorm > ctol_)) &&
61 (state.snorm > stol_) &&
62 (state.iter < max_iter_) ) {
63 return true;
64 }
65 else {
66 state.statusFlag = ((state.gnorm <= gtol_) && (state.cnorm <= ctol_) ? EXITSTATUS_CONVERGED
67 : state.snorm <= stol_ ? EXITSTATUS_STEPTOL
70 return false;
71 }
72 }
73
74}; // class ConstraintStatusTest
75
76} // namespace ROL
77
78#endif
Provides an interface to check status of optimization algorithms for problems with equality constrain...
ConstraintStatusTest(ROL::ParameterList &parlist)
ConstraintStatusTest(Real gtol=1e-6, Real ctol=1e-6, Real stol=1e-12, int max_iter=100, bool use_rel=false)
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.
Provides an interface to check status of optimization algorithms.
@ EXITSTATUS_STEPTOL
Definition ROL_Types.hpp:86
@ EXITSTATUS_MAXITER
Definition ROL_Types.hpp:85
@ EXITSTATUS_CONVERGED
Definition ROL_Types.hpp:84
@ EXITSTATUS_LAST
Definition ROL_Types.hpp:89
State for algorithm class. Will be used for restarts.
EExitStatus statusFlag