'Saving NEAT genome

Why does this code saves the worst genome (lowest fitness) instead of the best after I have completed "training"? I have tried to debug this for a while and still don't understand what's wrong.

winner = p.run(eval_genomes, 3)
with open("best.pickle.pkl", "wb") as f:
    pickle.dump(winner, f)
    f.close()


with open("best.pickle.pkl", "rb") as f:
    winner = pickle.load(f)
peli = Pelaaja()
peli.kokeile(winner, config)

Edit: For some reason I found out that the run function returns me the genome with lowest fitness. How can I get to the one with highest fitness.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source