ControlBandit.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_EMA 0
  11. #define MT_EPS 1
  12. #define ALPHA_STEP 0.001
  13. #define ALPHA_MIN 0.4
  14. #define ALPHA_MAX 0.6
  15. #define ALPHA_STATIC 0.5
  16. /* --- Structure --- */
  17. typedef struct {
  18. int fill;
  19. int heuristic;
  20. }fillAndHeuristic;
  21. class ControlBandit {
  22. public:
  23. ControlBandit();
  24. ~ControlBandit();
  25. void setMethod(int, bool);
  26. void setEpsilon(double);
  27. bool queueIsEmpty();
  28. fillAndHeuristic next();
  29. void addFill(int, int);
  30. void addHeuristic(int, int);
  31. private:
  32. int method;
  33. int epsilon;
  34. std::mutex mutex;
  35. std::mutex mutexFill;
  36. std::mutex mutexHeuristic;
  37. std::vector<fillAndHeuristic> queue;
  38. bool alphaStatic;
  39. double alpha;
  40. double fema[NB_FILL];
  41. double hema[NB_HEURISTIC];
  42. fillAndHeuristic methodEma();
  43. fillAndHeuristic methodEps();
  44. int getBestFill();
  45. int getBestHeuristic();
  46. inline int getRandomFill() {return rand() % 4 + 2;}
  47. inline int getRandomHeuristic() {return rand() % 7;}
  48. };
  49. #endif