33 case nlopt::FAILURE:
return false;
34 case nlopt::INVALID_ARGS:
return false;
35 case nlopt::OUT_OF_MEMORY:
return false;
36 case nlopt::ROUNDOFF_LIMITED:
return false;
37 case nlopt::FORCED_STOP:
return false;
39 case nlopt::STOPVAL_REACHED:
return true;
40 case nlopt::FTOL_REACHED:
return true;
41 case nlopt::XTOL_REACHED:
return true;
42 case nlopt::MAXEVAL_REACHED:
return true;
43 case nlopt::MAXTIME_REACHED:
return true;
52 , lower_bounds(
Eigen::VectorXd::Zero(n))
53 , upper_bounds(
Eigen::VectorXd::Zero(n))
74 if (i < 0 || i >=
n_dims) {
76 "array index out of bounds");
84 throw Setup_error(
"NLopt_optimizer::set_lower_bounds: " 85 "size of bounds vectors must match");
97 if (i < 0 || i >=
n_dims) {
99 "array index out of bounds");
107 throw Setup_error(
"NLopt_optimizer::set_upper_bounds: " 108 "size of bounds vectors must match");
115 throw Setup_error(
"NLopt_optimizer::set_max_time: " 116 "maximum allowed time must be non-negative");
124 if (guess.size() !=
n_dims) {
126 "initial guess size must match number of variables");
131 void* parameters = &
function;
140 optimizer.set_lower_bounds(lb);
141 optimizer.set_upper_bounds(ub);
148 optimizer.set_maxtime(
maxtime);
151 std::vector<double> x(guess.data(), guess.data() +
n_dims);
152 const nlopt::result status = optimizer.optimize(x,
extremum_value);
155 if(status == nlopt::MAXTIME_REACHED) {
157 "Timed out before locating extremum");
166 std::vector<double>& ,
170 const Eigen::VectorXd coords(Eigen::VectorXd::Map(x.data(), x.size()));
171 return (*func)(coords);
Eigen::VectorXd::Index Index
Exception indicating that the optimizer failed to converge.
nlopt::result optimize(const Eigen::VectorXd &guess)
void set_max_time(double maxtime)
Eigen::VectorXd upper_bounds
bool optimization_succeeded(nlopt::result)
void set_upper_bounds(double ub)
Eigen::VectorXd lower_bounds
Exception indicating out of bounds access error.
void set_lower_bounds(double lb)
std::function< double(const Eigen::VectorXd &)> Function
Exception indicating general setup error.
void set_ftol_rel(double ftol_rel_)
static double nlopt_function(const std::vector< double > &, std::vector< double > &, void *)
nlopt::algorithm algorithm
void set_xtol_rel(double xtol_rel_)
Extremum_type extremum_type