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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.