Angel \”Java\” Lopez on Blog

December 15, 2008

Playing with evolvable programs

Filed under: .NET, Artificial Intelligence, C Sharp, Software Development — ajlopez @ 9:57 am

Yesterday, I wrote a codekata-like solution. I like the idea of evolvable programs (having agents with programs that evolves, in a simulated environment), so I created a solution dedicated to experiment with a proof of concept example. It’s written in C# using VS 2008 and its test support. I’ve commited to my ajcodekatas google code project at:

http://code.google.com/p/ajcodekatas/source/browse/#svn/trunk/EvolveExample

The solution is EvolveExample:

(If you don’t have the test features installed in your VS, you can remove the Evolve.Test project).

The core classes reside in Evolve class library project:

Animal represents the agent. It has a list of Instructions, that are randomly generated. An animal habitates a field with food. Its program has instruction to Eat, Move East, North, West, South, or Predate (get food from other animal in the same cell in grid). Each instruction has a cost: one point of energy. Eat is an instruction to get 10 points of energy or less, from the food in the current cell. Predate get 100 points of energy or less, from any other animal in the same cell.

To see the program in action, start the Evolve.GUI winform project, select Evolve -> Run menu option. You’ll see:

The field is a grid (in this example, 20×20). Each cell has a food level (green is full, blank is empty). At the left, a list shows the best animals and its program. The animals are ranked according to their energy levels at the end of a simulation run. The program continues to run more simulations, with new fields. In the next simulation, the population is ordered by descending energy, the top performers are included in the new simulation, they are are mutated, and some new animals are injected with new random programs.

During a simulation, the food level and the best animal information is displayed in the status at bottom.

With Food and Population menu options, you can set the food level to seed in the field at beginning of each simulation, and the number of agents to include. The settings are for the next Evolve -> Run. Evolve -> Stop option can be used to terminate a serie of simulations.

Next steps

This is a first example, a proof of concept solution. I have some ideas to explore in future versions:

- Having a more interesting instruction set, with conditionals, sensoring the environment. I like to add something like “If there is food at north, go north”.

- Settings (field size, food level, initial energy) via a form, and serialize the values in .XML files

- Serializes the results and populations to .XML files

- Evolution in a cluster. I could use AjMessages, AjAgents, or MPI over HPC cluster, to simulate evolution in a grid/cluster of machines.

As usual, I had fun writing the code!

Angel “Java” Lopez
http://www.ajlopez.com/en
http://twitter.com/ajlopez
http://delicious.com/ajlopez

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers