ahmedfgad / GeneticAlgorithmPython

Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).
https://pygad.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.79k stars 451 forks source link

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

Closed mrh335 closed 5 months ago

mrh335 commented 5 months ago

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`

Domsall commented 1 month ago

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: https://github.com/ahmedfgad/GeneticAlgorithmPython/blob/0e8be9d61070df832ab89cae993e8827567d1184/pygad/pygad.py#L1683-L1685