code: def main():
      random.seed(64)
  
      # create an initial population of 300 individuals (where
      # each individual is a list of integers)
      pop = toolbox.population(n=300)
  
      # CXPB  is the probability with which two individuals
      #       are crossed
      #
      # MUTPB is the probability for mutating an individual
      CXPB, MUTPB = 0.5, 0.2
  
      print("Start of evolution")
  
      # Evaluate the entire population
      fitnesses = list(map(toolbox.evaluate, pop))
      for ind, fit in zip(pop, fitnesses):
          ind.fitness.values = fit
  
      print("  Evaluated %i individuals" % len(pop))
  
      # Extracting all the fitnesses of
      fits = [ind.fitness.values[0] for ind in pop]
  
      # Variable keeping track of the number of generations
      g = 0
  
      # Begin the evolution
      while max(fits) < 100 and g < 1000:
          # A new generation
          g = g + 1
          print("-- Generation %i --" % g)
  
          # Select the next generation individuals
          offspring = toolbox.select(pop, len(pop))
          # Clone the selected individuals
          offspring = list(map(toolbox.clone, offspring))
  
          # Apply crossover and mutation on the offspring
          for child1, child2 in zip(offspring[::2], offspring[1::2]):
              # cross two individuals with probability CXPB
              if random.random() < CXPB:
                  toolbox.mate(child1, child2)
  
                  # fitness values of the children
                  # must be recalculated later
                  del child1.fitness.values
                  del child2.fitness.values
  
          for mutant in offspring:
              # mutate an individual with probability MUTPB
              if random.random() < MUTPB:
                  toolbox.mutate(mutant)
                  del mutant.fitness.values
  
          # Evaluate the individuals with an invalid fitness
          invalid_ind = [
              ind for ind in offspring if not ind.fitness.valid
          ]
          fitnesses = map(toolbox.evaluate, invalid_ind)
          for ind, fit in zip(invalid_ind, fitnesses):
              ind.fitness.values = fit
  
          print("  Evaluated %i individuals" % len(invalid_ind))
  
          # The population is entirely replaced by the offspring
          pop[:] = offspring
  
          # Gather all the fitnesses in one list and print the stats
          fits = [ind.fitness.values[0] for ind in pop]
  
          length = len(pop)
          mean = sum(fits) / length
          sum2 = sum(x * x for x in fits)
          std = abs(sum2 / length - mean**2) ** 0.5
  
          print("  Min %s" % min(fits))
          print("  Max %s" % max(fits))
          print("  Avg %s" % mean)
          print("  Std %s" % std)
  
      print("-- End of (successful) evolution --")
  
      best_ind = tools.selBest(pop, 1)[0]
      print(
          "Best individual is %s, %s"
          % (best_ind, best_ind.fitness.values)
      )
  
imports: import random
  from deap import base
  from deap import creator
  from deap import tools
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types