125 {
129
130 opt_ = nlopt::opt(
alg_,
sizeof...(Args) );
131
132
133
135
138
139 nlopt::opt localopt;
140 switch(
opt_.get_algorithm()) {
141 case nlopt::GN_MLSL:
142 case nlopt::GN_MLSL_LDS:
144 sizeof...(Args));
147 opt_.set_local_optimizer(localopt);
148 default: ;
149 }
150
154 if(!std::isnan(abs_diff))
opt_.set_ftol_abs(abs_diff);
155 if(!std::isnan(rel_diff))
opt_.set_ftol_rel(rel_diff);
156 if(!std::isnan(stopval))
opt_.set_stopval(stopval);
157
160
161
163
165 std::make_pair(&func, this);
166
168 case OptDir::MIN:
169 opt_.set_min_objective(optfunc<Func, Args...>, &data);
break;
170 case OptDir::MAX:
171 opt_.set_max_objective(optfunc<Func, Args...>, &data);
break;
172 }
173
174 Result<Args...> result;
175 nlopt::result rescode;
176
177 try {
179 result.resultcode =
static_cast<ResultCodes>(rescode);
180 } catch( nlopt::forced_stop& ) {
182 }
183
185
186 return result;
187 }
std::vector< double > upper_bounds_
Definition nlopt_boilerplate.hpp:41
std::vector< double > lower_bounds_
Definition nlopt_boilerplate.hpp:40
std::vector< double > initvals_
Definition nlopt_boilerplate.hpp:42
nlopt::opt opt_
Definition nlopt_boilerplate.hpp:39
StopCriteria stopcr_
Definition optimizer.hpp:129
ResultCodes
Info about result of an optimization. These codes are exactly the same as the nlopt codes for convini...
Definition optimizer.hpp:72
@ FORCED_STOP
Definition optimizer.hpp:77
double absolute_score_difference
If the absolute value difference between two scores.
Definition optimizer.hpp:102
unsigned max_iterations
The max allowed number of iterations.
Definition optimizer.hpp:115
double relative_score_difference
If the relative value difference between two scores.
Definition optimizer.hpp:105
double stop_score
Stop if this value or better is found.
Definition optimizer.hpp:108
nlopt::algorithm method2nloptAlg(Method m)
Definition nlopt_boilerplate.hpp:22