ControlBandit.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #define EPSILON_DEFAULT 10
  13. /* --- Structure --- */
  14. typedef struct {
  15. int fill;
  16. int heuristic;
  17. }fillAndHeuristic;
  18. class ControlBandit {
  19. public:
  20. ControlBandit();
  21. ~ControlBandit();
  22. void setMethod(int);
  23. void setEpsilon(double);
  24. bool queueIsEmpty();
  25. fillAndHeuristic next();
  26. void addFill(int, int);
  27. void addHeuristic(int, int);
  28. private:
  29. int method;
  30. int epsilon;
  31. std::mutex mutex;
  32. std::mutex mutexFill;
  33. std::mutex mutexHeuristic;
  34. std::vector<fillAndHeuristic> queue;
  35. double favg[NB_FILL];
  36. unsigned int fnb[NB_FILL];
  37. double havg[NB_HEURISTIC];
  38. unsigned int hnb[NB_HEURISTIC];
  39. fillAndHeuristic methodAvg();
  40. fillAndHeuristic methodEps();
  41. int getBestFill();
  42. int getBestHeuristic();
  43. inline int getRandomFill() {return rand() % 4 + 2;}
  44. inline int getRandomHeuristic() {return rand() % 7;}
  45. };
  46. #endif