Understanding Reinsertion

Reinsertion is the process of taking chromosomes produced from selection, crossover, and mutation and inserting them back into a population to move on to the next generation. Look at evolve/4 in genetic.ex. It looks like this:

 def​ evolve(population, problem, generation, opts \\ []) ​do
  population = evaluate(population, &problem.fitness_function/1, opts)
  best = hd(population)
  IO.write(​"​​\rCurrent best: ​​#{​best.fitness​}​​\tGeneration: ​​#{​generation​}​​"​)
 if​ problem.terminate?(population, generation) ​do
  best
 else
  {parents, leftover} = select(population, opts)
  children = crossover(parents, opts)
  children ++ leftover
  |> mutation(opts)
  |> evolve(problem, generation+1, opts)
 end ...

Get Genetic Algorithms in Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.