-2

I want to use NLopt for my nonlinear optimization problem. I test the sample code in tutorial page enter link description here, C++ example. It works good. But the function I want to minimize should a return a vector. Which is, in the tutorial page it has

double minf;
nlopt::result result = opt.optimize(x, minf);
printf("found minimum at f(%g,%g) = %g ", x[0],x[1],minf);

I hope minf is a vector, so I change it to one dimension vector for just test.

std::vector<double> minf(1);
nlopt::result result = opt.optimize(x, minf);
printf("found minimum at f(%g,%g) = %g ", x[0],x[1],minf[0]);

Then it has errorsnltest2.cpp:44:44: error: no matching function for call to ‘nlopt::opt::optimize(std::vector<double>&, std::vector<double>&)’

Is there any way I can let it recturn an vector? What's more(if you cannot answer this that's OK.) I hope to use armadillo matrix library. The better if I could (I have included the h file needed)

mat minf(1,1);
nlopt::result result = opt.optimize(x, minf);
printf("found minimum at f(%g,%g) = %g ", x[0],x[1],minf(1,1));

This causes errors of course...

Thanks for your answer!!

1 Answers1

0

In fact if we want to put a vector to optimizae this becomes to an multi-objective optimization problem. I am not sure if NLopt can do that. One of the proper way you can do when you want to optimize a vector is that you change your vector into a scalar. for instance you want to optimize [x,y], you may can use z= x+y and optimize z. This may look like wrong but sometimes it works. Or use more advanced way called "Pareto Front". See the following slide change a vector to a scalar