Last night, FlashBrighton hosted a Code-along session, the primary objective of which was to develop a genetics algorithm collaboratively. Edd and I were there, desperately trying to follow the proceedings in our languages of choice, C# and Java, respectively.
At the risk of massively over-generalizing, from my understanding of last night’s session, the general pattern of a genetic algorithm is thus:
- Create a random population
- Evaluate the ‘fitness’ of the members of the population
- Destroy the ‘least fit’ members of the population
- To make up the numbers, the sad loss of aforementioned weaklings is replaced with mutations of the ‘most fit’ members of the population
To whet our appetites, we were given a quick demo of SmartRockets, a clever population of rockets that, over time, learn how to hit a random target.
So, with the groundwork covered, it was time to crack open our respective IDEs and attempt to follow along. As GA newbies, we didn’t quite reach the lofty heights of the SmartRockets algorithm, but we did create a population of bit streams, whose goal was to eliminate all 0s in favour of 1s.
Here’s the ActionScript implementation and, for those that attended last night and are interested, my Java implementation of this algorithm is here (execute it using this Java class). And Edd’s C# implementation here.
Sadly, I had to leave before the end of the night, in the midst of everyone debating how to evaluate a population whose sole intent was to evolve into a certain colour (at least that was my understanding, had my head stuck in a cloud of 1s and 0s, so it was hard to tell!) — for anyone that was there, I’d love to see the end result of this discussion!

3 Comments
Was a fun evening and I learnt quite a lot too… namely that I should stick to PHP.
I don’t think my C# code stuck strictly to the Actionscript we were trying to port but it seems to do somthing right… just not in the tidiest manner :)
I learned a lot about genetic algorithms in some courses at University. They are very useful for finding solutions to problems with huge numbers of variables – like predicting the weather or finding the best configuration for a robot’s limbs. And this screen saver uses people to evaluate the fitness of the best looking “sheep”:
http://www.electricsheep.org/. I’ve got an older version of Linux though so I haven’t installed it myself.
It’s a shame, but I’ve yet to come across any website development problem where I could even consider using a GA to solve it. I would really like to.
Yep, I agree, would definitely love the opportunity to put some of this theory into practice using the Web.