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
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

SearchHeuristic.h 1.6KB

  1. #ifndef SEARCHHEURISTIC_H
  2. #define SEARCHHEURISTIC_H
  3. #include <vector>
  4. #include "MasterMind.h"
  5. struct Point {
  6. Point() : Point(0,0) {};
  7. Point(int c, double v) : nb_calls{c}, value{v} {};
  8. int nb_calls;
  9. double value;
  10. };
  11. struct Candidate {
  12. Candidate(int* s, int v) {
  13. sol = s;
  14. value = v;
  15. }
  16. int* sol;
  17. int value;
  18. };
  19. void swap_candidates(Candidate** tab, unsigned int i, unsigned int j);
  20. struct {
  21. bool operator()(Candidate* a, Candidate* b) const {
  22. return a->value > b->value;
  23. }
  24. } cmp_candidates;
  25. struct Result {
  26. Result(int* s, int v, int c, bool a=false) {
  27. solution = s;
  28. v_solution = v;
  29. nb_calls = c;
  30. has_been_aborted = a;
  31. }
  32. int* solution;
  33. int v_solution;
  34. int nb_calls;
  35. bool has_been_aborted;
  36. };
  37. class SearchHeuristic
  38. {
  39. public:
  40. SearchHeuristic();
  41. virtual Result run() = 0;
  42. MasterMind* get_problem();
  43. void set_problem(MasterMind* problem);
  44. void set_abortion_limit(double l);
  45. void set_record(std::vector<Point>* m_record_tab);
  46. bool is_recording();
  47. void clear_record();
  48. void record(int nb_calls, double value);
  49. std::vector<Point>* get_record();
  50. void set_objective(double objective);
  51. virtual ~SearchHeuristic();
  52. protected:
  53. MasterMind* m_problem;
  54. double m_abortion_limit;
  55. std::vector<Point>* m_record;
  56. double m_objective; // 1=100% of the result
  57. private:
  58. };
  59. #endif // SEARCHHEURISTIC_H