Skip to content
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

tsp.py | Genetic Algorithm passes in incorrect parameters to np.argmax() #1256

Open
k-le opened this issue May 1, 2022 · 0 comments
Open

Comments

@k-le
Copy link

k-le commented May 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant