ControlBandit.hpp 1.1 KB

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