
My application doesn't quite conform to the true rules - I create six random source numbers and a single target number. The application then creates a candidate solution by inserting a random operator (add, subtract, multiply or divide) between each number. This candidate solution then spawns a mutated version - the mutation is a 50/50 chance of either randomly changing an operator or randomly exchanging the order of two of the numbers.
Whichever version of the solution is nearer to the target number lives on to the next generation where it spawns a further mutation. This process repeats until the rounded down result of a solution matches the target number.
The application is small and to get things finished in a short space of time, I've dispensed of any real framework. The main logic is in GeneticCountdownModel, but I've put the fitness function in CandidateSolutionPair. In a similar fashion, CandidateSolutions are responsible for their own cloning and mutations.
The application uses my SoftSkin - a skin I've been playing with over the last few weeks. I've included the source, but be warned it's a bit of a mess at the moment. It's still work in progress with lots of little hacks and copy-and-pastes and is desperate need of some serious refactoring.
Add a comment