Improving the results with enhanced exploration and elitism

If we try to increase the number of generations in the previous program, we will realize that the solution does not improve—it is stuck in the (somewhat) suboptimal solution that was reached sometime before generation 200, as shown in the next plot, displaying 500 generations:

Stats of the first program, running for 500 generations

From that point on, the similarity between the average value and the best value indicates that this solution took over the population and therefore we will not see any improvement unless a lucky mutation turns up. In genetic algorithm terms, this means ...

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.