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_B: algoB_ = TypeB::AlgorithmFactory<Real>(parlist,secant); break;
23  case TYPE_E: algoE_ = TypeE::AlgorithmFactory<Real>(parlist,secant); break;
24  case TYPE_EB: algoG_ = TypeG::AlgorithmFactory<Real>(parlist,secant); break;
25  case TYPE_LAST:
26  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
27  "Error in Solver::solve() : Unsupported problem type");
28  }
29 }
30 
31 template<typename Real>
32 int Solver<Real>::solve( const Ptr<StatusTest<Real>> &status,
33  bool combineStatus) {
34  nullstream bhs;
35  return solve(bhs,status,combineStatus);
36 }
37 
38 template<typename Real>
39 int Solver<Real>::solve( std::ostream &outStream,
40  const Ptr<StatusTest<Real>> &status,
41  bool combineStatus ) {
42  switch (problemType_) {
43  case TYPE_U:
44  if (status != nullPtr) algoU_->setStatusTest(status,combineStatus);
45  algoU_->run(*opt_,outStream);
46  break;
47  case TYPE_B:
48  if (status != nullPtr) algoB_->setStatusTest(status,combineStatus);
49  algoB_->run(*opt_,outStream);
50  break;
51  case TYPE_E:
52  if (status != nullPtr) algoE_->setStatusTest(status,combineStatus);
53  algoE_->run(*opt_,outStream);
54  break;
55  case TYPE_EB:
56  if (status != nullPtr) algoG_->setStatusTest(status,combineStatus);
57  algoG_->run(*opt_,outStream);
58  break;
59  case TYPE_LAST:
60  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
61  "Error in Solver::solve() : Unsupported problem type");
62  }
63  // TODO: Interrogate AlgorithmState and StatusTest to generate a return code
64  // that indicates why the solver has stopped
65 
66  // Return an integer code
67  return 0;
68 }
69 
70 template<typename Real>
71 Ptr<const AlgorithmState<Real>> Solver<Real>::getAlgorithmState() const {
72 //Ptr<const AlgorithmState<Real>>& Solver<Real>::getAlgorithmState() const {
73  switch (problemType_) {
74  case TYPE_U: return algoU_->getState();
75  case TYPE_B: return algoB_->getState();
76  case TYPE_E: return algoE_->getState();
77  case TYPE_EB: return algoG_->getState();
78  case TYPE_LAST:
79  default:
80  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
81  "Error in Solver::getAlgorithmState() : Unsupported problem type");
82  }
83 }
84 
85 template<typename Real>
87  switch (problemType_) {
88  case TYPE_U: algoU_->reset(); break;
89  case TYPE_B: algoB_->reset(); break;
90  case TYPE_E: algoE_->reset(); break;
91  case TYPE_EB: algoG_->reset(); break;
92  case TYPE_LAST:
93  default:
94  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
95  "Error in Solver::reset() : Unsupported problem type");
96  }
97 }
98 
99 } // namespace ROL
100 
101 #endif // ROL_SOLVER_DEF_HPP
102 
103 
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:39
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:36
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:34
Ptr< const AlgorithmState< Real > > getAlgorithmState() const
Return the AlgorithmState.
basic_nullstream< char, char_traits< char >> nullstream
Definition: ROL_Stream.hpp:38
Ptr< TypeE::Algorithm< Real > > algoE_
Definition: ROL_Solver.hpp:38
Ptr< TypeB::Algorithm< Real > > algoB_
Definition: ROL_Solver.hpp:37