stevengj / nlopt

library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization
Other
1.88k stars 584 forks source link

Parameterized optimization problem #386

Open qsh-zh opened 3 years ago

qsh-zh commented 3 years ago

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.

kilasuelika commented 3 years ago

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.