Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Evolixir

Minimal genetic algorithm toolkit in Elixir.

What it does

Evolixir provides a tiny, readable implementation of a genetic algorithm loop: initialize → evaluate → select → crossover → mutation → repeat.

Installation

If available in Hex, the package can be installed by adding evolixir to your list of dependencies in mix.exs:

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

Quick start (OneMax)

Find a 1000-bit chromosome of all 1s.

From the repo root:

mix one_max

Or use the wrapper script:

./bin/one_max

Showcase example

genotype = fn -> for _ <- 1..1000, do: Enum.random(0..1) end
fitness_function = fn chromosome -> Enum.sum(chromosome) end
max_fitness = 1000

solution = Evolixir.run(fitness_function, genotype, max_fitness, population_size: 100)

IO.puts("\nBest solution:")
IO.inspect(solution)

Parallel fitness evaluation

Evolixir.run(
  fitness_function,
  genotype,
  max_fitness,
  parallel: true,
  max_concurrency: 8,
  timeout: 5_000
)

Async GenServer runner

{:ok, pid} =
  Evolixir.Server.start_link(
    fitness_function: fitness_function,
    genotype: genotype,
    max_fitness: max_fitness,
    evolixir_opts: [parallel: true, max_concurrency: 8]
  )

{best, score} = Evolixir.Server.best(pid)
solution = Evolixir.Server.await(pid, 30_000)

Real example: route optimization (TSP-style)

mix run script/route_opt.exs

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages