Genetic algorithm packages for Python.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
fmga Changed interface to access to population parameters. Dec 21, 2018
vcga/vcga
.gitignore
LICENSE
README.md
fmga_neuro.py
fmga_plots.py
fmga_spiral_linear.png
fmga_spiral_neuro.png
fmga_test.py
functionplot.png added plot screenshots May 19, 2018
meanstats.png

README.md

GeneticAlgorithmsRepo codebeat badge

An assortment of genetic algorithms - all written from scratch, for Python 3.5.

Objective Function Maximization

fmga is a genetic algorithms package for arbitrary function maximization.
fmga is available on PyPI - latest version 2.7.0 - and now supports multiprocessing, a fmga.minimize() method and an easier interface to unpack arguments with fmga.unpack()!

pip install fmga

Then, use with:

import fmga
fmga.maximize(f, population_size=200, iterations=40, multiprocessing=True)

The objective function doesn't have to be differentiable, or even continuous in the specified domain!
The population of multi-dimensional points undergoes random mutations - and is selected through elitism and raking selection with selection weights inversely proportional to fitness and diversity ranks.

fmga_plots.py contains relevant code on obtaining surface plots of the function (if 2-dimensional), initial population and final population graphs, as well as line plots of mean population fitness and L1 diversity through the iterations.
Completely customizable - licensed under the MIT License.


A neural network trained by fmga by code in fmga_neuro.py, inspired by this exercise.

See the README in the fmga subdirectory for more details.

Minimum Vertex Cover for Graphs

vertex_cover.py gives a genetic algorithm heuristic to the well-known NP-Complete Minimum Vertex Cover problem - given a graph, find a subset of its vertices such that every edge has an endpoint in this subset.
This is an implementation of the OBIG heuristic with an indirect binary decision diagram encoding for the chromosomes, which is described in this paper by Isaac K. Evans, here.
A networkx graph is used as an input - and a population of vertex covers mutates and breeds to find an minimum vertex cover. As above, elitism and breeding with selection weights inversely proportional to fitness and diversity ranks are used to generate the new population.
The fitness of each vertex cover is defined as: