ROL
ROL_TypeE_AlgorithmFactory.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_TYPEE_ALGORITHMFACTORY_H
11 #define ROL_TYPEE_ALGORITHMFACTORY_H
12 
17 #include "ROL_Types.hpp"
18 
19 namespace ROL {
20 namespace TypeE {
21 
31 };
32 
33 inline std::string EAlgorithmEToString(EAlgorithmE alg) {
34  std::string retString;
35  switch(alg) {
36  case ALGORITHM_E_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
37  case ALGORITHM_E_FLETCHER: retString = "Fletcher"; break;
38  case ALGORITHM_E_COMPOSITESTEP: retString = "Composite Step"; break;
39  case ALGORITHM_E_STABILIZEDLCL: retString = "Stabilized LCL"; break;
40  case ALGORITHM_E_LAST: retString = "Last Type (Dummy)"; break;
41  default: retString = "INVALID EAlgorithmE";
42  }
43  return retString;
44 }
45 
52  return( (alg == ALGORITHM_E_AUGMENTEDLAGRANGIAN) ||
53  (alg == ALGORITHM_E_FLETCHER) ||
54  (alg == ALGORITHM_E_COMPOSITESTEP) ||
55  (alg == ALGORITHM_E_STABILIZEDLCL) ||
56  (alg == ALGORITHM_E_LAST)
57  );
58 }
59 
61  return type = static_cast<EAlgorithmE>(type+1);
62 }
63 
64 inline EAlgorithmE operator++(EAlgorithmE &type, int) {
65  EAlgorithmE oldval = type;
66  ++type;
67  return oldval;
68 }
69 
71  return type = static_cast<EAlgorithmE>(type-1);
72 }
73 
74 inline EAlgorithmE operator--(EAlgorithmE &type, int) {
75  EAlgorithmE oldval = type;
76  --type;
77  return oldval;
78 }
79 
80 inline EAlgorithmE StringToEAlgorithmE(std::string s) {
81  s = removeStringFormat(s);
83  if ( !s.compare(removeStringFormat(EAlgorithmEToString(alg))) ) {
84  return alg;
85  }
86  }
88 }
89 
90 template<typename Real>
91 inline Ptr<TypeE::Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
92  std::string stepType = parlist.sublist("Step").get("Type","Augmented Lagrangian");
93  EAlgorithmE ealg = StringToEAlgorithmE(stepType);
94  switch(ealg) {
95  case ALGORITHM_E_AUGMENTEDLAGRANGIAN: return makePtr<TypeE::AugmentedLagrangianAlgorithm<Real>>(parlist,secant);
96  case ALGORITHM_E_FLETCHER: return makePtr<TypeE::FletcherAlgorithm<Real>>(parlist,secant);
97  case ALGORITHM_E_COMPOSITESTEP: return makePtr<TypeE::CompositeStepAlgorithm<Real>>(parlist);
98  case ALGORITHM_E_STABILIZEDLCL: return makePtr<TypeE::StabilizedLCLAlgorithm<Real>>(parlist,secant);
99  default: return nullPtr;
100  }
101 }
102 
103 } // namespace TypeE
104 } // namespace ROL
105 
106 #endif
int isValidAlgorithmE(EAlgorithmE alg)
Verifies validity of a AlgorithmE enum.
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:215
std::string EAlgorithmEToString(EAlgorithmE alg)
Ptr< TypeE::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real >> &secant=nullPtr)
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:45
EAlgorithmE & operator++(EAlgorithmE &type)
EAlgorithmE & operator--(EAlgorithmE &type)
EAlgorithmE StringToEAlgorithmE(std::string s)