A genetic algorithm (GA) is a form of guessing machine. As an A.I. tool it can be seen as a creative function because it fuses together possible solutions in the search for an answer and also depends on a high degree of randomness. The GeneticAlgorithm class is an abstract class that must be extended in order for the library to be used, this is because the "fitness" of its components, the Chromosomes, is different for every task the GeneticAlgorithm is applied to. That is why the user of the library must extend GeneticAlgorithm and override the scoreFitness(Chromosome o) method. The Chromosomes can be used also to experiment with breeding automata, but they require the GA to supply most of the constants used in its operations, so yet again the GA class must be extended. Use of this library also requires knowledge of how to use Java's Vector class, which is a dynamic array for storing objects.
Unlike some GAs this one gives you the option of performing cross overs and mutations at a sub-integer level. This adds an extra level of randomness, and is performed using binary operations (so there's no real loss of speed). However, this can also lead to the values in the Chromosome's dna() to be greater than the number of traits defined up to a value of 2 to the power of the field traitBits(). You can choose to ignore these values (if value < traitSize() then use value) or you can wrap these values round using modulo (value % traitSize()). Sub-integer operations are not active as a default, but you can activate them with the command setSubInteger(true).
You may want to familiarise yourself with the following references before making use of this library:
Java Vector documentation
An
explanation of abstract classes
Genetic Algorithm links and code:
AI
Junkie's Genetic Algorithms for Beginners
Introduction to Genetic Algorithms
Craig Reynolds' Evolutionary Computation
Karl Sim's Artificial Evolution for Computer Graphics
Daniel Shiffman's Nature of Code
If you put together any work using the GA library Just drop me a line and I'll be happy to link to it here. Same goes for if you find any bugs, typos or just simply don't understand how this library works. Contact me at the Processing forums (st33d) or mail me: info[at]robotacid[dot]com.
To add the library to your project, put the unzipped folder gaLibrary into
the folder processing-###/libraries/
Next time you start Processing you should have a menu option of Sketch > Import
Library > gaLibrary
Click on that option to add the code: import ai.ga.*;
Source code can be downloaded here.
The Genetic Algorithm Library is released under the GNU Lesser General Public License
Tested with Processing and compiled with Eclipse
Powered by cups of tea and Boards of Canada records