ROL
ROL_ProbabilityFactory.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_PROBABILITYFACTORY_HPP
11#define ROL_PROBABILITYFACTORY_HPP
12
13#include "ROL_ParameterList.hpp"
14
15#include "ROL_Types.hpp"
16#include "ROL_BPOE.hpp"
17#include "ROL_SmoothedPOE.hpp"
18
19namespace ROL {
20
26
27 inline std::string EProbabilityToString(EProbability ed) {
28 std::string retString;
29 switch(ed) {
31 retString = "bPOE"; break;
33 retString = "Smoothed POE"; break;
35 retString = "Last Type (Dummy)"; break;
36 default:
37 retString = "INVALID EProbability"; break;
38 }
39 return retString;
40 }
41
43 return( (ed == PROBABILITY_BPOE) ||
45 }
46
48 return type = static_cast<EProbability>(type+1);
49 }
50
52 EProbability oldval = type;
53 ++type;
54 return oldval;
55 }
56
58 return type = static_cast<EProbability>(type-1);
59 }
60
62 EProbability oldval = type;
63 --type;
64 return oldval;
65 }
66
67 inline EProbability StringToEProbability(std::string s) {
68 s = removeStringFormat(s);
69 for ( EProbability tr = PROBABILITY_BPOE; tr < PROBABILITY_LAST; tr++ ) {
70 if ( !s.compare(removeStringFormat(EProbabilityToString(tr))) ) {
71 return tr;
72 }
73 }
74 return PROBABILITY_LAST;
75 }
76
77 template<class Real>
78 inline Ptr<RandVarFunctional<Real>> ProbabilityFactory(ParameterList &parlist) {
79 std::string prob = parlist.sublist("SOL").sublist("Probability").get("Name","bPOE");
81 switch(ed) {
83 return makePtr<BPOE<Real>>(parlist);
85 return makePtr<SmoothedPOE<Real>>(parlist);
86 default:
87 ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
88 "Invalid probability type " << prob << "!");
89 }
90 }
91}
92#endif
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Ptr< RandVarFunctional< Real > > ProbabilityFactory(ParameterList &parlist)
std::string EProbabilityToString(EProbability ed)
EPolyProjAlgo & operator--(EPolyProjAlgo &type)
EPolyProjAlgo & operator++(EPolyProjAlgo &type)
int isValidProbability(EProbability ed)
EProbability StringToEProbability(std::string s)