Question: First, let's create our own ` Frontier _ PQ ` class to represent the frontier ( priority queue ) for uniform - cost search. Note
First, let's create our own FrontierPQ class to represent the frontier priority queue for uniformcost search. Note that the heapq package is imported in the helpers at the bottom of this notebook; you may find that package useful. You could also use the Queue package. Your implementation of the uniformcost search frontier should adhere to these specifications:
Instantiation arguments:
FrontierPQstart cost
start is the initial state egstart'chi'
cost is the initial path cost what should it be for the initial state?
Instantiation attributesmethods:
states: maintains a dictionary of states on the frontier, along with the minimum path cost to arrive at them
q: a list of cost state tuples, representing the elements on the frontier; should be treated as a priority queue in contrast to the states dictionary, which is meant to keep track of the lowestcost to each state
appropriately initialize the starting state and cost
Methods to implement:
addstate cost: add the cost state tuple to the frontier
pop: return the lowestcost cost state tuple, and pop it off the frontier
replacestate cost: if you find a lowercost path to a state that's already on the frontier, it should be replaced using this method.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
