EvaluatorExample.py 501 B

123456789101112131415161718192021222324
  1. """Python evaluator function example
  2. """
  3. import random
  4. elements_score = [random.randint(1, 20) for _ in range(30)]
  5. # evaluator example
  6. def evaluatorExample(_solution):
  7. """
  8. Evaluator's example of solution to compute fitness
  9. Args:
  10. _solution: {Solution} -- solution to evaluate
  11. Returns:
  12. {float} -- fitness score of solution
  13. """
  14. fitness = 0
  15. for index, elem in enumerate(_solution.data):
  16. fitness += elements_score[index] * elem
  17. return fitness