code: def main():
      random.seed(64)
  
      NBR_DEMES = 3
      MU = 300
      NGEN = 40
      CXPB = 0.5
      MUTPB = 0.2
      MIG_RATE = 5
  
      demes = [toolbox.population(n=MU) for _ in range(NBR_DEMES)]
      hof = tools.HallOfFame(1)
  
      stats = tools.Statistics(lambda ind: ind.fitness.values)
      stats.register("avg", numpy.mean)
      stats.register("std", numpy.std)
      stats.register("min", numpy.min)
      stats.register("max", numpy.max)
  
      logbook = tools.Logbook()
      logbook.header = (
          "gen",
          "deme",
          "evals",
          "std",
          "min",
          "avg",
          "max",
      )
  
      for idx, deme in enumerate(demes):
          for ind in deme:
              ind.fitness.values = toolbox.evaluate(ind)
          logbook.record(
              gen=0, deme=idx, evals=len(deme), **stats.compile(deme)
          )
          hof.update(deme)
      print(logbook.stream)
  
      gen = 1
      while gen <= NGEN and logbook[-1]["max"] < 100.0:
          for idx, deme in enumerate(demes):
              deme[:] = toolbox.select(deme, len(deme))
              deme[:] = algorithms.varAnd(
                  deme, toolbox, cxpb=CXPB, mutpb=MUTPB
              )
  
              invalid_ind = [
                  ind for ind in deme if not ind.fitness.valid
              ]
              for ind in invalid_ind:
                  ind.fitness.values = toolbox.evaluate(ind)
  
              logbook.record(
                  gen=gen,
                  deme=idx,
                  evals=len(deme),
                  **stats.compile(deme),
              )
              hof.update(deme)
          print(logbook.stream)
  
          if gen % MIG_RATE == 0:
              toolbox.migrate(demes)
          gen += 1
  
      return demes, logbook, hof
  
file_path: deap/examples/ga/onemax_multidemic.py
imports: import array
  import random
  import numpy
  from deap import algorithms
  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() and returns: demes,  logbook,  hof