base.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. """Apply the computation of fitness from solution
  12. Fitness is a float value for mono-objective or set of float values if multi-objective evaluation
  13. Args:
  14. solution: {Solution} -- Solution instance
  15. Return:
  16. {float} -- computed solution score (float or set of float if multi-objective evaluation)
  17. """
  18. self._data = data
  19. @abstractmethod
  20. def compute(self, solution):
  21. """Apply the computation of fitness from solution
  22. Fitness is a float value for mono-objective or set of float values if multi-objective evaluation
  23. Args:
  24. solution: {Solution} -- Solution instance
  25. Return:
  26. {float} -- computed solution score (float or set of float if multi-objective evaluation)
  27. """
  28. pass
  29. def setAlgo(self, algo):
  30. """Keep into evaluator reference of the whole algorithm
  31. The reason is to better manage evaluator instance if necessary
  32. Args:
  33. algo: {Algorithm} -- the algorithm reference runned
  34. """
  35. self._algo = algo