ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
algorithm
TypeB
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
13
#include "
ROL_TypeB_GradientAlgorithm.hpp
"
14
#include "
ROL_TypeB_NewtonKrylovAlgorithm.hpp
"
15
#include "
ROL_TypeB_LinMoreAlgorithm.hpp
"
16
#include "
ROL_TypeB_MoreauYosidaAlgorithm.hpp
"
17
#include "
ROL_TypeB_InteriorPointAlgorithm.hpp
"
18
#include "
ROL_TypeB_PrimalDualActiveSetAlgorithm.hpp
"
19
#include "
ROL_TypeB_KelleySachsAlgorithm.hpp
"
20
#include "
ROL_TypeB_SpectralGradientAlgorithm.hpp
"
21
#include "
ROL_TypeB_LSecantBAlgorithm.hpp
"
22
#include "
ROL_TypeB_QuasiNewtonAlgorithm.hpp
"
23
#include "
ROL_TypeB_TrustRegionSPGAlgorithm.hpp
"
24
#include "
ROL_TypeB_ColemanLiAlgorithm.hpp
"
25
#include "
ROL_Types.hpp
"
26
27
namespace
ROL
{
28
namespace
TypeB
{
29
40
enum
EAlgorithmB
{
41
ALGORITHM_B_LINESEARCH
= 0,
42
ALGORITHM_B_TRUSTREGION
,
43
ALGORITHM_B_MOREAUYOSIDA
,
44
ALGORITHM_B_PRIMALDUALACTIVESET
,
45
ALGORITHM_B_INTERIORPOINT
,
46
ALGORITHM_B_SPECTRALGRADIENT
,
47
ALGORITHM_B_LAST
48
};
49
50
inline
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
70
inline
int
isValidAlgorithmB
(
EAlgorithmB
alg){
71
return
( (alg ==
ALGORITHM_B_LINESEARCH
) ||
72
(alg ==
ALGORITHM_B_TRUSTREGION
) ||
73
(alg ==
ALGORITHM_B_MOREAUYOSIDA
) ||
74
(alg ==
ALGORITHM_B_PRIMALDUALACTIVESET
) ||
75
(alg ==
ALGORITHM_B_INTERIORPOINT
) ||
76
(alg ==
ALGORITHM_B_SPECTRALGRADIENT
) ||
77
(alg ==
ALGORITHM_B_LAST
)
78
);
79
}
80
81
inline
EAlgorithmB
&
operator++
(
EAlgorithmB
&type) {
82
return
type =
static_cast<
EAlgorithmB
>
(type+1);
83
}
84
85
inline
EAlgorithmB
operator++
(
EAlgorithmB
&type,
int
) {
86
EAlgorithmB
oldval = type;
87
++type;
88
return
oldval;
89
}
90
91
inline
EAlgorithmB
&
operator--
(
EAlgorithmB
&type) {
92
return
type =
static_cast<
EAlgorithmB
>
(type-1);
93
}
94
95
inline
EAlgorithmB
operator--
(
EAlgorithmB
&type,
int
) {
96
EAlgorithmB
oldval = type;
97
--type;
98
return
oldval;
99
}
100
101
inline
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
}
108
return
ALGORITHM_B_TRUSTREGION
;
109
}
110
111
template
<
typename
Real>
112
inline
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) {
116
case
ALGORITHM_B_LINESEARCH
:
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
}
132
case
ALGORITHM_B_TRUSTREGION
:
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
ROL_TypeB_ColemanLiAlgorithm.hpp
ROL_TypeB_GradientAlgorithm.hpp
ROL_TypeB_InteriorPointAlgorithm.hpp
ROL_TypeB_KelleySachsAlgorithm.hpp
ROL_TypeB_LSecantBAlgorithm.hpp
ROL_TypeB_LinMoreAlgorithm.hpp
ROL_TypeB_MoreauYosidaAlgorithm.hpp
ROL_TypeB_NewtonKrylovAlgorithm.hpp
ROL_TypeB_PrimalDualActiveSetAlgorithm.hpp
ROL_TypeB_QuasiNewtonAlgorithm.hpp
ROL_TypeB_SpectralGradientAlgorithm.hpp
ROL_TypeB_TrustRegionSPGAlgorithm.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::TypeB
Definition
ROL_TypeB_Algorithm.hpp:25
ROL::TypeB::StringToEAlgorithmB
EAlgorithmB StringToEAlgorithmB(std::string s)
Definition
ROL_TypeB_AlgorithmFactory.hpp:101
ROL::TypeB::AlgorithmFactory
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeB_AlgorithmFactory.hpp:112
ROL::TypeB::operator--
EAlgorithmB & operator--(EAlgorithmB &type)
Definition
ROL_TypeB_AlgorithmFactory.hpp:91
ROL::TypeB::operator++
EAlgorithmB & operator++(EAlgorithmB &type)
Definition
ROL_TypeB_AlgorithmFactory.hpp:81
ROL::TypeB::EAlgorithmBToString
std::string EAlgorithmBToString(EAlgorithmB alg)
Definition
ROL_TypeB_AlgorithmFactory.hpp:50
ROL::TypeB::EAlgorithmB
EAlgorithmB
Definition
ROL_TypeB_AlgorithmFactory.hpp:40
ROL::TypeB::ALGORITHM_B_PRIMALDUALACTIVESET
@ ALGORITHM_B_PRIMALDUALACTIVESET
Definition
ROL_TypeB_AlgorithmFactory.hpp:44
ROL::TypeB::ALGORITHM_B_MOREAUYOSIDA
@ ALGORITHM_B_MOREAUYOSIDA
Definition
ROL_TypeB_AlgorithmFactory.hpp:43
ROL::TypeB::ALGORITHM_B_SPECTRALGRADIENT
@ ALGORITHM_B_SPECTRALGRADIENT
Definition
ROL_TypeB_AlgorithmFactory.hpp:46
ROL::TypeB::ALGORITHM_B_INTERIORPOINT
@ ALGORITHM_B_INTERIORPOINT
Definition
ROL_TypeB_AlgorithmFactory.hpp:45
ROL::TypeB::ALGORITHM_B_LAST
@ ALGORITHM_B_LAST
Definition
ROL_TypeB_AlgorithmFactory.hpp:47
ROL::TypeB::ALGORITHM_B_TRUSTREGION
@ ALGORITHM_B_TRUSTREGION
Definition
ROL_TypeB_AlgorithmFactory.hpp:42
ROL::TypeB::ALGORITHM_B_LINESEARCH
@ ALGORITHM_B_LINESEARCH
Definition
ROL_TypeB_AlgorithmFactory.hpp:41
ROL::TypeB::isValidAlgorithmB
int isValidAlgorithmB(EAlgorithmB alg)
Verifies validity of a AlgorithmB enum.
Definition
ROL_TypeB_AlgorithmFactory.hpp:70
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::removeStringFormat
std::string removeStringFormat(std::string s)
Definition
ROL_Types.hpp:215
Generated by
1.17.0