20 #ifndef _OPTFACTORY_H_ 21 #define _OPTFACTORY_H_ 28 static void initMap(std::map<std::string, nlopt::algorithm>& m_algMap){
30 m_algMap[
"GN_DIRECT"]=nlopt::GN_DIRECT;
31 m_algMap[
"GN_DIRECT_L"]=nlopt::GN_DIRECT_L;
32 m_algMap[
"GN_DIRECT_L_RAND"]=nlopt::GN_DIRECT_L_RAND;
33 m_algMap[
"GN_DIRECT_NOSCAL"]=nlopt::GN_DIRECT_NOSCAL;
34 m_algMap[
"GN_DIRECT_L_NOSCAL"]=nlopt::GN_DIRECT_L_NOSCAL;
35 m_algMap[
"GN_DIRECT_L_RAND_NOSCAL"]=nlopt::GN_DIRECT_L_RAND_NOSCAL;
36 m_algMap[
"GN_ORIG_DIRECT"]=nlopt::GN_ORIG_DIRECT;
37 m_algMap[
"GN_ORIG_DIRECT_L"]=nlopt::GN_ORIG_DIRECT_L;
38 m_algMap[
"GD_STOGO"]=nlopt::GD_STOGO;
39 m_algMap[
"GD_STOGO_RAND"]=nlopt::GD_STOGO_RAND;
40 m_algMap[
"LD_LBFGS_NOCEDAL"]=nlopt::LD_LBFGS_NOCEDAL;
41 m_algMap[
"LD_LBFGS"]=nlopt::LD_LBFGS;
42 m_algMap[
"LN_PRAXIS"]=nlopt::LN_PRAXIS;
43 m_algMap[
"LD_VAR1"]=nlopt::LD_VAR1;
44 m_algMap[
"LD_VAR2"]=nlopt::LD_VAR2;
45 m_algMap[
"LD_TNEWTON"]=nlopt::LD_TNEWTON;
46 m_algMap[
"LD_TNEWTON_RESTART"]=nlopt::LD_TNEWTON_RESTART;
47 m_algMap[
"LD_TNEWTON_PRECOND"]=nlopt::LD_TNEWTON_PRECOND;
48 m_algMap[
"LD_TNEWTON_PRECOND_RESTART"]=nlopt::LD_TNEWTON_PRECOND_RESTART;
49 m_algMap[
"GN_CRS2_LM"]=nlopt::GN_CRS2_LM;
50 m_algMap[
"GN_MLSL"]=nlopt::GN_MLSL;
51 m_algMap[
"GD_MLSL"]=nlopt::GD_MLSL;
52 m_algMap[
"GN_MLSL_LDS"]=nlopt::GN_MLSL_LDS;
53 m_algMap[
"GD_MLSL_LDS"]=nlopt::GD_MLSL_LDS;
54 m_algMap[
"LD_MMA"]=nlopt::LD_MMA;
55 m_algMap[
"LN_COBYLA"]=nlopt::LN_COBYLA;
56 m_algMap[
"LN_NEWUOA"]=nlopt::LN_NEWUOA;
57 m_algMap[
"LN_NEWUOA_BOUND"]=nlopt::LN_NEWUOA_BOUND;
58 m_algMap[
"LN_NELDERMEAD"]=nlopt::LN_NELDERMEAD;
59 m_algMap[
"LN_SBPLX"]=nlopt::LN_SBPLX;
60 m_algMap[
"LN_AUGLAG"]=nlopt::LN_AUGLAG;
61 m_algMap[
"LD_AUGLAG"]=nlopt::LD_AUGLAG;
62 m_algMap[
"LN_AUGLAG_EQ"]=nlopt::LN_AUGLAG_EQ;
63 m_algMap[
"LD_AUGLAG_EQ"]=nlopt::LD_AUGLAG_EQ;
64 m_algMap[
"LN_BOBYQA"]=nlopt::LN_BOBYQA;
65 m_algMap[
"GN_ISRES"]=nlopt::GN_ISRES;
66 m_algMap[
"AUGLAG"]=nlopt::AUGLAG;
67 m_algMap[
"AUGLAG_EQ"]=nlopt::AUGLAG_EQ;
68 m_algMap[
"G_MLSL"]=nlopt::G_MLSL;
69 m_algMap[
"G_MLSL_LDS"]=nlopt::G_MLSL_LDS;
70 m_algMap[
"LD_SLSQP "]=nlopt::LD_SLSQP;
76 static nlopt::opt getOptimizer(
const std::string& algorithmString,
unsigned int npar){
77 std::map<std::string, nlopt::algorithm> m_algMap;
79 switch(m_algMap[algorithmString]){
80 case(nlopt::GN_DIRECT):{
81 nlopt::opt theOptimizer(nlopt::GN_DIRECT,npar);
85 case(nlopt::GN_DIRECT_L):{
86 nlopt::opt theOptimizer(nlopt::GN_DIRECT_L,npar);
90 case(nlopt::GN_DIRECT_L_RAND):{
91 nlopt::opt theOptimizer(nlopt::GN_DIRECT_L_RAND,npar);
95 case(nlopt::GN_DIRECT_NOSCAL):{
96 nlopt::opt theOptimizer(nlopt::GN_DIRECT_NOSCAL,npar);
100 case(nlopt::GN_DIRECT_L_NOSCAL):{
101 nlopt::opt theOptimizer(nlopt::GN_DIRECT_L_NOSCAL,npar);
102 return(theOptimizer);
105 case(nlopt::GN_DIRECT_L_RAND_NOSCAL):{
106 nlopt::opt theOptimizer(nlopt::GN_DIRECT_L_RAND_NOSCAL,npar);
107 return(theOptimizer);
110 case(nlopt::GN_ORIG_DIRECT):{
111 nlopt::opt theOptimizer(nlopt::GN_ORIG_DIRECT,npar);
112 return(theOptimizer);
115 case(nlopt::GN_ORIG_DIRECT_L):{
116 nlopt::opt theOptimizer(nlopt::GN_ORIG_DIRECT_L,npar);
117 return(theOptimizer);
120 case(nlopt::LN_PRAXIS):{
121 nlopt::opt theOptimizer(nlopt::LN_PRAXIS,npar);
122 return(theOptimizer);
125 case(nlopt::GN_CRS2_LM):{
126 nlopt::opt theOptimizer(nlopt::GN_CRS2_LM,npar);
127 return(theOptimizer);
130 case(nlopt::GN_MLSL):{
131 nlopt::opt theOptimizer(nlopt::GN_MLSL,npar);
132 return(theOptimizer);
135 case(nlopt::GN_MLSL_LDS):{
136 nlopt::opt theOptimizer(nlopt::GN_MLSL_LDS,npar);
137 return(theOptimizer);
140 case(nlopt::LN_COBYLA):{
141 nlopt::opt theOptimizer(nlopt::LN_COBYLA,npar);
142 return(theOptimizer);
145 case(nlopt::LN_NEWUOA):{
146 nlopt::opt theOptimizer(nlopt::LN_NEWUOA,npar);
147 return(theOptimizer);
150 case(nlopt::LN_NEWUOA_BOUND):{
151 nlopt::opt theOptimizer(nlopt::LN_NEWUOA_BOUND,npar);
152 return(theOptimizer);
155 case(nlopt::LN_NELDERMEAD):{
156 nlopt::opt theOptimizer(nlopt::LN_NELDERMEAD,npar);
157 return(theOptimizer);
160 case(nlopt::LN_SBPLX):{
161 nlopt::opt theOptimizer(nlopt::LN_SBPLX,npar);
162 return(theOptimizer);
165 case(nlopt::LN_AUGLAG):{
166 nlopt::opt theOptimizer(nlopt::LN_AUGLAG,npar);
167 return(theOptimizer);
170 case(nlopt::LN_AUGLAG_EQ):{
171 nlopt::opt theOptimizer(nlopt::LN_AUGLAG_EQ,npar);
172 return(theOptimizer);
175 case(nlopt::LN_BOBYQA):{
176 nlopt::opt theOptimizer(nlopt::LN_BOBYQA,npar);
177 return(theOptimizer);
180 case(nlopt::GN_ISRES):{
181 nlopt::opt theOptimizer(nlopt::GN_ISRES,npar);
182 return(theOptimizer);
185 case(nlopt::G_MLSL_LDS):
187 case(nlopt::AUGLAG_EQ):
189 case(nlopt::GD_MLSL):
190 case(nlopt::GD_MLSL_LDS):
191 case(nlopt::GD_STOGO):
192 case(nlopt::GD_STOGO_RAND):
193 case(nlopt::LD_LBFGS_NOCEDAL):
194 case(nlopt::LD_LBFGS):
195 case(nlopt::LD_VAR1):
196 case(nlopt::LD_VAR2):
197 case(nlopt::LD_TNEWTON):
198 case(nlopt::LD_TNEWTON_RESTART):
199 case(nlopt::LD_TNEWTON_PRECOND):
200 case(nlopt::LD_TNEWTON_PRECOND_RESTART):
202 case(nlopt::LD_AUGLAG):
203 case(nlopt::LD_AUGLAG_EQ):
204 case(nlopt::LD_SLSQP):
206 std::string errorString=
"Error: derivative optimization algorithm ";
207 errorString+= algorithmString;
208 errorString+=
" not supported, select derivative-free algorithm ([GL]N_*])";