Description
PYTHON VERSION:
Python 3.9
ERROR:
In tsp.py
, the Genetic Algorithm, which is implemented by the method genetic_algorithm(self, problem, map_canvas)
on line 221
attempts to reference an unknown method, argmax(population, key=fitness_fn
from the numpy
module on line 263
.
OUTPUT:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1884, in __call__
return self.func(*args)
File ".../aima-python/tsp.py", line 112, in run_traveling_salesman
self.create_canvas(tsp_problem)
File ".../aima-python/tsp.py", line 179, in create_canvas
self.genetic_algorithm(problem, map_canvas)
File ".../aima-python/tsp.py", line 263, in genetic_algorithm
current_best = np.argmax(population, key=fitness_fn)
File "<__array_function__ internals>", line 179, in argmax
TypeError: _argmax_dispatcher() got an unexpected keyword argument 'key'
EXPECTED BEHAVIOR:
When selecting the Genetic Algorithm in the GUI and starting the run, it should model the algorithm and provide the cost of the current route that is displayed on the Romanian map.
ACTUAL BEHAVIOR:
When selecting the Genetic Algorithm in the GUI and starting the run, nothing occurs and an error is thrown in the Python interpreter.
PROPOSED SOLUTION:
On line 263
, change it from:
current_best = np.argmax(population, key=fitness_fn)
to:
current_best = argmax_random_ties(population, key=fitness_fn)
so that it may reference the argmax_random_tie(seq, key)
method in the utils.py
package.