ROL
ROL_TypeG_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_TYPEG_ALGORITHMFACTORY_H
11#define ROL_TYPEG_ALGORITHMFACTORY_H
12
17#include "ROL_Types.hpp"
18
19namespace ROL {
20namespace TypeG {
21
37
38inline std::string EAlgorithmGToString(EAlgorithmG alg) {
39 std::string retString;
40 switch(alg) {
41 case ALGORITHM_G_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
42 case ALGORITHM_G_MOREAUYOSIDA: retString = "Moreau-Yosida"; break;
43 case ALGORITHM_G_INTERIORPOINT: retString = "Interior Point"; break;
44 case ALGORITHM_G_STABILIZEDLCL: retString = "Stabilized LCL"; break;
45 case ALGORITHM_G_LAST: retString = "Last Type (Dummy)"; break;
46 default: retString = "INVALID EAlgorithmG";
47 }
48 return retString;
49}
50
57 return( (alg == ALGORITHM_G_AUGMENTEDLAGRANGIAN) ||
58 (alg == ALGORITHM_G_MOREAUYOSIDA) ||
61 (alg == ALGORITHM_G_LAST)
62 );
63}
64
66 return type = static_cast<EAlgorithmG>(type+1);
67}
68
70 EAlgorithmG oldval = type;
71 ++type;
72 return oldval;
73}
74
76 return type = static_cast<EAlgorithmG>(type-1);
77}
78
80 EAlgorithmG oldval = type;
81 --type;
82 return oldval;
83}
84
85inline EAlgorithmG StringToEAlgorithmG(std::string s) {
86 s = removeStringFormat(s);
88 if ( !s.compare(removeStringFormat(EAlgorithmGToString(alg))) ) {
89 return alg;
90 }
91 }
93}
94
95template<typename Real>
96inline Ptr<TypeG::Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
97 std::string stepType = parlist.sublist("Step").get("Type","Augmented Lagrangian");
98 EAlgorithmG ealg = StringToEAlgorithmG(stepType);
99 switch(ealg) {
100 case ALGORITHM_G_AUGMENTEDLAGRANGIAN: return makePtr<TypeG::AugmentedLagrangianAlgorithm<Real>>(parlist,secant);
101 case ALGORITHM_G_MOREAUYOSIDA: return makePtr<TypeG::MoreauYosidaAlgorithm<Real>>(parlist,secant);
102 case ALGORITHM_G_INTERIORPOINT: return makePtr<TypeG::InteriorPointAlgorithm<Real>>(parlist,secant);
103 case ALGORITHM_G_STABILIZEDLCL: return makePtr<TypeG::StabilizedLCLAlgorithm<Real>>(parlist,secant);
104 default: return nullPtr;
105 }
106}
107} // namespace TypeG
108} // namespace ROL
109
110#endif
Contains definitions of custom data types in ROL.
Provides interface for and implements limited-memory secant operators.
EAlgorithmG StringToEAlgorithmG(std::string s)
EAlgorithmG & operator++(EAlgorithmG &type)
EAlgorithmG & operator--(EAlgorithmG &type)
std::string EAlgorithmGToString(EAlgorithmG alg)
int isValidAlgorithmG(EAlgorithmG alg)
Verifies validity of a AlgorithmG enum.
Ptr< TypeG::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
std::string removeStringFormat(std::string s)