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 | Hill climbing algorithm AttributeError - attempts to reference an unknown method from numpy #1255

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

Comments

@k-le
Copy link

k-le commented May 1, 2022

PYTHON VERSION:
Python 3.9

ERROR:
In tsp.py, the Hill Climbing algorithm, which is implemented by the method hill_climbing(self, problem, map_canvas) on line 281 attempts to reference an unknown method, argmax_random_tie(arg1, arg2) from the numpy module on line 297.

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/gui/tsp.py", line 112, in run_traveling_salesman
    self.create_canvas(tsp_problem)
  File ".../aima-python/gui/tsp.py", line 187, in create_canvas
    self.hill_climbing(problem, map_canvas)
  File ".../aima-python/gui/tsp.py", line 297, in hill_climbing
    neighbor = np.argmax_random_tie(neighbors, key=lambda node: problem.value(node.state))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/__init__.py", line 315, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'argmax_random_tie'

EXPECTED BEHAVIOR:
When selecting the Hill Climbing 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 Hill Climbing algorithm in the GUI and starting the run, nothing occurs and an error is thrown in the Python interpreter.

PROPOSED SOLUTION:
On line 297, change it from:
neighbor = np.argmax_random_tie(neighbors, key=lambda node: problem.value(node.state))
to:
neighbor = argmax_random_tie(neighbors, key=lambda node: problem.value(node.state))
so that it may reference the argmax_random_tie(seq, key) method in the utils.py package.

@k-le k-le changed the title tsp.py | Hill climbing algorithm AttributeError - attempts to reference a method from numpy instead of utils.py tsp.py | Hill climbing algorithm AttributeError - attempts to reference an unknown method from numpy May 1, 2022
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