Operator.py 962 B

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