Operator.py 915 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Abstract Operator class
  2. """
  3. # main imports
  4. from enum import Enum
  5. from abc import abstractmethod
  6. # enumeration which stores kind of operator
  7. class KindOperator(Enum):
  8. """Enum in order to recognize kind of operators
  9. """
  10. MUTATOR = 1
  11. CROSSOVER = 2
  12. class Operator():
  13. """Abstract Operator class which enables to update solution applying operator (computation)
  14. """
  15. @abstractmethod
  16. def __init__(self):
  17. pass
  18. @abstractmethod
  19. def apply(self, solution):
  20. """Apply the current operator transformation
  21. Args:
  22. solution: {Solution} -- Solution instance
  23. """
  24. pass
  25. def setAlgo(self, algo):
  26. """Keep into operator reference of the whole algorithm
  27. The reason is to better manage operator instance
  28. Args:
  29. algo: {Algorithm} -- the algorithm reference runned
  30. """
  31. self._algo = algo