ROL
ROL_TypeP_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_TYPEP_ALGORITHMFACTORY_H
11#define ROL_TYPEP_ALGORITHMFACTORY_H
12
19#include "ROL_Types.hpp"
20
21namespace ROL {
22namespace TypeP {
23
39
40inline std::string EAlgorithmPToString(EAlgorithmP alg) {
41 std::string retString;
42 switch(alg) {
43 case ALGORITHM_P_LINESEARCH: retString = "Line Search"; break;
44 case ALGORITHM_P_TRUSTREGION: retString = "Trust Region"; break;
45 case ALGORITHM_P_SPECTRALGRADIENT: retString = "Spectral Gradient"; break;
46 case ALGORITHM_P_IPIANO: retString = "iPiano"; break;
47 case ALGORITHM_P_LAST: retString = "Last Type (Dummy)"; break;
48 default: retString = "INVALID EAlgorithmP";
49 }
50 return retString;
51}
52
59 return( (alg == ALGORITHM_P_LINESEARCH) ||
60 (alg == ALGORITHM_P_TRUSTREGION) ||
62 (alg == ALGORITHM_P_IPIANO) ||
63 (alg == ALGORITHM_P_LAST)
64 );
65}
66
68 return type = static_cast<EAlgorithmP>(type+1);
69}
70
72 EAlgorithmP oldval = type;
73 ++type;
74 return oldval;
75}
76
78 return type = static_cast<EAlgorithmP>(type-1);
79}
80
82 EAlgorithmP oldval = type;
83 --type;
84 return oldval;
85}
86
87inline EAlgorithmP StringToEAlgorithmP(std::string s) {
88 s = removeStringFormat(s);
89 for ( EAlgorithmP alg = ALGORITHM_P_LINESEARCH; alg < ALGORITHM_P_LAST; alg++ ) {
90 if ( !s.compare(removeStringFormat(EAlgorithmPToString(alg))) ) {
91 return alg;
92 }
93 }
95}
96
97template<typename Real>
98inline Ptr<Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
99 std::string stepType = parlist.sublist("Step").get("Type","Trust Region");
100 EAlgorithmP ealg = StringToEAlgorithmP(stepType);
101 switch(ealg) {
103 {
104 std::string desc
105 = parlist.sublist("Step").sublist("Line Search").sublist("Descent Method").get("Type","Newton-Krylov");
106 if (desc=="Newton-Krylov" || desc=="Newton")
107 return makePtr<InexactNewtonAlgorithm<Real>>(parlist);
108 else if (desc=="Quasi-Newton Method" || desc == "Quasi-Newton")
109 return makePtr<QuasiNewtonAlgorithm<Real>>(parlist, secant);
110 else
111 return makePtr<ProxGradientAlgorithm<Real>>(parlist);
112 }
113 case ALGORITHM_P_TRUSTREGION: return makePtr<TrustRegionAlgorithm<Real>>(parlist, secant);
114 case ALGORITHM_P_SPECTRALGRADIENT: return makePtr<SpectralGradientAlgorithm<Real>>(parlist);
115 case ALGORITHM_P_IPIANO: return makePtr<iPianoAlgorithm<Real>>(parlist);
116 default: return nullPtr;
117 }
118}
119} // namespace TypeP
120} // namespace ROL
121
122#endif
Contains definitions of custom data types in ROL.
Provides interface for and implements limited-memory secant operators.
std::string EAlgorithmPToString(EAlgorithmP alg)
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
int isValidAlgorithmP(EAlgorithmP alg)
Verifies validity of a AlgorithmP enum.
EAlgorithmP StringToEAlgorithmP(std::string s)
EAlgorithmP & operator--(EAlgorithmP &type)
EAlgorithmP & operator++(EAlgorithmP &type)
std::string removeStringFormat(std::string s)