Genetic Algorithm Simulation

Each car is controlled by a vector of accelerations (DNA). The goal is to go as far as possible on the track.

✨The obstacles can be moved with the mouse.


Navigation

  1. The DNA of Cars
  2. Life Cycle of a Generation
  3. Fitness and Evolution

1. The DNA of Cars

Each car has a vector of accelerations:

  • It’s a list of small vectors applied at every time step.
  • This determines its trajectory.

DNA schema:

Car DNA = [ (→), (↗), (↑), (↗), (→), (↓), ... ]

2. Life Cycle of a Generation

The genetic algorithm follows this cycle:

  1. Initialization: create a population of cars with random DNA.
  2. Simulation: each car follows its DNA until it dies or reaches the finish line.
  3. Evaluation: compute its fitness (distance traveled, bonus if reached).
  4. Selection: keep the best individuals (elitism).
  5. Crossover: mix DNA from two parents.
  6. Mutation: randomly change some genes.
  7. New generation: repeat the process.

3. Fitness and Evolution

  • Fitness = distance reached (plus a bonus if the finish line is crossed).
  • Cars that die too early get a penalty.
  • Over generations, the population learns to avoid obstacles better.
Generation 1 : random cars (all die quickly)
Generation 5 : some pass the first obstacle
Generation 15: a few get near the finish
Generation 50+: most can finish successfully