code: def main():
      random.seed(64)
  
      population = toolbox.population(n=300)
      hof = tools.ParetoFront()
  
      stats = tools.Statistics(lambda ind: ind.fitness.values)
      stats.register("Avg", tools.mean)
      stats.register("Std", tools.std)
      stats.register("Min", min)
      stats.register("Max", max)
  
      CXPB, MUTPB, ADDPB, DELPB, NGEN = 0.5, 0.2, 0.01, 0.01, 40
  
      # Evaluate every individuals
      fitnesses = toolbox.map(toolbox.evaluate, population)
      for ind, fit in zip(population, fitnesses):
          ind.fitness.values = fit
  
      hof.update(population)
      stats.update(population)
  
      # Begin the evolution
      for g in range(NGEN):
          print("-- Generation %i --" % g)
          offspring = [toolbox.clone(ind) for ind in population]
  
          # Apply crossover and mutation
          for ind1, ind2 in zip(offspring[::2], offspring[1::2]):
              if random.random() < CXPB:
                  toolbox.mate(ind1, ind2)
                  del ind1.fitness.values
                  del ind2.fitness.values
  
          # Note here that we have a different scheme of mutation than in the
          # original algorithm, we use 3 different mutations subsequently.
          for ind in offspring:
              if random.random() < MUTPB:
                  toolbox.mutate(ind)
                  del ind.fitness.values
              if random.random() < ADDPB:
                  toolbox.addwire(ind)
                  del ind.fitness.values
              if random.random() < DELPB:
                  toolbox.delwire(ind)
                  del ind.fitness.values
  
          # Evaluate the individuals with an invalid fitness
          invalid_ind = [
              ind for ind in offspring if not ind.fitness.valid
          ]
          fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)
          for ind, fit in zip(invalid_ind, fitnesses):
              ind.fitness.values = fit
  
          print("  Evaluated %i individuals" % len(invalid_ind))
  
          population = toolbox.select(
              population + offspring, len(offspring)
          )
          hof.update(population)
          stats.update(population)
  
          print("  Min %s" % stats.Min[0][-1][0])
          print("  Max %s" % stats.Max[0][-1][0])
          print("  Avg %s" % stats.Avg[0][-1][0])
          print("  Std %s" % stats.Std[0][-1][0])
  
      best_network = sn.SortingNetwork(INPUTS, hof[0])
      print(best_network)
      print(best_network.draw())
      print("%i errors, length %i, depth %i" % hof[0].fitness.values)
  
      return population, stats, hof
  
file_path: deap/doc/code/tutorials/part_4/4_4_Using_Cpp_NSGA.py
imports: import random
  from deap import algorithms
  from deap import base
  from deap import creator
  from deap import tools
  from deap import cTools
  import sortingnetwork
label_desc: Use image node_id 7 for calling a global function with example usage: main() and returns: population,  stats,  hof