multi.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. """Multi-objective evaluators classes
  2. """
  3. # main imports
  4. from .base import Evaluator
  5. class WeightedSum(Evaluator):
  6. """Weighted-sum sub-evaluator class which enables to compute solution using specific `_data`
  7. - stores into its `_data` dictionary attritute required measures when computing a solution
  8. - `_data['evaluators']` current evaluator to use
  9. - `_data['weights']` Associated weight to use
  10. - `compute` method enables to compute and associate a tuples of scores to a given solution
  11. """
  12. def compute(self, solution):
  13. """Apply the computation of fitness from solution
  14. - Associate tuple of fitness scores for each objective to the current solution
  15. - Compute weighted-sum for these objectives
  16. Args:
  17. solution: {Solution} -- Solution instance
  18. Returns:
  19. {float} -- weighted-sum of the fitness scores
  20. """
  21. scores = [evaluator.compute(solution) for evaluator in self._data['evaluators']]
  22. # associate objectives scores to solution
  23. solution._scores = scores
  24. return sum([scores[i] for i, w in enumerate(self._data['weights'])])