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_, gtol0_;
28  Real ctol_, ctol0_;
29  Real stol_, stol0_;
30  int max_iter_;
31  bool use_rel_;
32 
33 public:
34 
35  virtual ~ConstraintStatusTest() {}
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
68  : state.iter >= max_iter_ ? EXITSTATUS_MAXITER
69  : EXITSTATUS_LAST);
70  return false;
71  }
72  }
73 
74 }; // class ConstraintStatusTest
75 
76 } // namespace ROL
77 
78 #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(ROL::ParameterList &parlist)
ConstraintStatusTest(Real gtol=1e-6, Real ctol=1e-6, Real stol=1e-12, int max_iter=100, bool use_rel=false)
Provides an interface to check status of optimization algorithms.
virtual bool check(AlgorithmState< Real > &state)
Check algorithm status.