Experiment with genetic algorithm

I’ve got some ideas for kinetic sculptures involving genetic algorithms. The specifics of of the sculptures are still in flux, and I’m waiting to see which ideas gel.  In the meantime, however, I’ve started build a code base to begin to see what I can do with GA.  Here is one of the first little Processing sketches I’ve done to get the basics working.

This is a continually evolving population of Lines.  Each row is a member of the population called a Line.  A Line is defined by a string of  random numbers (0-1) that makes up its “DNA”.  When the Line is born, its DNA is translated in chunks of two numbers, each two number chunk defines a single segment of that Line, and an Line is made of multiple segments.  The two numbers determine the color and length of a segment.  The DNA is read until the Line is complete at the edge of the screen.  All the lines on the screen at a given moment represent the population.

Once the population is complete, each is evaluated for fitness, as defined by the controls on the bottom, and the most fit members of the population are mated and mutated to generate a new population.

The controls at the bottom allow the user to select for a lines color (purple or green) and segment length (long or short).  The sliders allow you to adjust to population size and the mutation rate.

So, really not much interesting looking happens as you click the buttons.  Select for short-segmented green Lines and you get them.  But keep in mind that the changes that you are seeing are based on the probabilistic evolution of the population.

You can click here or the images below to run the program yourself. This GA code is based on the work of Daniel Shiffman

No Comments

Post a reply

© 2012 FIVE TON CRANE | RSNEIGHT designs