minbleic In the previous version , I can get the objective function value and others. But in 3.8.0,I Don't know how to get the objective function value with minbleic ?
void function1_grad(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr) { // // this callback calculates f(x0,x1) = 100*(x0+3)^4 + (x1-3)^4 // and its derivatives df/d0 and df/dx1 // func = 100*pow(x[0]+3,4) + pow(x[1]-3,4); grad[0] = 400*pow(x[0]+3,3); grad[1] = 4*pow(x[1]-3,3); }
int main(int argc, char **argv) { // // This example demonstrates minimization of f(x,y) = 100*(x+3)^4+(y-3)^4 // subject to bound constraints -1<=x<=+1, -1<=y<=+1, using BLEIC optimizer. // real_1d_array x = "[0,0]"; real_1d_array bndl = "[-1,-1]"; real_1d_array bndu = "[+1,+1]"; minbleicstate state; minbleicreport rep;
// // These variables define stopping conditions for the optimizer. // // We use very simple condition - |g|<=epsg // double epsg = 0.000001; double epsf = 0; double epsx = 0; ae_int_t maxits = 0;
// // Now we are ready to actually optimize something: // * first we create optimizer // * we add boundary constraints // * we tune stopping conditions // * and, finally, optimize and obtain results... // minbleiccreate(x, state); minbleicsetbc(state, bndl, bndu); minbleicsetcond(state, epsg, epsf, epsx, maxits); alglib::minbleicoptimize(state, function1_grad); minbleicresults(state, x, rep);
// // ...and evaluate these results // printf("%d\n", int(rep.terminationtype)); // EXPECTED: 4 printf("%s\n", x.tostring(2).c_str()); // EXPECTED: [-1,1]
cout<<"rep.iterationscount= "<<rep.iterationscount<<endl; cout<<"rep.nfev= "<<rep.nfev<<endl; cout<<"rep.debugdx= "<<rep.debugdx<<endl; cout<<"rep.debugff= "<<rep.debugff<<endl; cout<<"rep.debugfs= "<<rep.debugfs<<endl;
// rep.iterationscount= 3 // rep.nfev= 5 // rep.debugdx= nan // rep.debugff= nan // rep.debugfs= nan return 0; }
|