1 // A C-callable front-end to the StoGO global-optimization library.
2 // -- Steven G. Johnson
7 class MyGlobal : public Global {
9 objective_func my_func;
14 MyGlobal(RTBox D, GlobalParams P, objective_func func, void *data) : Global(D, 0, 0, P), my_func(func), my_data(data) {}
16 virtual double ObjectiveGradient(RCRVector xy, RVector &grad, whichO which){
20 case OBJECTIVE_AND_GRADIENT:
21 return my_func(xy.GetLength(), xy.raw_data_const(), grad.raw_data(), my_data);
23 return my_func(xy.GetLength(), xy.raw_data_const(), NULL, my_data);
29 int stogo_minimize(int n,
30 objective_func fgrad, void *data,
31 double *x, double *fmin,
32 const double *l, const double *u,
33 long int maxeval, double maxtime,
38 // FIXME: WTF do these parameters mean?
39 params.rnd_pnts=nrandom;
40 params.det_pnts=2*n+1 - nrandom;
41 params.eps_cl=0.1; params.rshift=0.3;
44 params.maxtime = maxtime;
45 params.maxeval = maxeval;
48 for (int i = 0; i < n; ++i) {
53 MyGlobal Problem(D, params, fgrad, data);
55 Problem.Search(-1, dummyvec);
57 if (Problem.NoMinimizers())
60 *fmin = Problem.OneMinimizer(dummyvec);
61 for (int i = 0; i < n; ++i) x[i] = dummyvec(i);