Genex

Genex makes it easy to write Genetic Algorithms with Elixir.

Build StatusCoverage Status

This library is inspired by Python's DEAP.

Installation

The package can be installed by adding genex to your list of dependencies in mix.exs.

def deps do
[
{:genex, "~> 0.1.0"}
]
end

Usage

Genex works by making transformations on a Population.

The simplest way to use Genex is by including it in one of your modules with default parameters.

It requires you to implement 3 functions: encoding/0, fitness_function/1, terminate?/1.

defmodule OneMax do
use Genex
def encoding do
for _ <- 1..10, do: Enum.random(0..1)
end
def fitness_function(chromosome), do: Enum.sum(chromosome.genes)
def terminate?(population), do: population.max_fitness == 10
end

Your algorithm can then be run by calling the run/0 method Genex provides.

Visualization

Genex currently offers text visualization of populations. To view a summary of the solution your algorithm produced simply do:

soln = OneMax.run()
Genex.Visualizers.Text.display_summary(soln)

Genealogy

Genex comes with an implementation of a Genealogy tree using an Erlang digraph. The tree is available in the history field of the Population struct. As of this version of Genex, there are no pre-packaged genealogy visualizers. You'll have to find a third-party solution.

Configuration

Genex can be configured like so:

def MyGA do
use Genex, crossover_type: :two_point, crossover_rate: 0.5
...
end

Please see the documentation for a full list of configuration options.