Initial commit

This commit is contained in:
2022-06-22 13:15:43 +02:00
commit 0b318ac0e4
10 changed files with 209 additions and 0 deletions

23
scripts/one_max.exs Normal file
View File

@@ -0,0 +1,23 @@
genotype = fn -> for _ <- 1..1000, do: Enum.random(0..1) end
fitness_function = fn chromosome -> Enum.sum(chromosome) end
max_fitness = 1000
defmodule OneMax do
@behaviour Problem
@impl Problem
def genotype() do
for _ <- 1..1000, do: Enum.random(0..
end
@impl Problem
def fitness_function(chromosome) do
Enum.sum(chromosome.genes)
end
end
soln = Genetic.run(fitness_function, genotype, max_fitness)
IO.write("\n")
IO.inspect(soln)