Genetic Algorithms with JGAP

JGAP - Framework for Genetic Algorithms (and Genetic Programming)

There are several frameworks available to help you building up your own GA implementation without coping with the sticky details. One of these frameworks is JGAP. I am administrator of this project. There has been much feedback from JGAP users supporting the package with very positive feedback. The new release 2.0 was just published begin of this year and we got over a thousand page views one day. This is not much for some other projects, but I find it great for a sort of non-popular subject like Genetic Algorithms.

JGAP can be used as a startup basis, because it's not so complex and provides basic functionality.JGAP sets you into the position concentrating on the real problems of a GA: Setting up a fitness function, choosing a representation for your problem and fine-tuning the parameters. No need to hassle around with those boring stuff like programming random functions, genetic operators and so on. Although it is possible to implement your own extensions quite easily. Here's a class diagram for the most important JGAP classes (for version 1.1 and partly version 2.0):

(Click on image to zoom)

Implementing a GA

Using JGAP

With JGAP comes a simple example demonstrating the procedure of using the framework. The story behind the example is: For a given number between 1 and 100 find the minimum set of coins required to reach the given number. The coins available are 25, 10, 5, 2 and 1.

The Fitness Function

The fitness function is measuring the quality or fitness of a solution encoded by the internal state of an individual. In our example we just would calculate the difference between the number to be reached, say 100, and the number reached by the individual (using coins of several valences).

Representing an Individual

For the example an individual could be represented as a chromosome consisting of 5 IntegerGenes. An IntegerGene is a JGAP class and represents an integer number, that's easy. In our case, the index of the IntegerGene (1 to 5) would indicate the coin to use (25, 10 etc.). Additionally, the value of the IntegerGene would determine the number of coins of a certain value (25, 10...) to use.
With that we can easily encode possible solutions without knowing the solution exactly. And the fitness function could easily evaluate the state (resp. the coin value) of each single individual within the population.


With JGAP it is easy to implement Genetic Algorithms. It is offering all basic functionalities required to do so. Hosted at sourceforge you can use it freely and therefor be able to "go for gold" with evolutionary algorithms at no cost. Admitted: GA's - or generally speaking: EA's - are not a solution to any problem. They do not make you a magician. But for some problems they are definitively better than other algorithms (take the NASA who designed an antenna for space with help of GA's).
Watch out for other frameworks, like ECJ by Sean Luke. ECJ is more complex than JGAP which means it is more powerful on the one hand but you need more effort implementing your solution on the other hand.


No comments: