RandomPolicy.py 646 B

123456789101112131415161718192021222324
  1. """Policy class implementation which is used for select operator randomly
  2. """
  3. # main imports
  4. import random
  5. # module imports
  6. from .Policy import Policy
  7. class RandomPolicy(Policy):
  8. """Policy class implementation which is used for select operator randomly
  9. Attributes:
  10. operators: {[Operator]} -- list of selected operators for the algorithm
  11. """
  12. def select(self):
  13. """Select randomly the next operator to use
  14. Returns:
  15. {Operator}: the selected operator
  16. """
  17. # choose operator randomly
  18. index = random.randint(0, len(self.operators) - 1)
  19. return self.operators[index]