I did some debugging and was able to track the error down, at least a bit.
I attached a small example demonstrating the problem. The code exits with
"nlopt invalid argument" if lower and upper bound are not set, otherwise
everything works.
2013/4/13 [email protected] <[email protected]>
> Dear Steven,
>
> that was also my first thought, but I removed all constraints and the
> error still occurs. I tested the following Code:
>
> -------------------------------
> double minf;
> nlopt::result result;
>
> nlopt::opt opt_first(nlopt::LN_BOBYQA, N);
> opt_first.set_min_objective(opt_func, reinterpret_cast<void*>(¶meter));
> opt_first.set_xtol_rel(1e-4);
> result = opt_first.optimize(Xmin, minf);
>
> nlopt::opt opt_second(nlopt::LN_BOBYQA, N);
> opt_second.set_min_objective(opt_func,
> reinterpret_cast<void*>(¶meter));
> opt_second.set_xtol_rel(1e-4);
> result = opt_second.optimize(Xmin, minf);
> -------------------------------
>
> The first run works as expected, the second one fails without even
> calling opt_func once. If I reset Xmin in between the two runs, the second
> run works as expected. The code works for example with NEWUOA. I also tried
> to reproduce the error with the Rosenbrock function as opt_func, but
> everything works fine there.
>
> Thanks,
> Klaus
>
> 2013/4/12 Steven G. Johnson <[email protected]>
>
>
>> On Apr 12, 2013, at 7:54 AM, "[email protected]" <
>> [email protected]> wrote:
>>
>> > Dear all,
>> >
>> > I'm using NLopt to solve a non-linear optimization problem without
>> constraints. I was testing the algorithm BOBYQA, which is causing some
>> trouble. Depending on the initial guess, I get an the following error:
>> >
>> > terminate called after throwing an instance of 'std::invalid_argument'
>> > what(): nlopt invalid argument
>>
>> The initial guess must satisfy your bound constraints. Are you violating
>> those?
>>
>>
>> _______________________________________________
>> NLopt-discuss mailing list
>> [email protected]
>> http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss
>>
>
>
#include <iostream>
#include <vector>
#include <assert.h>
#include <nlopt.hpp>
using namespace std;
double myvfunc(const std::vector<double> &x, std::vector<double> &grad, void *my_func_data)
{
assert ( grad.empty() );
double f = 0;
for (unsigned int i=0; i<x.size(); ++i) {
f += x.at(i)*x.at(i);
}
return f;
}
int main()
{
int N = 3;
std::vector<double> x(N);
double minf;
x.at(0) = 0.5;
x.at(1) = -0.5;
x.at(2) = 0.5;
nlopt::opt opt(nlopt::LN_BOBYQA, N);
//opt.set_lower_bounds(-1);
//opt.set_upper_bounds(1);
opt.set_min_objective(myvfunc, NULL);
opt.set_xtol_rel(1e-4);
nlopt::result result = opt.optimize(x, minf);
for (int i=0; i<N; ++i) {
cout << x.at(i) << " ";
}
cout << endl;
}
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss