ROL
ROL_Solver_Def.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_SOLVER_DEF_HPP
11 #define ROL_SOLVER_DEF_HPP
12 
13 namespace ROL {
14 
15 template<typename Real>
17  ParameterList &parlist,
18  const Ptr<Secant<Real>> &secant )
19  : opt_(opt), problemType_(opt_->getProblemType()) {
20  switch (problemType_) {
21  case TYPE_U: algoU_ = TypeU::AlgorithmFactory<Real>(parlist,secant); break;
22  case TYPE_P: algoP_ = TypeP::AlgorithmFactory<Real>(parlist,secant); break;
23  case TYPE_B: algoB_ = TypeB::AlgorithmFactory<Real>(parlist,secant); break;
24  case TYPE_E: algoE_ = TypeE::AlgorithmFactory<Real>(parlist,secant); break;
25  case TYPE_EB: algoG_ = TypeG::AlgorithmFactory<Real>(parlist,secant); break;
26  case TYPE_LAST:
27  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
28  "Error in Solver::solve() : Unsupported problem type");
29  }
30 }
31 
32 template<typename Real>
33 int Solver<Real>::solve( const Ptr<StatusTest<Real>> &status,
34  bool combineStatus) {
35  nullstream bhs;
36  return solve(bhs,status,combineStatus);
37 }
38 
39 template<typename Real>
40 int Solver<Real>::solve( std::ostream &outStream,
41  const Ptr<StatusTest<Real>> &status,
42  bool combineStatus ) {
43  switch (problemType_) {
44  case TYPE_U:
45  if (status != nullPtr) algoU_->setStatusTest(status,combineStatus);
46  algoU_->run(*opt_,outStream);
47  break;
48  case TYPE_P:
49  if (status != nullPtr) algoP_->setStatusTest(status,combineStatus);
50  algoP_->run(*opt_,outStream);
51  break;
52  case TYPE_B:
53  if (status != nullPtr) algoB_->setStatusTest(status,combineStatus);
54  algoB_->run(*opt_,outStream);
55  break;
56  case TYPE_E:
57  if (status != nullPtr) algoE_->setStatusTest(status,combineStatus);
58  algoE_->run(*opt_,outStream);
59  break;
60  case TYPE_EB:
61  if (status != nullPtr) algoG_->setStatusTest(status,combineStatus);
62  algoG_->run(*opt_,outStream);
63  break;
64  case TYPE_LAST:
65  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
66  "Error in Solver::solve() : Unsupported problem type");
67  }
68  // TODO: Interrogate AlgorithmState and StatusTest to generate a return code
69  // that indicates why the solver has stopped
70 
71  // Return an integer code
72  return 0;
73 }
74 
75 template<typename Real>
76 Ptr<const AlgorithmState<Real>> Solver<Real>::getAlgorithmState() const {
77 //Ptr<const AlgorithmState<Real>>& Solver<Real>::getAlgorithmState() const {
78  switch (problemType_) {
79  case TYPE_U: return algoU_->getState();
80  case TYPE_P: return algoP_->getState();
81  case TYPE_B: return algoB_->getState();
82  case TYPE_E: return algoE_->getState();
83  case TYPE_EB: return algoG_->getState();
84  case TYPE_LAST:
85  default:
86  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
87  "Error in Solver::getAlgorithmState() : Unsupported problem type");
88  }
89 }
90 
91 template<typename Real>
93  switch (problemType_) {
94  case TYPE_U: algoU_->reset(); break;
95  case TYPE_P: algoP_->reset(); break;
96  case TYPE_B: algoB_->reset(); break;
97  case TYPE_E: algoE_->reset(); break;
98  case TYPE_EB: algoG_->reset(); break;
99  case TYPE_LAST:
100  default:
101  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
102  "Error in Solver::reset() : Unsupported problem type");
103  }
104 }
105 
106 } // namespace ROL
107 
108 #endif // ROL_SOLVER_DEF_HPP
109 
110 
basic_nullstream< char, std::char_traits< char >> nullstream
Definition: ROL_Stream.hpp:36
Ptr< TypeP::Algorithm< Real > > algoP_
Definition: ROL_Solver.hpp:41
int solve(const Ptr< StatusTest< Real >> &status=nullPtr, bool combineStatus=true)
Solve optimization problem with no iteration output.
Ptr< TypeG::Algorithm< Real > > algoG_
Definition: ROL_Solver.hpp:40
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:45
Solver(const Ptr< Problem< Real >> &opt, ParameterList &list, const Ptr< Secant< Real >> &secant=nullPtr)
Constructor.
Ptr< TypeU::Algorithm< Real > > algoU_
Definition: ROL_Solver.hpp:37
Provides an interface to check status of optimization algorithms.
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
void reset()
Reset both Algorithm and Step.
const EProblem problemType_
Definition: ROL_Solver.hpp:35
Ptr< const AlgorithmState< Real > > getAlgorithmState() const
Return the AlgorithmState.
Ptr< TypeE::Algorithm< Real > > algoE_
Definition: ROL_Solver.hpp:39
Ptr< TypeB::Algorithm< Real > > algoB_
Definition: ROL_Solver.hpp:38