Skip to content

Bug in save best solutions #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
screetech opened this issue Jan 15, 2021 · 2 comments
Closed

Bug in save best solutions #25

screetech opened this issue Jan 15, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@screetech
Copy link

screetech commented Jan 15, 2021

Description

If save_best_solutions = True, the best_solutions list is overwritten after each generation when a new population is being generated. A bug appears on line number 748. Solutions stored in best_solutions are probably just shallow copies, i.e., pointers to population.

What the bug looks like

best_solutions = []
best_solutions = [[9, 10, 5, 9, 9]] # after append on the line 728, it holds first best solution found
best_solutions = [[6, 9, 6, 9, 6]] # after the line 748, original value has been changed (changed after every single generation)

@ahmedfgad ahmedfgad self-assigned this Jan 15, 2021
@ahmedfgad ahmedfgad added the bug Something isn't working label Jan 15, 2021
@ahmedfgad
Copy link
Owner

Thanks.

The bug is fixed by creating a copy of the best solution. This prevents a solution saved in the best_solutions attribute from being changed.

The next line:

best_solution = self.population[best_match_idx, :]

is replaced by this line:

best_solution = self.population[best_match_idx, :].copy()

ahmedfgad added a commit that referenced this issue Jan 15, 2021
A bug fix when save_best_solutions=True. Refer to this issue for more information: #25
@ahmedfgad
Copy link
Owner

PyGAD 2.10.2 is released which addresses this issue. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants