Genetic Algorithms in Elixir: Ch 3 chromosome metadata not maintained (~p 144)

After creating the Chromosome type and updating the one_max script, the size attribute isn’t carried through. I realised that in both crossover() and mutation() the new Chromosome instance isn’t being populated by the relevant parent / existing chromosome. I updated the crossover code to

    {c1, c2} = {
      %Chromosome{p1 | genes: h1 ++ t2},
      %Chromosome{p2 | genes: h2 ++ t1}
    }

and similar for mutation:

      %Chromosome{chromosome | genes: Enum.shuffle(chromosome.genes)}

That sorted it out.

Unrelated I’m pretty sure there were some typos in the area where we updated all the framework code to carry the Problem definition through (initialise’s arguments were missing something, from memory) but I didn’t take notes.

Cheers,
Thomas

2 Likes