More changes

This commit is contained in:
2022-06-28 08:57:51 +02:00
parent 0b318ac0e4
commit e367229253
6 changed files with 129 additions and 20 deletions

View File

@@ -1,23 +1,24 @@
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
alias Types.Chromosome
@behaviour Problem
@impl Problem
@impl true
def genotype() do
for _ <- 1..1000, do: Enum.random(0..
genes = for _ <- 1..1000, do: Enum.random(0..1)
%Chromosome{genes: genes}
end
@impl Problem
@impl true
def fitness_function(chromosome) do
Enum.sum(chromosome.genes)
end
@impl true
def terminate?(_population, generation), do: generation == 100
end
soln = Genetic.run(fitness_function, genotype, max_fitness)
soln = Genetic.run(OneMax)
IO.write("\n")
IO.inspect(soln)
IO.inspect(soln.genes)