ControlBandit.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 MT_EMA 2
  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. fillAndHeuristic methodEma();
  42. int getBestFill();
  43. int getBestHeuristic();
  44. inline int getRandomFill() {return rand() % 4 + 2;}
  45. inline int getRandomHeuristic() {return rand() % 7;}
  46. };
  47. #endif