Policy.py 858 B

123456789101112131415161718192021222324252627282930313233
  1. # main imports
  2. import logging
  3. # define policy to choose `operator` function at current iteration
  4. class Policy():
  5. # here you can define your statistical variables for choosing next operator to apply
  6. def __init__(self, _operators):
  7. self.operators = _operators
  8. def select(self):
  9. """
  10. Select specific operator to solution and returns solution
  11. """
  12. raise NotImplementedError
  13. def apply(self, solution):
  14. """
  15. Apply specific operator chosen to solution and returns solution
  16. """
  17. operator = self.select()
  18. logging.info("---- Applying %s on %s" %
  19. (type(operator).__name__, solution))
  20. # check kind of operator
  21. newSolution = operator.apply(solution)
  22. logging.info("---- Obtaining %s" % (solution))
  23. return newSolution