nlopt
nlopt copied to clipboard
Parameterized optimization problem
I am new to the excellent library. I go through the manual and wonder what is the best practice for parameterized optimization problems?
As the example in tutorial. Different choice of the parameters a,b will result in difficult optimum. I need to implement a method whose input is the set of parameters and output is the optimum corresponding to those parameters.
The first idea that comes to my mind is instantiating nlopt.opt repeatedly. However, it seems very expensive. Is there a possibility that I create an instance of nlopt.opt once and get different optimums by call solver with different probelm parameters.
I thought what you need is the extra parameter void * data such as
double myfunc(unsigned n, const double *x, double *grad, void *my_func_data)
The my_func_data is used to pass extra data. Then you can just loop over your parameter sets. You can use a fixed pointer. But each time you reset the address which the pointer stores. And rerun the solver to get results.