ROL
ROL_TypeG_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_TYPEG_ALGORITHMFACTORY_H
45 #define ROL_TYPEG_ALGORITHMFACTORY_H
46 
51 #include "ROL_Types.hpp"
52 
53 namespace ROL {
54 namespace TypeG {
55 
70 };
71 
72 inline std::string EAlgorithmGToString(EAlgorithmG alg) {
73  std::string retString;
74  switch(alg) {
75  case ALGORITHM_G_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
76  case ALGORITHM_G_MOREAUYOSIDA: retString = "Moreau-Yosida"; break;
77  case ALGORITHM_G_INTERIORPOINT: retString = "Interior Point"; break;
78  case ALGORITHM_G_STABILIZEDLCL: retString = "Stabilized LCL"; break;
79  case ALGORITHM_G_LAST: retString = "Last Type (Dummy)"; break;
80  default: retString = "INVALID EAlgorithmG";
81  }
82  return retString;
83 }
84 
91  return( (alg == ALGORITHM_G_AUGMENTEDLAGRANGIAN) ||
92  (alg == ALGORITHM_G_MOREAUYOSIDA) ||
93  (alg == ALGORITHM_G_INTERIORPOINT) ||
94  (alg == ALGORITHM_G_STABILIZEDLCL) ||
95  (alg == ALGORITHM_G_LAST)
96  );
97 }
98 
100  return type = static_cast<EAlgorithmG>(type+1);
101 }
102 
103 inline EAlgorithmG operator++(EAlgorithmG &type, int) {
104  EAlgorithmG oldval = type;
105  ++type;
106  return oldval;
107 }
108 
110  return type = static_cast<EAlgorithmG>(type-1);
111 }
112 
113 inline EAlgorithmG operator--(EAlgorithmG &type, int) {
114  EAlgorithmG oldval = type;
115  --type;
116  return oldval;
117 }
118 
119 inline EAlgorithmG StringToEAlgorithmG(std::string s) {
120  s = removeStringFormat(s);
121  for ( EAlgorithmG alg = ALGORITHM_G_AUGMENTEDLAGRANGIAN; alg < ALGORITHM_G_LAST; alg++ ) {
122  if ( !s.compare(removeStringFormat(EAlgorithmGToString(alg))) ) {
123  return alg;
124  }
125  }
127 }
128 
129 template<typename Real>
130 inline Ptr<TypeG::Algorithm<Real>> AlgorithmFactory(ParameterList &parlist, const Ptr<Secant<Real>> &secant = nullPtr) {
131  EAlgorithmG ealg = StringToEAlgorithmG(parlist.sublist("Step").get("Type","Augmented Lagrangian"));
132  switch(ealg) {
133  case ALGORITHM_G_AUGMENTEDLAGRANGIAN: return makePtr<TypeG::AugmentedLagrangianAlgorithm<Real>>(parlist,secant);
134  case ALGORITHM_G_MOREAUYOSIDA: return makePtr<TypeG::MoreauYosidaAlgorithm<Real>>(parlist,secant);
135  case ALGORITHM_G_INTERIORPOINT: return makePtr<TypeG::InteriorPointAlgorithm<Real>>(parlist,secant);
136  case ALGORITHM_G_STABILIZEDLCL: return makePtr<TypeG::StabilizedLCLAlgorithm<Real>>(parlist,secant);
137  default: return nullPtr;
138  }
139 }
140 } // namespace TypeG
141 } // namespace ROL
142 
143 #endif
EAlgorithmG
Enumeration of generally constrained algorithm types.
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:249
EAlgorithmG StringToEAlgorithmG(std::string s)
std::string EAlgorithmGToString(EAlgorithmG alg)
Ptr< TypeG::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real >> &secant=nullPtr)
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:79
EAlgorithmG & operator++(EAlgorithmG &type)
EAlgorithmG & operator--(EAlgorithmG &type)
int isValidAlgorithmG(EAlgorithmG alg)
Verifies validity of a AlgorithmG enum.