Genetic Algorithms in Elixir: Ch 4, changing evolve to track generation (~p 174

The definition for run/2 is also included but the call to evolve is omitted.

This solved the issue for me:

  def run(problem, opts \\ []) do
    population = initialize(&problem.genotype/0, opts)
    population
    |> evolve(problem, 0, opts)
  end

(To clarify where this is in the book: Just before you add temperature tracking in the evolve method.)

1 Like

Good catch :slight_smile:

I think the many adjustments that are made to track different termination criteria can get a little overwhelming and make the chapter a bit confusing (especially with mistakes like this). Did you find the chapter difficult to follow at all? If you have any questions, suggestions or feedback, feel free to PM me!

1 Like

I think there’s a weird stumbling block near the end of the chapter where you sketch out an approach in code but I’m not sure it actually is enough to run (the portfolio example). I haven’t gotten back to it yet but I think there might also be a return type issue with that one, from memory. When I next sit down with it I’ll write something up in a topic here if it’s not just user error.

Apart from that it’s all making perfect sense. I would generally suggest making the signature for the terminate function take 3 arguments for the remainder of the book, even if we’re only using any one of them at a time. Right now it’s a bit messy as the signature of the method call fluctuates a fair bit and it requires a bit of diligence to keep examples running (I think you added the temperature to it but then backed out of using that, from memory).