A generation is one complete iteration of population variation, evaluation, and selection in an evolutionary algorithm. It begins with a population, evaluates fitness, selects parents, applies crossover and mutation, and produces a new population of children. The new generation is then evaluated and passed through the process again. section 2.5.8 section 2.4.1
A practical generation loop typically performs these steps:
- Evaluate every individual’s fitness. section 2.5.8
- Select individuals to reproduce according to fitness. section 2.5.8 section 2.4.1
- Create offspring through crossover, then introduce variation through mutation. section 2.5.8 section 2.5.9
- Replace or advance the population, reevaluate fitness, and check stopping criteria. section 2.5.8 section 2.4.1
One-max simulation
A simple Python simulation initializes a binary population, runs simple_GA for each generation, recalculates the sum of each individual’s genes, and reports maximum, minimum, mean, and standard-deviation fitness. Tracking the whole population reveals progress beyond the best individual; after 100 generations, the displayed run reaches a maximum fitness of 98. section 2.5.8
Listing 2.19 EDL_2_5_Genetic_Algorithms.ipynb: The full GA process
def simple_GA(pop, crossover_rate=.5, mutation_rate=.05):
fitness = np.sum(pop,axis=1) #1
parents = elite_selection(fitness) #2
children = np.zeros((population,genes)) #3
for i in range(population): #4
offspring = crossover(pop[parents[0]],
pop[parents[1]], crossover_rate) #5
children[i] = mutation(offspring[0],mutation_rate) #6
return children
simple_GA(pop) #7
Use the complete GA implementation to inspect how fitness evaluation, elite selection, crossover, mutation, and child return form one generation. section 2.5.8


