For my first attempt at anything like this, I found an excellent guide  and programmed the example. The algorithm had the task of making an equation that equalled a goal number. So, for example, I might tell it “Make me an equation nine long that creates 13”, and it could come back with (1 * 9 + 2 + 6 - 4).
It took quite a while to get it working since the algorithm isn’t deterministic I found the code quite hard to debug. It all works well now though, and I’m quite pleased with the code, it’s clean, and I managed to optimise it to run a lot faster.
As always feel free to use the code, any feedback would be useful. Next up I’m going to apply GA to a more interesting problem.
Edit: I optimised the code by using the SBCL profiler to see what was slowing things down. It turned out that the spin-the-wheel function was taking about 92% of the time with the functions it called. Firstly I examined the function and realised I could reduce the comparisons, that reduced it to about 87%. Next, the guys in #lisp explained that I should declare the variables in that function as float’s so that SBCL could optimise things for me. When I tried that it reduced the time spent in spin-the-wheel down to around 36%!
I found it surprising that the ‘roulette wheel spinning’ function that we use to select chromosomes for crossover was the most computationally intensive part of the code. I’m curious to know if that’s normal. Also if you have any idea how I could optimise more I would be grateful, here is the profiler output.
 - According to the comments the guide is teaching very out of date methods, possibly consider a different source of information!
Edit: Before I replaced WordPress there were some excellent comments:
That tutorial is really quite astonishingly crappy. So what I’m going to say is obviously exaggeration but is close to the truth:
(1) NO ONE has done roulette selection in the last ten years. Tournament selection, truncation selection, etc., yes. Roulette selection? Laughable.
(2) NO ONE has done binary encodings of non-binary problems in the last ten years. You use an encoding which matches your actual problem.
(3) NO ONE does one-point crossover any more. A parametrisation uniform crossover. Or at LEAST, heaven forbid, a two-point crossover.
(4) NO ONE does genetic programming (the little encoding of math the guy’s showing) in a fixed-length string. It borders on the hilariously ignorant.
Hey, it’s all fine if you’re doing this for the first time, and you go pick up a 1970 book on genetic algorithms and publish a web page on how you coded it up. But to claim that you’re doing a TUTORIAL? This guy should have been taken out behind the shed and shot.
You might find this tutorial useful: http://www.obitko.com/tutorials/genetic-algorithms/index.php
Also, the “field guide to genetic programming” by Poli, Langdon and McPhee is very up-to-date, and can be downloaded for free: http://www.lulu.com/content/2167025