Evolutionary Programming!

And now for something completely different…

…most of the programming work i perform revolves around business issues (make sure business rule X is performed when condition Y is met etc…)

However just for fun I have had a look into the realm of evolutionary programming this is one part of the 4 major evolutionary algorithm paradigms. How did I come to look into this area so devoid from the usual software development I perform.

Well I was chatting to my boss at work who mentioned about the terrarium project setup by microsoft when .NET was first released, the principal was to create a software creature that could be uploaded to a shared ecosystem and effectively adapt and survive. This reminded me of a chapter of an old book I had attempted to read through a few years back about evolutionary programming.

In the chapter the author creates a program that makes robotic ants that follow a food trail on a grid, each time the next ant generation gets smarter and smarter and learn how to eat the most amount of food.

The whole idea of those ants getting smarter and smarter with no intervention to me is very cool and is what made me think that this would probably have been the way to go with coming up with a very intelligent creature for terrarium, instead of trying to come up with a answer to every possible encounter while in it’s environment, you could instead come up with some initial cases that it should deal with a then train generations of creatures in a fully controlled environment once you have an intelligent creature able to react to changes in the environment try it out in the shared environment.

Anyhow to cut a long story short I ported the code from the java book into C#, not as easy as it sounds when there was mistakes in the source code from the beginning! The program consists of windows form and an accompanying library, when the form is loaded you can select “Mutation Example” which shows how the mutations take place against a MutableFiniteMachine object, clicking the “Run” button unsurprisingly runs through a custom amounts of generations of ants and display how each one did, feedback is displayed via a textbox.

You can access the code via my google code repository. Be warned the code is not that great but instead was just to get an idea of how an evolutionary programming example works. It provides a base, you could from here extend the example so that ants are trained against varying graphs, penalised for taking too many moves, penalised for crossing previous paths, and also change the output into a more nicer grid UI, I leave those for an exercise for the reader 😉

One thought on “Evolutionary Programming!

  1. Neat. I once tried to write an evolutionary algorithm to create musical melodies. It started off by creating random streams of notes, the idea being you selected the best ones, and mutated those into a new generation, etc. Writing a selection function though — how to select good music from bad? when the whole point is to get music out of it, because making music is hard? Well my selection function involved listening to each generated MIDI sequence and voting yea or nay, gladiotor style… horrible stuff to listen to. Mostly a failure at generating music, perhaps due to my own impatience and limited lifespan, but interesting from a programming perspective nonetheless.

Comments are closed.