我得到了一个实现优先级队列的类,它使用一个函数来计算优先级。在class PriorityQueueWithFunction(PriorityQueue):
"""
Implements a priority queue with the same push/pop signature of the
Queue and the Stack classes. This is designed for drop-in replacement for
those two classes. The caller has to provide a priority function, which
extracts each item's priority.
"""
def __init__(self, priorityFunction):
# type: (object) -> object
"priorityFunction (item) -> priority"
self.priorityFunction = priorityFunction # store the priority function
PriorityQueue.__init__(self) # super-class initializer
def push(self, item):
"Adds an item to the queue with priority from the priority function"
PriorityQueue.push(self, item, self.priorityFunction(item))
我还得到了一个priority函数,我将用它初始化上面的类。在
^{pr2}$
以上代码是给我们的,我们不能更改它。我必须创建PriorityQueueWithFunction类并将元素推送到它。类的push函数接受参数item。但我的优先权函数是2。
我应该使用什么样的参数来将正确的elemnt推送到类中,并且使priorityfunction正常工作?在
这就是我所尝试的,我得到了编译错误,manhattanHeuristic…接受2个参数,1个给定#Creating a queingFn
queuingFn = PriorityQueueWithFunction(heuristic)
Frontier = queuingFn
#Creating the item that needs to be pushed
StartState = problem.getStartState()
StartNode = (StartState,'',0,(-1,-1))
#Here is my problem
item = StartState , problem
Frontier.push(item)
我要改变我的物品的形式吗?有什么想法吗?在