nlopt
nlopt copied to clipboard
Vector-valued multi-constraints in c++
Hi,
i want to use a std::vector-based inequality-multi-constraint instead of the arrays. I have no problem doing this for the objective function, but it does not work for the constraint function. To demonstrate this i use the tutorial example from the webside (https://nlopt.readthedocs.io/en/latest/NLopt_Tutorial/#example-in-cc) and the version with multi-constraint provided in issue #168 .
The objective function from the tutorial:
double myfunc(unsigned n, const double *x, double *grad, void *my_func_data) { … }
can also be defined as:
double myfunc(const std::vector<double> &x, std::vector<double> &grad, void *my_func_data) { … }.
So i tried to write the multi-constraint function:
void multi_constraint(unsigned m, double *result, unsigned n, const double* x, double* grad, void* f_data) { … }
in this way:
void multi_constraint(unsigned m, std::vector<double> &result, unsigned n, const std::vector<double> &x, std::vector<double> &grad, void* f_data) { … }.
I can't find such an definition for the constraint function in the nlopt-header file. Does anyone know how to define it?
Thank you!