Evolution

Evolution can be regarded as an algorithm that repeatedly produces a new generation of designs from a previous generation such that the average fitness of the designs increases from generation to generation. The new generation is produced by asking the fittest designs in the current generation to reproduce themselves. The reproductions aren't exact, however. Chance mutations make some of the new designs superior (and some inferior) to their parent designs. The fitness of a design is determined by an external evaluator: designer, QA engineer, God, the environment, etc.

We can explain this using evolve.nlogo.

Here's a screen shot:

This model introduces a breed of turtles called designs:

breed [designs design]

Note: A breed is a subtype of the turtle. NetLogo automatically introduces variations of the turtle operations that apply only to the declared subtype. For example:

designs-own [...]

ask designs [...]

Each design has a fitness attribute:

designs-own [fitness]

Pressing the start button invokes the init-population procedure, which creates 100 designs of random fitness:

to init-population
  ca
  create-designs 100
  [
    set fitness random 100
    setxy random-xcor random-ycor ; for aesthetics
  ]
end

Pressing the evolve button repeatedly invokes the evolve procedure:

to evolve
  tick ; keeps count of generations
  if count designs = 0 [stop]
  let avg mean [fitness] of designs
  if fitness-goal < avg [stop] ; success!
  let current-designs designs  ; only current generation reproduces and dies
  ask current-designs
  [
    ifelse fitness > avg
    [
      reproduce
      die
    ]
    [
      die
    ]
  ]
end

This procedure kills all designs in the current generation. However, designs with above average fitness are allowed to reproduce before they die.

There are two types of reproduction: sexual and asexual. Both types produce one or more offspring. The offspring generally have the same fitness as the parent(s), but random mutation means that some designs will be more fit than their parent(s) while others less.

Here's a simple procedure for asexual reproduction:

to reproduce
  let parent-fitness fitness
  hatch 2
  [
    set fitness random (1.5 * parent-fitness)
  ]
end

In this case the parent produces two offspring. Ideally, this should keep the population stable because approximately half of the turtles are able to reproduce.

If the fitness of the parent is 50, then the fitness of the offspring will be a random number below 75. So one third of the time the offspring will be more fit than the parent.

In sexual reproduction, the fitness of the offspring is the average of the fitness of each parent plus or minus a random mutation.