#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "EA.h" #include "RLS.h" #include "analysis.h" #include "PEA.h" #include "ea-complexity.h" #include "crossover-rate.h" #include "scripts.h" #include "scripts2.h" #include "bestPGA.h" #include "bestPGA.h" #include "bestPEA.h" #include "algo-complexity.h" using namespace std; struct Data { Data() : nb_goods{0} {}; double r; double s; double t; double u; double a; double b; double c; double d; double alpha; double beta; double gamma; double lambda; int nb_goods; }; int main(int argc, char** argv) { srand(time(NULL)); std::default_random_engine randomizer{static_cast(time(0))}; if(argc >= 2) { int num_experiment = atoi(argv[1]); switch(num_experiment) { case 1: cout << "Experiment: Optimal Crossover probability" << endl; switch(atoi(argv[2])) { case 0: // Start from beginning script_crossover_proba_global_optim(randomizer, "global-crossover-proba.csv", false, 5, 5); break; case 1: // Restart from a specific point { stringstream ss; ss << "global-crossover-proba-" << atoi(argv[3]) << "-" << atoi(argv[4]) << ".csv"; script_crossover_proba_global_optim(randomizer, ss.str(), true, atoi(argv[3]), atoi(argv[4])); }break; case 2: // Filtering crossover_model_filtering(argv[3], argv[4], argv[5], atoi(argv[6]), atoi(argv[7])); break; case 3: // Local optimization of model crossover_model_optimization(argv[3]); break; case 4: // Validation of model crossover_model_validation(argv[3], atof(argv[4]), atof(argv[5]), atof(argv[6]), atof(argv[7])); break; } return 0; case 2: cout << "Experiment: EA Complexity" << endl; switch(atoi(argv[2])) { case 1: { int n_initial = (argc>=4) ? atoi(argv[3]) : 3; stringstream ss; ss << "complexity-ea-n-" << n_initial << ".csv"; ofstream outfile(ss.str()); for(int n=n_initial; n<30; n++) { MasterMind mm(n, n, randomizer); for(int mu=1; mu<50; mu+=2) { cout << " n=" << n << ": mu=" << mu << endl; for(int lambda=1; lambda<50; lambda+=2) { EA algo(mu, lambda, PLUS, 1./n, randomizer); algo.set_problem(&mm); Statistic stat = avg_calls(&algo, 1000, -1, 1.9623414611); outfile << n << ";" << mu << ";" << lambda << ";" << stat.average << ";" << stat.alea << endl; } } } } break; case 2: // Filtering ea_complexity_filtering(argv[3], argv[4], atoi(argv[5]), atoi(argv[6]), atoi(argv[7])); break; } return 0; } } //////////////////////////////////////////////////// Data datas[30]; std::ifstream infile("complexity-ea.csv"); std::string line; while(getline(infile, line)) { int n, mu, lda; double avg, alea; sscanf(line.c_str(), "%d;%d;%d;%lf;%lf", &n, &mu, &lda, &avg, &alea); if((mu==5 || mu==45) && (lda==5 || lda==45)) { if(mu==5) { if(lda==5) datas[n].r = avg; else datas[n].s = avg; } else { if(lda==5) datas[n].t = avg; else datas[n].u = avg; } } } for(int n=5; n<30; n++) { Data dat = datas[n]; datas[n].a = (dat.s - dat.r) / (45. - 5.); datas[n].b = dat.s - 45.*datas[n].a; datas[n].c = (dat.u - dat.t) / (45. - 5.); datas[n].b = dat.u - 45.*datas[n].c; } for(int n=5; n<30; n++) { Data dat = datas[n]; datas[n].alpha = (dat.c - dat.a) / (45. - 5.); datas[n].gamma = dat.a - 5*datas[n].alpha; datas[n].beta = (dat.d - dat.b) / (45. - 5.); datas[n].lambda = dat.b - 5*datas[n].beta; } std::ifstream in2file("complexity-ea.csv"); while(getline(in2file, line)) { int n, mu, lda; double avg, alea; sscanf(line.c_str(), "%d;%d;%d;%lf;%lf", &n, &mu, &lda, &avg, &alea); Data d = datas[n]; double prev = d.alpha*mu*lda + d.beta*mu + d.gamma*lda + d.lambda; if(abs(avg-prev) <= alea) datas[n].nb_goods++; } for(int n=5; n<30; n++) { Data d = datas[n]; cout << n << ": " << d.alpha << "*mu*lda + " << d.beta << "*mu + " << d.gamma << "*lda + " << d.lambda << " => " << 100*d.nb_goods/625. << "%" << endl; } return 0; /* RLS algo; vector stats = compute_complexity(randomizer, &algo, 10, 1000, 10, 100, 1.9842169516, true); save_in_file("RLS-complexity", stats); return 0; */ //script_optimal_proba(randomizer); /* pea_optimisation(10, 20, randomizer); return 0; */ int nb_colors = 20; int nb_cases = 20; int n=20; /* MasterMind mm(nb_colors, nb_cases, randomizer); RLS algo1; EA algo2(1, 1, PLUS, 1./n, randomizer); EA algo3(2, 1, PLUS, 1./n, randomizer); EA algo4(4, 1, PLUS, 1./n, randomizer); EA algo5(8, 1, PLUS, 1./n, randomizer); EA algo6(16, 1, PLUS, 1./n, randomizer); algo1.set_problem(&mm); algo2.set_problem(&mm); algo3.set_problem(&mm); algo4.set_problem(&mm); algo5.set_problem(&mm); algo6.set_problem(&mm); vector algos = {&algo1, &algo2, &algo3, &algo4, &algo5, &algo6}; */ MasterMind mm(nb_colors, nb_cases, randomizer); RLS algo1; EA algo2(1, 1, PLUS, 1./n, randomizer); PEA algo3(1, 1, PLUS, {}, randomizer); algo1.set_problem(&mm); algo2.set_problem(&mm); algo3.set_problem(&mm); vector algos = {&algo1, &algo2, &algo3}; Statistic stat = avg_calls(&algo1, 20, -1, 3.883); int max_nb_calls = ceil(stat.average+stat.alea)*2; cmp_evolution(algos, mm, max_nb_calls, 100); return 0; /* Statistic* curves[6]; Statistic* dcurves[6]; int length = 0; for(int i=0; i::max(), '\n'); std::cin.get(); return 0; cout << "=========================" << endl; for(int n=5; n<6; n++) { vector avg_list; vector lambdas; int lambda_init = 1; int lambda_final = 20; int nb_tests = 10000; auto start = start_chrono(); for(int lambda=lambda_init; lambda lambda=" << lambda << ", nbcalls=" << avg << endl; } auto stop = stop_chrono(); int elapsed_milliseconds = interval_chrono(start, stop); int min_ind = 0; for(unsigned int i=1; i avg_list[i]) min_ind = i; double lambda_best = lambdas[min_ind]; cout << "n=" << n << ": " << lambda_best << " in " << elapsed_milliseconds/1000. << " seconds " << "(" << nb_tests*(lambda_final-lambda_init) << " problems)" << endl; } return 0; }