PGAPy: Python wrapper for pgapack parallel genetic algorithm library

PGAPy is a wrapper for pgapack, the parallel genetic algorithm library (see pgapack Readme), 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.

For the Debian Linux distribution, pgapack is already included, install with a simple:

apt-get install pgapack

For debian the pre-built documentation is in /usr/share/doc/pgapack/user_guide.ps.gz

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:

Naming conventions in PGAPy

When you extend PGAPy -- remember not all functions of pgapack are wrapped yet and you may need additional functions -- you should stick to the my naming conventions when making changes. The following naming conventions were used for the wrapper:

  • Constants of pgapack like PGA_REPORT_STRING are used as-is in uppercase. These constants can be directly imported from the wrapper module. Not all constants are wrapped so far, if you need more, add them to the constdef array in pgamodule.c and send me a patch.
  • For methods of the pga.PGA class I've removed the PGA prefix used throughout pgapack and converted the method to lowercase with underscores between uppercase words in the original function name, so PGARun becomes run, PGACheckStoppingConditions becomes check_stopping_conditions.
  • Where possible I've made a single class method where pgapack needs a separate function for each datatype, so PGAGetBinaryAllele, PGAGetCharacterAllele, PGAGetIntegerAllele, PGAGetRealAllele all become get_allele. Same holds true for set_allele.
  • Internal method names in the wrapper program have a leading PGA_ -- so the class method set_allele is implemented by the C-function PGA_set_allele in pgamodule.c.

Missing Features

As already mentioned, not all functions and constants of pgapack are wrapped yet -- still for many applications the given set should be enough. If you need additional functions, you may want to wrap these and send me a patch.

Another feature of pgapack is currently not implemented in the wrapper, the usage of custom datatypes. With pgapack you can define your own datatypes complete with their custom implementations of the genetic algorithm functionality like crossover, mutation, etc. I don't expect problems implementing these, though.

Reporting Bugs

Please use the Sourceforge Bug Tracker and

  • give a short description of what you think is the correct behaviour
  • give a description of the observed behaviour
  • tell me exactly what you did.

Resources

Project information and download from Sourceforge main page