Minimal genetic algorithm toolkit in Elixir.
Evolixir provides a tiny, readable implementation of a genetic algorithm loop: initialize → evaluate → select → crossover → mutation → repeat.
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"}
]
endFind a 1000-bit chromosome of all 1s.
From the repo root:
mix one_maxOr use the wrapper script:
./bin/one_maxgenotype = 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)Evolixir.run(
fitness_function,
genotype,
max_fitness,
parallel: true,
max_concurrency: 8,
timeout: 5_000
){: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)mix run script/route_opt.exs