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 `Frontier_PQ` class to represent the frontier (priority queue) for uniform-cost 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 uniform-cost search frontier should adhere to these specifications:
* Instantiation arguments:
***Frontier_PQ(start, cost)**
***start** is the initial state (e.g.,**start**='chi')
***cost** is the initial path cost (what should it be for the initial state?)
* Instantiation attributes/methods:
***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 lowest-cost to each state)
* appropriately initialize the starting state and cost
* Methods to implement:
***add(state, cost)**: add the (cost, state) tuple to the frontier
***pop()**: return the lowest-cost (cost, state) tuple, and pop it off the frontier
***replace(state, cost)**: if you find a lower-cost 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!