ROL
ROL_TypeB_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_TYPEB_ALGORITHMFACTORY_H
11#define ROL_TYPEB_ALGORITHMFACTORY_H
12
25#include "ROL_Types.hpp"
26
27namespace ROL {
28namespace TypeB {
29
49
50inline std::string EAlgorithmBToString(EAlgorithmB alg) {
51 std::string retString;
52 switch(alg) {
53 case ALGORITHM_B_LINESEARCH: retString = "Line Search"; break;
54 case ALGORITHM_B_TRUSTREGION: retString = "Trust Region"; break;
55 case ALGORITHM_B_MOREAUYOSIDA: retString = "Moreau-Yosida"; break;
56 case ALGORITHM_B_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
57 case ALGORITHM_B_INTERIORPOINT: retString = "Interior Point"; break;
58 case ALGORITHM_B_SPECTRALGRADIENT: retString = "Spectral Gradient"; break;
59 case ALGORITHM_B_LAST: retString = "Last Type (Dummy)"; break;
60 default: retString = "INVALID EAlgorithmB";
61 }
62 return retString;
63}
64
71 return( (alg == ALGORITHM_B_LINESEARCH) ||
72 (alg == ALGORITHM_B_TRUSTREGION) ||
73 (alg == ALGORITHM_B_MOREAUYOSIDA) ||
77 (alg == ALGORITHM_B_LAST)
78 );
79}
80
82 return type = static_cast<EAlgorithmB>(type+1);
83}
84
86 EAlgorithmB oldval = type;
87 ++type;
88 return oldval;
89}
90
92 return type = static_cast<EAlgorithmB>(type-1);
93}
94
96 EAlgorithmB oldval = type;
97 --type;
98 return oldval;
99}
100
101inline EAlgorithmB StringToEAlgorithmB(std::string s) {
102 s = removeStringFormat(s);
103 for ( EAlgorithmB alg = ALGORITHM_B_LINESEARCH; alg < ALGORITHM_B_LAST; alg++ ) {
104 if ( !s.compare(removeStringFormat(EAlgorithmBToString(alg))) ) {
105 return alg;
106 }
107 }
109}
110
111template<typename Real>
112inline Ptr<Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
113 std::string stepType = parlist.sublist("Step").get("Type","Trust Region");
114 EAlgorithmB ealg = StringToEAlgorithmB(stepType);
115 switch(ealg) {
117 {
118 std::string desc = parlist.sublist("Step").sublist("Line Search").sublist("Descent Method").get("Type","Newton-Krylov");
119 if (desc=="Newton-Krylov" || desc=="Newton")
120 return makePtr<NewtonKrylovAlgorithm<Real>>(parlist,secant);
121 else if (desc=="Quasi-Newton Method" || desc=="Quasi-Newton") {
122 std::string method = parlist.sublist("Step").sublist("Line Search").sublist("Quasi-Newton").get("Method","L-Secant-B");
123 if (method == "L-Secant-B")
124 return makePtr<LSecantBAlgorithm<Real>>(parlist,secant); // Similar to L-BFGS-B
125 else
126 return makePtr<QuasiNewtonAlgorithm<Real>>(parlist,secant); // PQN
127 }
128 else {
129 return makePtr<GradientAlgorithm<Real>>(parlist);
130 }
131 }
133 {
134 std::string trmod = parlist.sublist("Step").sublist("Trust Region").get("Subproblem Model","Lin-More");
135 if (trmod=="Kelley-Sachs")
136 return makePtr<KelleySachsAlgorithm<Real>>(parlist,secant);
137 else if (trmod=="SPG")
138 return makePtr<TrustRegionSPGAlgorithm<Real>>(parlist,secant);
139 else if (trmod=="Coleman-Li")
140 return makePtr<ColemanLiAlgorithm<Real>>(parlist,secant);
141 else
142 return makePtr<LinMoreAlgorithm<Real>>(parlist,secant);
143 }
144 case ALGORITHM_B_MOREAUYOSIDA: return makePtr<MoreauYosidaAlgorithm<Real>>(parlist,secant);
145 case ALGORITHM_B_PRIMALDUALACTIVESET: return makePtr<PrimalDualActiveSetAlgorithm<Real>>(parlist,secant);
146 case ALGORITHM_B_INTERIORPOINT: return makePtr<InteriorPointAlgorithm<Real>>(parlist,secant);
147 case ALGORITHM_B_SPECTRALGRADIENT: return makePtr<SpectralGradientAlgorithm<Real>>(parlist);
148 default: return nullPtr;
149 }
150}
151} // namespace TypeB
152} // namespace ROL
153
154#endif
Contains definitions of custom data types in ROL.
Provides interface for and implements limited-memory secant operators.
EAlgorithmB StringToEAlgorithmB(std::string s)
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
EAlgorithmB & operator--(EAlgorithmB &type)
EAlgorithmB & operator++(EAlgorithmB &type)
std::string EAlgorithmBToString(EAlgorithmB alg)
int isValidAlgorithmB(EAlgorithmB alg)
Verifies validity of a AlgorithmB enum.
std::string removeStringFormat(std::string s)