Looks like this modification to PriorityQueue.contains() method makes the Best First Search original implementation fails with the frontier management. The queue will not work as expected by BFS algorithm and the frontier will grow in size every time a repeated situation/state is found.
In class PriotityQueue
|
def __contains__(self, item): |
|
"""Return True if item in PriorityQueue.""" |
|
return (self.f(item), item) in self.heap |
Inside best_first_graph_search method (lines 276 and 278).
|
for child in node.expand(problem): |
|
if child.state not in explored and child not in frontier: |
|
frontier.append(child) |
|
elif child in frontier: |
|
incumbent = frontier[child] |
|
if f(child) < f(incumbent): |
|
del frontier[incumbent] |
|
frontier.append(child) |
Looks like this modification to PriorityQueue.contains() method makes the Best First Search original implementation fails with the frontier management. The queue will not work as expected by BFS algorithm and the frontier will grow in size every time a repeated situation/state is found.
In class PriotityQueue
aima-python/utils.py
Lines 726 to 728 in 5889656
Inside best_first_graph_search method (lines 276 and 278).
aima-python/search.py
Lines 275 to 282 in 5889656