ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
algorithm
TypeP
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
13
#include "
ROL_TypeP_ProxGradientAlgorithm.hpp
"
14
#include "
ROL_TypeP_SpectralGradientAlgorithm.hpp
"
15
#include "
ROL_TypeP_iPianoAlgorithm.hpp
"
16
#include "
ROL_TypeP_QuasiNewtonAlgorithm.hpp
"
17
#include "
ROL_TypeP_TrustRegionAlgorithm.hpp
"
18
#include "
ROL_TypeP_InexactNewtonAlgorithm.hpp
"
19
#include "
ROL_Types.hpp
"
20
21
namespace
ROL
{
22
namespace
TypeP
{
23
32
enum
EAlgorithmP
{
33
ALGORITHM_P_LINESEARCH
= 0,
34
ALGORITHM_P_TRUSTREGION
,
35
ALGORITHM_P_SPECTRALGRADIENT
,
36
ALGORITHM_P_IPIANO
,
37
ALGORITHM_P_LAST
38
};
39
40
inline
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
58
inline
int
isValidAlgorithmP
(
EAlgorithmP
alg){
59
return
( (alg ==
ALGORITHM_P_LINESEARCH
) ||
60
(alg ==
ALGORITHM_P_TRUSTREGION
) ||
61
(alg ==
ALGORITHM_P_SPECTRALGRADIENT
) ||
62
(alg ==
ALGORITHM_P_IPIANO
) ||
63
(alg ==
ALGORITHM_P_LAST
)
64
);
65
}
66
67
inline
EAlgorithmP
&
operator++
(
EAlgorithmP
&type) {
68
return
type =
static_cast<
EAlgorithmP
>
(type+1);
69
}
70
71
inline
EAlgorithmP
operator++
(
EAlgorithmP
&type,
int
) {
72
EAlgorithmP
oldval = type;
73
++type;
74
return
oldval;
75
}
76
77
inline
EAlgorithmP
&
operator--
(
EAlgorithmP
&type) {
78
return
type =
static_cast<
EAlgorithmP
>
(type-1);
79
}
80
81
inline
EAlgorithmP
operator--
(
EAlgorithmP
&type,
int
) {
82
EAlgorithmP
oldval = type;
83
--type;
84
return
oldval;
85
}
86
87
inline
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
}
94
return
ALGORITHM_P_TRUSTREGION
;
95
}
96
97
template
<
typename
Real>
98
inline
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) {
102
case
ALGORITHM_P_LINESEARCH
:
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
ROL_TypeP_InexactNewtonAlgorithm.hpp
ROL_TypeP_ProxGradientAlgorithm.hpp
ROL_TypeP_QuasiNewtonAlgorithm.hpp
ROL_TypeP_SpectralGradientAlgorithm.hpp
ROL_TypeP_TrustRegionAlgorithm.hpp
ROL_TypeP_iPianoAlgorithm.hpp
ROL_Types.hpp
Contains definitions of custom data types in ROL.
ROL::Secant
Provides interface for and implements limited-memory secant operators.
Definition
ROL_Secant.hpp:45
ROL::TypeP
Definition
ROL_TypeP_Algorithm.hpp:22
ROL::TypeP::EAlgorithmPToString
std::string EAlgorithmPToString(EAlgorithmP alg)
Definition
ROL_TypeP_AlgorithmFactory.hpp:40
ROL::TypeP::EAlgorithmP
EAlgorithmP
Definition
ROL_TypeP_AlgorithmFactory.hpp:32
ROL::TypeP::ALGORITHM_P_SPECTRALGRADIENT
@ ALGORITHM_P_SPECTRALGRADIENT
Definition
ROL_TypeP_AlgorithmFactory.hpp:35
ROL::TypeP::ALGORITHM_P_IPIANO
@ ALGORITHM_P_IPIANO
Definition
ROL_TypeP_AlgorithmFactory.hpp:36
ROL::TypeP::ALGORITHM_P_LINESEARCH
@ ALGORITHM_P_LINESEARCH
Definition
ROL_TypeP_AlgorithmFactory.hpp:33
ROL::TypeP::ALGORITHM_P_LAST
@ ALGORITHM_P_LAST
Definition
ROL_TypeP_AlgorithmFactory.hpp:37
ROL::TypeP::ALGORITHM_P_TRUSTREGION
@ ALGORITHM_P_TRUSTREGION
Definition
ROL_TypeP_AlgorithmFactory.hpp:34
ROL::TypeP::AlgorithmFactory
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeP_AlgorithmFactory.hpp:98
ROL::TypeP::isValidAlgorithmP
int isValidAlgorithmP(EAlgorithmP alg)
Verifies validity of a AlgorithmP enum.
Definition
ROL_TypeP_AlgorithmFactory.hpp:58
ROL::TypeP::StringToEAlgorithmP
EAlgorithmP StringToEAlgorithmP(std::string s)
Definition
ROL_TypeP_AlgorithmFactory.hpp:87
ROL::TypeP::operator--
EAlgorithmP & operator--(EAlgorithmP &type)
Definition
ROL_TypeP_AlgorithmFactory.hpp:77
ROL::TypeP::operator++
EAlgorithmP & operator++(EAlgorithmP &type)
Definition
ROL_TypeP_AlgorithmFactory.hpp:67
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::removeStringFormat
std::string removeStringFormat(std::string s)
Definition
ROL_Types.hpp:215
Generated by
1.17.0