Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions examples/interactive.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
defmodule Interactive do
use Genex

def encoding, do: Chromosome.binary(size: 10)
def genotype, do: Genotype.binary(10)

def fitness_function(chromosome), do: interactive(chromosome)
def fitness_function(chromosome), do: Evaluation.interactive(&read/1, "\nRate this\n", chromosome)

def terminate?(population), do: population.max_fitness >= 10

defp read(prompt) do
prompt
|> IO.gets()
|> String.trim_trailing()
|> String.to_integer()
end
end

import Genex.Config
solution = Interactive.run(
population_size: 5
)

[population_size: 5]
|> Interactive.run()
IO.inspect(solution.strongest.genes)