PGAPy 0.1 review

Download
by rbytes.net on

PGAPy is a wrapper for pgapack, the parallel genetic algorithm library, a powerfull genetic algorithm library by D

License: LGPL (GNU Lesser General Public License)
File size: 0K
Developer: Ralf Schlatterbeck
0 stars award from rbytes.net

PGAPy is a wrapper for pgapack, the parallel genetic algorithm library, a powerfull genetic algorithm library by D. Levine, Mathematics and Computer Science Division Argonne National Laboratory.

The library is written in C. PGAPy wraps this library for use with Python. The original pgapack library is already quite old and not very actively maintained -- still I've found it one of the most complete and accurate (and fast, although this is not my major concern when wrapping it to python) genetic algorithm implementations out there with a lot of bells and whistles for experimentation. That's why I wanted to use it in Python, too.

There currently is not much documentation for PGAPy. You really, absolutely need to read the documentation that comes with pgapack -- and of course you need the pgapack library.

The pgapack library can be downloaded from the pgapack ftp site, it is written in ANSI C and therefore should run on most platforms. I have tested it on Linux only and I'll currently not provide Windows versions.

To get you started, I've included a very simple example in test.py that implements the "Maxbit" example -- modified to use integer genes instead of bits -- from the pgapack documentation. This illustrates several points:

- Your class implementing the genetic algorithm needs to inherit from pga.PGA (pga is the PGAPy wrapper module).
- You need to define an evaluation function called evaluate that returns a number indicating the fitness of the gene given with the parameters p and pop that can be used to fetch allele values from the gene using the get_allele method, for more details refer to the pgapack documentation.
Y- u can define additional functions overriding built-in functions of the pgapack library, illustrated by the example of print_string. Note that we do a call to the original print_string method of our PGA superclass.
- The constructor of the class needs to define the Gene type, in the example we use an integer (type (2), a python expression for the built-in integer datatype).
- The length of the gene (100 in the example) needs to be given.
-We want to maximize the numbers returned by our evaluation function, set the parameter maximize to False if you want to minimize.
- We can define an array of init values each entry containing a sequence with lower and upper bound. The array has to have the length of the gene. Note that the upper bound is included in the range of possible values (unlike the python range operator but compatible with the pgapack definition).
- In the constructor of the class we can add parameters of the genetic algorithm. Not all parameters of pgapack are wrapped yet, currently you would need to consult the sourcecode of PGAPy to find out which parameters are wrapped. In the example we define several print options.
- Finally the genetic algorithm is started with the run method.

PGAPy 0.1 search tags