本文整理匯總了Python中PriorityQueue.PriorityQueue.update_priority方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityQueue.update_priority方法的具體用法?Python PriorityQueue.update_priority怎麽用?Python PriorityQueue.update_priority使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.update_priority方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: replan
# 需要導入模塊: from PriorityQueue import PriorityQueue [as 別名]
# 或者: from PriorityQueue.PriorityQueue import update_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!"