selecting the next generation individualsoffspring toolbox select(populationlen(population)nowclone the selected individualsoffspring list(map(toolbox cloneoffspring)apply crossover and mutation on the offspringfor child child in zip(offspring[:: ]offspring[ :: ])if random random(probab_crossingtoolbox mate(child child delete the fitness value of childdel child fitness values del child fitness values nowapply mutationfor mutant in offspringif random random(probab_mutatingtoolbox mutate(mutantdel mutant fitness values evaluate the individuals with an invalid fitnessinvalid_ind [ind for ind in offspring if not ind fitness validfitnesses map(toolbox evaluateinvalid_indfor indfit in zip(invalid_indfitnesses)ind fitness values fit print('evaluated'len(invalid_ind)'individuals'nowreplace population with next generation individualpopulation[:offspring print the statistics for the current generationsfits [ind fitness values[ for ind in populationlength len(populationmean sum(fitslength