GenePool is a framework for writing evolutionary optimization algorithms in OCaml. This library is not a complete solution but rather is a generic skeleton which takes care of the plumbing and nuisances of optimization. You provide GenePool with functions that give meaning to fitness and reproduction and after a specified number of generation, GenePool returns an array of the best "genomes" it evolved. You can download the GenePool source, which is distributed under the LGPL license.
The interface to GenePool is extremely simple. It consists of a single function evolve whose type is:
As you can tell from the signature, GenePool is polymorphic over both the representation of the genome and the type of fitness values. Typically your genome will be an array and fitness will be expressed as either an int or float. However, nothing stops you from using different types if your problem requires them.
The first parameter is a record (of type ga_spec) which encodes how evolution will proceed for your specific problem.
Some parameters (ie, the maximum number of generations, the number of genomes which survive each generations, etc...) are universal across all optimization algorithms. These are provided in another record, whose type is ga_params.
The return value of evolve is 'genome array * 'fitness which is the last generation sorted by order of their fitness and the fitness of the single best genome (ie, the genome at the 0th index of the returned generation).
To demonstrate GenePool in action, let's solve a completely trivial problem: maximizing the number of bits in a binary vector. First, we must pick a genome representation for solutions. In this simple case both the genomes and their corresponding solutions can be of the same type: bool array.
Now, let's make a ga_spec record to use as an argument to evolve. GenePool comes with a set of handy functions for manipulating array genomes. These can be found in the GenePool.ArrayGenome module.
Furthermore, let's create a ga_params record to specify that we want to evolve a 1000 vectors over 10 generations without a time limit.
To make something happen, just call evolve with the two records we just created. You'll get back the best array along with its fitness score.
You can download a copy of the above example here.
Since the internal timer in GenePool relies on the Unix module, be sure to link with either unix.cma or unix.cmxa (depending on which compiler you use).