Skip to content
Genetic Algorithms in Elixir!
Branch: master
Clone or download
Sean Moriarity
Latest commit e9618c9 Aug 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bench up for v0.2.0 Aug 9, 2019
examples davis order test fix Aug 15, 2019
guides update docs Aug 10, 2019
lib davis order test fix Aug 15, 2019
test davis order test fix Aug 15, 2019
.formatter.exs first commit Aug 3, 2019
.gitignore WIP Aug 13, 2019
.travis.yml Add coverage Aug 5, 2019
LICENSE Create LICENSE Aug 9, 2019 accidentally deleted README Aug 18, 2019 added config library Aug 13, 2019
mix.exs update README Aug 10, 2019
mix.lock added tests Aug 8, 2019


Genex makes it easy to write Genetic Algorithms with Elixir.

Build Status Coverage Status Hex Version

This library is inspired by Python's DEAP.


Documentation is available at


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

def deps do
    {:genex, "~> 0.2.1"}


Genex requires an implementation module with 3 functions: encoding/0, fitness_function/1, and terminate?/1.

defmodule OneMax do
  use Genex

  def encoding do
    for _ <- 1..10, do: Enum.random(0..1)

  def fitness_function(chromosome), do: Enum.sum(chromosome.genes)

  def terminate?(population), do: population.max_fitness == 10

Now, run iex -S mix.




Genex strives to be as simple and customizable as possible. Along with the ability to customize EVERY step of your Genetic algorithm, Genex comes with the following features:

  • 6 Selection Operators
  • 7 Crossover Operators
  • 6 Mutation Operators
  • Customizable Population Statistics
  • Customizable Benchmarking of Algorithms
  • Exportable Genealogy Tree
  • Flexible Encoding of Chromosomes
  • Simple Text Visualizations


There are currently 3 basic examples available in the examples directory. To run them, clone the repo and run:

mix run examples/[example].exs

The current examples are:

  • one_max.exs
  • knapsack.exs
  • speller.exs
  • linear_regression.exs
  • n_queens.exs


To run benchmarks, clone this repo. In the genex directory run:

mix run bench/benchmarks.exs

You can also run the individual benchmarks available in the bench/ directory. This will take some time!


If you have any problems with Genex, please open an issue! If you have a fix for an issue, submit a pull request.


The next phase of this library will involve extensive performance improvements. Most of the algorithms involve processing very large lists. This is an ideal job for a NIF.

If anybody has any experience writing NIFs or writing algorithms for processing large lists, email me to get involved!

You can’t perform that action at this time.