Evolving the solution

The genetic flow is implemented in the main() function, as described in the following steps:

  1. We start the flow by creating the initial population using the populationCreator operator we defined earlier, and the POPULATION_SIZE constant as the argument for this operator. The generationCounter variable, which will be used later on, is initialized here as well:
population = toolbox.populationCreator(n=POPULATION_SIZE)generationCounter = 0
  1. To calculate the fitness for each individual in the initial population, we use the Python map() function to apply the evaluate operator to each item in the population. As the evaluate operator is an alias for the oneMaxFitness() function, the resulting iterable consists of the calculated ...

Get Hands-On Genetic Algorithms with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.