Skip to content

Error when running 3.2.0 vs. 3.1.0 for ga_instance.best_solutions #261

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
mrh335 opened this issue Jan 8, 2024 · 2 comments
Closed

Error when running 3.2.0 vs. 3.1.0 for ga_instance.best_solutions #261

mrh335 opened this issue Jan 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@mrh335
Copy link

mrh335 commented Jan 8, 2024

When running version 3.1.0 and prior, the code runs to completion and returns result. When installing 3.2.0, the following error is returned after the ga_instance.run() has completed and the following code is run: solution, solution_fitness, solution_idx = ga_instance.best_solution()

`100%|██████████| 100/100 [01:44<00:00, 1.04s/it]
'numpy.ndarray' object has no attribute 'index'
Traceback (most recent call last):
File "C:\Users\user\AppData\Roaming\Python\Python312\site-packages\pygad\pygad.py", line 1663, in cal_pop_fitness
solution_idx = self.best_solutions.index(list(sol))
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute 'index'
An exception has occurred, use %tb to see the full traceback.

Traceback (most recent call last):

File ~\AppData\Roaming\Python\Python312\site-packages\pygad\pygad.py:1663 in cal_pop_fitness
solution_idx = self.best_solutions.index(list(sol))

AttributeError: 'numpy.ndarray' object has no attribute 'index'

During handling of the above exception, another exception occurred:

SystemExit: -1`

@mrh335 mrh335 closed this as completed Jan 10, 2024
@Domsall
Copy link

Domsall commented May 16, 2024

I am having the same issue, what was your solution to the problem? @mrh335 @ahmedfgad

For reference, my issue is solved by deleting these lines:

elif (self.save_best_solutions) and (len(self.best_solutions) > 0) and (list(sol) in self.best_solutions):
solution_idx = self.best_solutions.index(list(sol))
fitness = self.best_solutions_fitness[solution_idx]

@ahmedfgad ahmedfgad added the bug Something isn't working label Jan 7, 2025
@ahmedfgad
Copy link
Owner

This is also highlighted in this issue: #293.

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

3 participants