Hello,
I'm using the Levenberg Marquardt algorithm to optimize a simulation based problem. Algo works fine but I have some issues with the termination. I'm tracking the different iterations and the final solution is not the best that have been tested for my problem. I tried to call "minlmrequesttermination(state);" in my call-back function to force termination at the right moment, but i'm not sure how to do it. If you have any suggestions on why the final result of optimisation isn't the best one and/or can I code "minlmrequesttermination(state) properly, I'll be glad.
Thanks in advance !
Here is my call back function :
void functionRT_fvec(const real_1d_array &x, real_1d_array &fi, void *ptr) { InputDataRT temp = *((InputDataRT *)ptr); int size = temp.vec.size(); std::ofstream indices("./data/indices/TEMP-Optimisation.dat"); for (size_t j = 0; j<size-2; ++j) { indices << temp.vec[j] << " ";
} indices << x[0] << " " << x[1]; indices.close();
double freq, R,Tr, rad,E;
system("MCRT.exe");
std::string path = "./temp/OutForOpti_1_RTERad.dat"; std::ifstream RTERad(path.c_str()); std::string line;
if (RTERad.good()) { while(std::getline(RTERad,line)) { char firstChar = line[0];
if (firstChar != '#') { RTERad >> freq; RTERad >> R; RTERad >> Tr; RTERad >> rad; RTERad >> E; } } } else {std::cout << "Can't open MCRT output file !" << std::endl;}
//std::cout << "indexes are : " << x[0] << " " << x[1] << std::endl;
fi[0] = temp.data_R-R; fi[1] = temp.data_T-Tr; if(abs(fi[0]) <= 1e-2 && abs(fi[1]) <= 1e-2) { minlmstate state; /* redefining state is certainly not the right way */ std::cout << "STOP REQUIRED" << std::endl; minlmrequesttermination(state); }
};
|