Projet du cours MPRI 2.24.2 "Résolution de problèmes d'optimisation avec heuristiques de recherche" : https://wikimpri.dptinfo.ens-cachan.fr/doku.php?id=cours:c-2-24-2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scripts.h 1.2KB

  1. #ifndef SCRIPTS_H_INCLUDED
  2. #define SCRIPTS_H_INCLUDED
  3. #include <vector>
  4. #include "analysis.h"
  5. using namespace std;
  6. void optimal_proba(int n_initial, int n_final, std::default_random_engine& randomizer, double p_init=0.05, double p_final=0.5, double p_step=0.01) {
  7. for(int n=n_initial; n<n_final; n++) {
  8. vector<double> avg_list;
  9. vector<double> probas;
  10. auto start = start_chrono();
  11. for(double p=p_init; p<p_final; p+=p_step) {
  12. EA algo(p, 1, 1, randomizer);
  13. Statistic stat = avg_calls(algo, MasterMind(n, n, randomizer));
  14. double avg = stat.average;
  15. avg_list.push_back(avg);
  16. probas.push_back(p);
  17. }
  18. auto stop = stop_chrono();
  19. int elapsed_milliseconds = interval_chrono(start, stop);
  20. int min_ind = 0;
  21. for(int i=1; i<avg_list.size(); i++)
  22. if(avg_list[min_ind] > avg_list[i])
  23. min_ind = i;
  24. double p_best = probas[min_ind];
  25. cout << "n=" << n << ": " << p_best << " in " << elapsed_milliseconds/1000. << " seconds " << "(" << 100*floor((p_final-p_init)/p_step) << " problems)" << endl;
  26. }
  27. }
  28. #endif // SCRIPTS_H_INCLUDED