Building Bridges with Evolutionairy Algorithms and Javascript

Last time, I described the first "evolutionairy algorithm" I made. This time, let's have a look at a newer one I wrote:

It tries to build some sort of bridge to the right. On the left hand side, you can see the best individual of each generation. On the right, a plot of the fitness of the best individual for each generation. The fitness is defined as

fitness = Math.pow(maxX, 1.5) / number of (edges + nodes)

So the maximum distance the bridge covers is weighted and compared to the number of nodes and edges used. This allows for dynamic numbers of nodes, and therefor allows different types of bridges to be compared. Adding to this, speciation would be useful. That would mean separating different types of bridges, so new designs have a chance of evolving without having to compete with old, tested designs.

Maybe, one day...

As of now, this program uses the following principles:

  • 4 Different Types of mutation
    • Adding a node
    • Moving a node
    • Removing a node
    • Adding an edge
  • Roulette Wheel Selection of parents

And missing the following:

  • No crossover (hard to implement for structures like these)
  • No speciation

It was an interesting experiment and took quite some iterations to get to work properly. And even now, I don't seem to get consistent results. Sometimes bridges look like this, sometimes like that. The beforementioned speciation may help with that, seeing different species evolve and therefore being able to asses the design. Whereas the way it is right now, I have to leave it running a few times and compare results afterwards.

Implemented in Javascript, using

Matter.js seems to be a little unstable. It changes behaviour, when the window is not in focus, and also, when adjusting the timestep. Still, very usable and nicely documented.