12 #include<TRInterface.h> 25 for (
int i=0;i<(length-1);i++) {
26 result+=
pow(1-xx[i],2)+100*
pow(xx[i+1]-
pow(xx[i],2),2);
36 for (
int i=0;i<length;i++) {
37 result+=xx[i]*xx[i]-10*
cos(6.2831853*xx[i]);
42 void GlobalMinimization()
45 ROOT::R::TRInterface &
r=ROOT::R::TRInterface::Instance();
47 Bool_t installed=r.Eval(
"is.element('DEoptim', installed.packages()[,1])");
49 std::cout<<
"Package DEoptim no installed in R"<<std::endl;
50 std::cout<<
"Run install.packages('DEoptim') in R's environment"<<std::endl;
55 r<<
"suppressMessages(library(DEoptim, quietly = TRUE))";
58 r[
"GenRosenBrock"]<<ROOT::R::TRFunctionExport(GenRosenBrock);
70 bench.
Start(
"GlobalMinimizationRosenBrock");
72 r<<
"result1<-DEoptim(fn=GenRosenBrock,lower=ll,upper=ul,control=list(NP=10*n,itermax=MaxIter,trace=FALSE))";
73 std::cout<<
"-----------------------------------------"<<std::endl;
74 std::cout<<
"RosenBrock's minimum in: "<<std::endl;
75 r<<
"print(result1$optim$bestmem)";
76 std::cout<<
"Bechmark Times"<<std::endl;
78 bench.
Show(
"GlobalMinimizationRosenBrock");
81 r[
"Rastrigin"]<<ROOT::R::TRFunctionExport(Rastrigin);
91 bench.
Start(
"GlobalMinimizationRastrigin");
93 r<<
"result2<-DEoptim(fn=Rastrigin,lower=ll,upper=ul,control=list(NP=10*n,itermax=MaxIter,trace=FALSE))";
94 std::cout<<
"-----------------------------------------"<<std::endl;
95 std::cout<<
"Rastrigin's minimum in: "<<std::endl;
96 r<<
"print(result2$optim$bestmem)";
97 std::cout<<
"Bechmark Times"<<std::endl;
99 bench.
Show(
"GlobalMinimizationRastrigin");
101 if (!
gROOT->IsBatch()) {
102 r<<
"dev.new(title='RosenBrock Convergence')";
103 r<<
"plot(result1,type='o',pch='.')";
105 r<<
"dev.new(title='Rastrigin Convergence')";
106 r<<
"plot(result2,type='o',pch='.')";
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
virtual void Start(const char *name)
Starts Benchmark with the specified name.
double pow(double, double)
Int_t GetNoElements() const
This class is a ROOT utility to help benchmarking applications.