base.py 1.2 KB

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