A toolkit for genetic algorithms in Python, written as a companion to a technical talk.
The levis
package contains a collection of genetic traits meant
to be composed to achieve a desired algorithm behavior.
To implement your own GA, you will probably want to extend from one of the
classes in selection
and one of the classes in logger
. The former will
give you proportionate or tournament selection, and the latter will enable
logging (including verbosity).
You'll also want to override the crossover()
and mutate()
methods with
implementations from the packages by the same name.
The examples each have three components: a genetic solution, a method to
generate data, and a main
method to wire in command line arguments. The
examples will respond to a -h
flag to display help.
Levis currently targets Python 2.7 and has no external dependencies for basic
use. Image rendering in the examples, when implemented, relies on svgwrite
,
and some data generation needs Faker
.:
$ pip install svgwrite $ pip install fake-factory
Install by cloning the git repository. Installation via PyPI is coming soon.:
$ git clone https://github.com/rawg/levis
If you're looking at this project, you're probably more interested in the
example implementations than in the core genetic behaviors. Each *.py
file
in the examples/
folder should respond to a -h
argument to list its
options. All should run without any options, but you'll want to tweak the
parameters to better understand each algorithm.:
$ cd examples/ $ python knapsack01.py -h $ python knapsack01.py --iterations=10 --population-size=5
Embarassingly, there aren't that many to run! Test suites can be run individually, like so::
$ cd tests $ python test_crossover.py
The code is run through pylint
, if that sort of thing interests you. Note
that many pylint warnings are currently ignored, but it's good to know your
faults.
- [ ] Python 3 support
- [ ] Alternative end conditions
- [ ] Cycle crossover
- [ ] Merge crossover
- [ ] Explicit "cut-and-splice" crossover (use n-point in the meantime)
- [ ] Separate traits for logging behavior
- [ ]
NewBestScore
to add a trigger for when a new high score is seen - [ ] Clean up handling of configuration and CLI arguments
- [ ] More tests
Version numbers follow the SemVer scheme. For the versions available, see the tags on this repository.
Only one soul can be blamed for this:
- Jeremy Fisher, @thisisroot.
This project is licensed under the MIT License - see the LICENSE.md file for details.