aimacode / aima-python

Python implementation of algorithms from Russell And Norvig's "Artificial Intelligence - A Modern Approach"
MIT License
8.04k stars 3.8k forks source link

PriorityQueue needs rework #1024

Open rajatjain1997 opened 5 years ago

rajatjain1997 commented 5 years ago

As pointed out by #919 and #941, A search is behaving incorrectly. This is partly due to the way the A implementation interfaces with the PriorityQueue (in utils.py). Due to how __contains__ is implemented in PriorityQueue, if the heuristic function passed to A produces non-unique values for the same state (As in the case of #919), A would re-visit the same state multiple times.

829 also raises some concerns about the implementation of __getitem__ and __contains__ in PriorityQueue. While these methods seem similar, they are quite distinct. Using __getitem__ instead of __contains__ should fix A*. However, since both these functions are confused many times (#828), we should include at least some documentation and test cases to illustrate this use. Another solution to this confusion would be altering the roles of __getitem__ and __contains__ such that for a priority queue A and element x:

zeph1yr commented 5 years ago

Is this issue resolved? If resolved, why is it still open?

rajatjain1997 commented 5 years ago

Yes. My PR works to resolve this issue and those I've mentioned in it. I think they'll be closed once the PR is merged.