From 0e65529cf20f02bddbcfb23ffec541e19483d9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20de=20Alc=C3=A2ntara=20Barroso?= Date: Mon, 27 Jun 2022 23:40:17 +0100 Subject: [PATCH] Fix interactive example --- examples/interactive.exs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/interactive.exs b/examples/interactive.exs index 4448ef4..97b5d84 100644 --- a/examples/interactive.exs +++ b/examples/interactive.exs @@ -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() \ No newline at end of file +IO.inspect(solution.strongest.genes)