本文整理汇总了Python中PriorityQueue.PriorityQueue.get_priority方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.get_priority方法的具体用法?Python PriorityQueue.get_priority怎么用?Python PriorityQueue.get_priority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.get_priority方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replan
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import get_priority [as 别名]
def replan(self, location, heading):
"""
:type location: Position
:param location: The current location of the robot
:type heading: Direction
:param heading: The current direction the robot is pointing
"""
open_nodes = PriorityQueue(lifo=False)
closed_nodes = set()
came_from = {} # The key is the end state, the value is a tuple of g, move, and start state
initial_state = (location, heading)
g = 0
h = self.heuristic.get_value(initial_state)
f = g + h
open_nodes.insert(f, initial_state)
came_from[initial_state] = (g, None, None)
current_state = initial_state
while len(open_nodes) > 0:
while current_state in closed_nodes:
current_state = open_nodes.pop_min()
closed_nodes.add(current_state)
if self.heuristic.get_value(current_state) == 0:
pol = self.create_policy(current_state, initial_state, came_from)
return self.policy
moves = self.get_possible_moves(current_state)
for move in moves:
new_state = self.get_move_result(current_state, move)
if new_state in closed_nodes:
continue
g = came_from[current_state][0] + self.get_cost(move)
h = self.heuristic.get_value(new_state)
f = g + h
if new_state not in open_nodes:
open_nodes.insert(f, new_state)
elif new_state in came_from and f >= open_nodes.get_priority(new_state):
continue
came_from[new_state] = (g, move, current_state)
open_nodes.update_priority(new_state,f)
return "No path to goal!"