ControlBandit.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef CONTROLBANDIT_HPP
  2. #define CONTROLBANDIT_HPP
  3. /* --- Include --- */
  4. #include <mutex>
  5. #include <vector>
  6. #include <stdlib.h>
  7. /* --- Define --- */
  8. #define NB_FILL 4
  9. #define NB_HEURISTIC 7
  10. #define MT_AVG 0
  11. #define MT_EPS 1
  12. /* --- Structure --- */
  13. typedef struct {
  14. int fill;
  15. int heuristic;
  16. }fillAndHeuristic;
  17. class ControlBandit {
  18. public:
  19. ControlBandit();
  20. ~ControlBandit();
  21. void setMethod(int);
  22. void setEpsilon(double);
  23. bool queueIsEmpty();
  24. fillAndHeuristic next();
  25. void addFill(int, int);
  26. void addHeuristic(int, int);
  27. private:
  28. int method;
  29. int epsilon;
  30. std::mutex mutex;
  31. std::mutex mutexFill;
  32. std::mutex mutexHeuristic;
  33. std::vector<fillAndHeuristic> queue;
  34. double favg[NB_FILL];
  35. unsigned int fnb[NB_FILL];
  36. double havg[NB_HEURISTIC];
  37. unsigned int hnb[NB_HEURISTIC];
  38. fillAndHeuristic methodAvg();
  39. fillAndHeuristic methodEps();
  40. int getBestFill();
  41. int getBestHeuristic();
  42. inline int getRandomFill() {return rand() % 4 + 2;}
  43. inline int getRandomHeuristic() {return rand() % 7;}
  44. };
  45. #endif