Initial commit
This commit is contained in:
23
scripts/one_max.exs
Normal file
23
scripts/one_max.exs
Normal 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)
|
Reference in New Issue
Block a user