EvaluatorExample.py 498 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