//Example based in //http://cran.r-project.org/web/packages/DEoptim/DEoptim.pdf //Please install the R package DEoptim before run this example. //Author: Omar Zapata #include #include #include #include //In the next function the *double pointer should be changed by a TVectorD datatype, //because the pointer has no meaning in R's enviroment. //This is a generalization of the RosenBrock function, with the min xi=1 and i>0. Double_t GenRosenBrock(const TVectorD xx ) { int length=xx.GetNoElements(); Double_t result=0; for(int i=0;i<(length-1);i++) { result+=pow(1-xx[i],2)+100*pow(xx[i+1]-pow(xx[i],2),2); } return result; } //the min xi=0 i>0 Double_t Rastrigin(const TVectorD xx) { int length=xx.GetNoElements(); Double_t result=10*length; for(int i=0;iIsBatch()) { r<<"dev.new(title='RosenBrock Convergence')"; r<<"plot(result1,type='o',pch='.')"; r<<"dev.off()"; r<<"dev.new(title='Rastrigin Convergence')"; r<<"plot(result2,type='o',pch='.')"; r<<"dev.off()"; } }