This document describes the implementation of a uniform cost search (UCS) algorithm. It includes a flow chart and code to perform UCS on a graph by maintaining a priority queue of nodes and tracking explored nodes with costs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
5 views2 pages
AI Lab4
This document describes the implementation of a uniform cost search (UCS) algorithm. It includes a flow chart and code to perform UCS on a graph by maintaining a priority queue of nodes and tracking explored nodes with costs.
while len(frontier._container) != 0: # print(frontier) # pop node from frontier node = frontier.pop()
# test goal state
if (goal_test(node, goal)): return node_to_path(node)
# if goal not reached, push the ancestors in the priority queue
for successor, cost in graph[node.state]: # check for the explored nodes if successor not in explored: new_cost = explored[node.state] + cost frontier.push(Node(successor, node, new_cost)) explored[successor] = new_cost return None