ROL
ROL_CombinedStatusTest.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_COMBINEDSTATUSTEST_H
11 #define ROL_COMBINEDSTATUSTEST_H
12 
13 #include "ROL_StatusTest.hpp"
14 
20 namespace ROL {
21 
22 template<typename Real>
23 class CombinedStatusTest : public StatusTest<Real> {
24 private:
25  std::vector<Ptr<StatusTest<Real>>> status_;
26 
27 public:
29  status_.clear();
30  }
31 
32  void reset(void) {
33  status_.clear();
34  }
35 
36  void add(const Ptr<StatusTest<Real>> &status) {
37  status_.push_back(status);
38  }
39 
40  bool check( AlgorithmState<Real> &state ) {
41  ROL_TEST_FOR_EXCEPTION(status_.empty(),std::logic_error,
42  ">>> ROL::CombinedStatusTest::check : No status test has been added!");
43 
44  bool flag = true;
45  for (const auto & status : status_) {
46  flag = status->check(state);
47  if (!flag) break;
48  }
49 
50  // true = "continue iteration"
51  // false = "stop iteration"
52  return flag;
53  }
54 
55 }; // class CombinedStatusTest
56 
57 } // namespace ROL
58 
59 #endif
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:109
Provides an interface to check status of optimization algorithms.
std::vector< Ptr< StatusTest< Real > > > status_
void add(const Ptr< StatusTest< Real >> &status)
Provides an interface to check two status tests of optimization algorithms.
bool check(AlgorithmState< Real > &state)
Check algorithm status.