ROL
ROL_TypeU_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_TYPEU_ALGORITHM_FACTORY_H
11#define ROL_TYPEU_ALGORITHM_FACTORY_H
12
16#include "ROL_Types.hpp"
17
18namespace ROL {
19namespace TypeU {
20
34
35inline std::string EAlgorithmUToString(EAlgorithmU alg) {
36 std::string retString;
37 switch(alg) {
38 case ALGORITHM_U_BUNDLE: retString = "Bundle"; break;
39 case ALGORITHM_U_LINESEARCH: retString = "Line Search"; break;
40 case ALGORITHM_U_TRUSTREGION: retString = "Trust Region"; break;
41 case ALGORITHM_U_LAST: retString = "Last Type (Dummy)"; break;
42 default: retString = "INVALID EAlgorithmU";
43 }
44 return retString;
45}
46
53 return( (alg == ALGORITHM_U_BUNDLE) ||
54 (alg == ALGORITHM_U_LINESEARCH) ||
55 (alg == ALGORITHM_U_TRUSTREGION) ||
56 (alg == ALGORITHM_U_LAST)
57 );
58}
59
61 return type = static_cast<EAlgorithmU>(type+1);
62}
63
65 EAlgorithmU oldval = type;
66 ++type;
67 return oldval;
68}
69
71 return type = static_cast<EAlgorithmU>(type-1);
72}
73
75 EAlgorithmU oldval = type;
76 --type;
77 return oldval;
78}
79
80inline EAlgorithmU StringToEAlgorithmU(std::string s) {
81 s = removeStringFormat(s);
82 for ( EAlgorithmU alg = ALGORITHM_U_BUNDLE; alg < ALGORITHM_U_LAST; alg++ ) {
83 if ( !s.compare(removeStringFormat(EAlgorithmUToString(alg))) ) {
84 return alg;
85 }
86 }
88}
89
90template<typename Real>
91inline Ptr<Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
92 std::string stepType = parlist.sublist("Step").get("Type","Trust Region");
93 EAlgorithmU ealg = StringToEAlgorithmU(stepType);
94 switch(ealg) {
95 case ALGORITHM_U_BUNDLE: return makePtr<BundleAlgorithm<Real>>(parlist);
96 case ALGORITHM_U_LINESEARCH: return makePtr<LineSearchAlgorithm<Real>>(parlist,secant);
97 case ALGORITHM_U_TRUSTREGION: return makePtr<TrustRegionAlgorithm<Real>>(parlist,secant);
98 default: return nullPtr;
99 }
100}
101
102} // namespace TypeU
103} // namespace ROL
104
105#endif
Contains definitions of custom data types in ROL.
Provides interface for and implements limited-memory secant operators.
EAlgorithmU & operator--(EAlgorithmU &type)
EAlgorithmU StringToEAlgorithmU(std::string s)
EAlgorithmU & operator++(EAlgorithmU &type)
int isValidAlgorithmU(EAlgorithmU alg)
Verifies validity of a AlgorithmU enum.
std::string EAlgorithmUToString(EAlgorithmU alg)
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
std::string removeStringFormat(std::string s)