base.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Abstract Evaluator class for computing fitness score associated to a solution
  2. - stores into its `_data` dictionary attritute required measures when computing a solution
  3. - `compute` abstract method enable to compute and associate a score to a given solution
  4. """
  5. # main imports
  6. from abc import abstractmethod
  7. class Evaluator():
  8. """Abstract Evaluator class which enables to compute solution using specific `_data`
  9. """
  10. def __init__(self, data: dict):
  11. """Initialise Evaluator instance which stores into its `_data` dictionary attritute required measures when computing a solution
  12. Args:
  13. data: {dict} -- specific data dictionnary
  14. """
  15. self._data = data
  16. @abstractmethod
  17. def compute(self, solution):
  18. """Apply the computation of fitness from solution
  19. Fitness is a float value for mono-objective or set of float values if multi-objective evaluation
  20. Args:
  21. solution: {Solution} -- Solution instance
  22. Return:
  23. {float} -- computed solution score (float or set of float if multi-objective evaluation)
  24. """
  25. pass
  26. def setAlgo(self, algo):
  27. """Keep into evaluator reference of the whole algorithm
  28. The reason is to better manage evaluator instance if necessary
  29. Args:
  30. algo: {Algorithm} -- the algorithm reference runned
  31. """
  32. self._algo = algo