+ 5

Genetic algorithm

i wanted to learn more about ai on the way i encounterd genetic algorythms so i tried programing a commonly used practice for genetic algorythm (monkeys typing a line from shakespeare) my code is now not the best but it works for smaller lines now the problem i have is , that the code wont print the count of the latest generation :/ so i would like to ask for some help please :) https://code.sololearn.com/cdqQ67qYXQ45/?ref=app

20th Oct 2018, 8:58 PM
Mbrustler
Mbrustler - avatar
2 Antworten
+ 3
When you are inside in function you need to say to python that gen variable is global. So inside crossover in beginning you need write. global gen The error happens because python interpreter is trying to create a local variable called gen.
20th Oct 2018, 9:15 PM
Anya
Anya - avatar
+ 2
thank you :)
20th Oct 2018, 9:18 PM
Mbrustler
Mbrustler - avatar