I'm having difficulty implementing UCS in python. I don't know where I get missed the code.
def UCS(N, w, start, goal):
visited = []
frontier = [(0, start)]
explored = set()
while frontier:
cost, node = heapq.heappop(frontier)
visited.append(node)
if node == goal:
return visited
if node not in explored:
explored.add(node)
for neighbor in N[node]:
new_cost = cost + w[(node, neighbor)]
heapq.heappush(frontier, (new_cost, neighbor))
Expected output: s d e p b c e h r q a a h r p q f p q f q c g
My output : s d e p b c e h q r a a f p q c g