Open Resch-Said opened 2 months ago
Not really an explanation for this weird behavior, but maybe a workaround. In the multi-objective example (https://pygad.readthedocs.io/en/latest/pygad_more.html#multi-objective-optimization), they use:
solution, solution_fitness, solution_idx = ga_instance.best_solution(ga_instance.last_generation_fitness)
This works well for me and (seemingly) always returns the best solution of the last generation.
So, I played around with pygad a bit and realized that you only get the best solution of the previous generation. This is particularly noticeable with a stop criteria.
I would like to put the stress especially on the part stop_criteria="reach_500". I put some prints in the on_generation method, so you can see that the limit is reached and the final solution is printed, but when I run the ga_instance.best_solution(), I only get the result of the previous generation.
I have uploaded a sample code here and the output as an image which makes it easy to recognize.