Building a Framework for Genetic Algorithms

You now have an empty project and an idea of what your genetic algorithm framework should look like. It’s time to start implementing each step.

Start by opening the genetic.ex file. The file is populated with some default code and will look something like this:

 defmodule​ Genetic ​do
  ...documentation...
 def​ hello ​do
 :world
 end
 
 end

You can delete the default documentation and Hello World function. This module will contain the most basic parts of your genetic algorithm. This is where you’ll define each step of the algorithm based on the rules you determined earlier.

Creating an Initial Outline

In genetic.ex, start by creating a function named run, like this:

 def​ run(...) ...

Get Genetic Algorithms in Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.