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 
21 namespace ROL {
22 
23 template <class Real>
24 class ConstraintStatusTest : public StatusTest<Real> {
25 private:
26 
27  Real gtol_;
28  Real ctol_;
29  Real stol_;
30  int max_iter_;
31 
32 public:
33 
34  virtual ~ConstraintStatusTest() {}
35 
36  ConstraintStatusTest( ROL::ParameterList &parlist ) {
37  Real em6(1e-6);
38  gtol_ = parlist.sublist("Status Test").get("Gradient Tolerance", em6);
39  ctol_ = parlist.sublist("Status Test").get("Constraint Tolerance", em6);
40  stol_ = parlist.sublist("Status Test").get("Step Tolerance", em6*gtol_);
41  max_iter_ = parlist.sublist("Status Test").get("Iteration Limit", 100);
42  }
43 
44  ConstraintStatusTest( Real gtol = 1e-6, Real ctol = 1e-6, Real stol = 1e-12, int max_iter = 100 ) :
45  gtol_(gtol), ctol_(ctol), stol_(stol), max_iter_(max_iter) {}
46 
49  virtual bool check( AlgorithmState<Real> &state ) {
50  if ( ((state.gnorm > gtol_) || (state.cnorm > ctol_)) &&
51  (state.snorm > stol_) &&
52  (state.iter < max_iter_) ) {
53  return true;
54  }
55  else {
56  state.statusFlag = ((state.gnorm <= gtol_) && (state.cnorm <= ctol_) ? EXITSTATUS_CONVERGED
57  : state.snorm <= stol_ ? EXITSTATUS_STEPTOL
58  : state.iter >= max_iter_ ? EXITSTATUS_MAXITER
59  : EXITSTATUS_LAST);
60  return false;
61  }
62  }
63 
64 }; // class ConstraintStatusTest
65 
66 } // namespace ROL
67 
68 #endif
EExitStatus statusFlag
Definition: ROL_Types.hpp:126
Provides an interface to check status of optimization algorithms for problems with equality constrain...
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:109
ConstraintStatusTest(Real gtol=1e-6, Real ctol=1e-6, Real stol=1e-12, int max_iter=100)
ConstraintStatusTest(ROL::ParameterList &parlist)
Provides an interface to check status of optimization algorithms.
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.