"You can use *ptr to pass pointer to some complex structure (declared by you), which stores Ai, mi, Sigma, filenames, etc. It is possible without modification of ALGLIB."
Hi there, I am relatively new to c++, so i have a basic question about the statement above: how do I do this? I would like to pass an object to the function to be optimized, but when i do it through the void *ptr, the object isn't recognized as such within the function. My code is below. Any suggestions would be greatly appreciated.
Thanks
void function1_fvec(const alglib::real_1d_array &x, alglib::real_1d_array &fi, void *my_obj) { // // this callback calculates // f0(x0,x1) = (a number)*100*(x0+3)^4, // f1(x0,x1) = (x1-3)^4 // fi[0] = my_obj->A[2]*10*pow(x[0]+3,2); fi[1] = pow(x[1]-3,2); }
int main(void) {
alglib::real_1d_array x = "[0,0,3,6,-4.368]"; double epsg = 0.0000000001; double epsf = 0; double epsx = 0; alglib::ae_int_t maxits = 0; alglib::minlmstate state; alglib::minlmreport rep;
my_type *my_obj = new my_type(.....);
minlmcreatev(3, x, 0.0001, state); minlmsetcond(state, epsg, epsf, epsx, maxits); minlmoptimize(state, function1_fvec,NULL, my_obj); minlmresults(state, x, rep);
printf("%d\n", int(rep.terminationtype)); // EXPECTED: 4 printf("%s\n", x.tostring(2).c_str()); // EXPECTED: [-3,+3] }
|