Skip to content

Commit

Permalink
Detect wrong algorithm string
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Jul 24, 2019
1 parent 945d055 commit 59d25ac
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/api/nlopt-in.hpp
Expand Up @@ -219,10 +219,13 @@ namespace nlopt {
nlopt_set_munge(o, free_myfunc_data, dup_myfunc_data);
}
opt(const char * algo_str, unsigned n) :
o(nlopt_create(nlopt_algorithm_from_string(algo_str), n)),
xtmp(0), gradtmp(0), gradtmp0(0),
o(NULL), xtmp(0), gradtmp(0), gradtmp0(0),
last_result(nlopt::FAILURE), last_optf(HUGE_VAL),
forced_stop_reason(NLOPT_FORCED_STOP) {
const nlopt_algorithm a = nlopt_algorithm_from_string(algo_str);
if (a < 0)
throw std::invalid_argument("wrong algorithm string");
o = nlopt_create(a, n);
if (!o) throw std::bad_alloc();
nlopt_set_munge(o, free_myfunc_data, dup_myfunc_data);
}
Expand Down

0 comments on commit 59d25ac

Please sign in to comment.