ROL
ROL_TypeP_AlgorithmFactory.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_TYPEP_ALGORITHMFACTORY_H
45#define ROL_TYPEP_ALGORITHMFACTORY_H
46
53#include "ROL_Types.hpp"
54
55namespace ROL {
56namespace TypeP {
57
73
74inline std::string EAlgorithmPToString(EAlgorithmP alg) {
75 std::string retString;
76 switch(alg) {
77 case ALGORITHM_P_LINESEARCH: retString = "Line Search"; break;
78 case ALGORITHM_P_TRUSTREGION: retString = "Trust Region"; break;
79 case ALGORITHM_P_SPECTRALGRADIENT: retString = "Spectral Gradient"; break;
80 case ALGORITHM_P_IPIANO: retString = "iPiano"; break;
81 case ALGORITHM_P_LAST: retString = "Last Type (Dummy)"; break;
82 default: retString = "INVALID EAlgorithmP";
83 }
84 return retString;
85}
86
93 return( (alg == ALGORITHM_P_LINESEARCH) ||
94 (alg == ALGORITHM_P_TRUSTREGION) ||
96 (alg == ALGORITHM_P_IPIANO) ||
97 (alg == ALGORITHM_P_LAST)
98 );
99}
100
102 return type = static_cast<EAlgorithmP>(type+1);
103}
104
106 EAlgorithmP oldval = type;
107 ++type;
108 return oldval;
109}
110
112 return type = static_cast<EAlgorithmP>(type-1);
113}
114
116 EAlgorithmP oldval = type;
117 --type;
118 return oldval;
119}
120
121inline EAlgorithmP StringToEAlgorithmP(std::string s) {
122 s = removeStringFormat(s);
123 for ( EAlgorithmP alg = ALGORITHM_P_LINESEARCH; alg < ALGORITHM_P_LAST; alg++ ) {
124 if ( !s.compare(removeStringFormat(EAlgorithmPToString(alg))) ) {
125 return alg;
126 }
127 }
129}
130
131template<typename Real>
132inline Ptr<Algorithm<Real>> AlgorithmFactory(ParameterList &parlist) {
133 EAlgorithmP ealg = StringToEAlgorithmP(parlist.sublist("Step").get("Type","Trust Region"));
134 switch(ealg) {
136 {
137 std::string desc
138 = parlist.sublist("Step").sublist("Line Search").sublist("Descent Method").get("Type","Newton-Krylov");
139 if (desc=="Newton-Krylov" || desc=="Newton")
140 return makePtr<InexactNewtonAlgorithm<Real>>(parlist);
141 else if (desc=="Quasi-Newton Method" || desc = "Quasi-Newton")
142 return makePtr<QuasiNewtonAlgorithm<Real>>(parlist);
143 else
144 return makePtr<ProxGradientAlgorithm<Real>>(parlist);
145 }
146 case ALGORITHM_P_TRUSTREGION: return makePtr<TrustRegionAlgorithm<Real>>(parlist);
147 case ALGORITHM_P_SPECTRALGRADIENT: return makePtr<SpectralGradientAlgorithm<Real>>(parlist);
148 case ALGORITHM_P_IPIANO: return makePtr<iPianoAlgorithm<Real>>(parlist);
149 default: return nullPtr;
150 }
151}
152} // namespace TypeP
153} // namespace ROL
154
155#endif
Contains definitions of custom data types in ROL.
std::string EAlgorithmPToString(EAlgorithmP alg)
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist)
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)