當前位置: 首頁>>代碼示例>>Python>>正文


Python PriorityQueue.pop_min方法代碼示例

本文整理匯總了Python中PriorityQueue.PriorityQueue.pop_min方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityQueue.pop_min方法的具體用法?Python PriorityQueue.pop_min怎麽用?Python PriorityQueue.pop_min使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PriorityQueue.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.pop_min方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: replan

# 需要導入模塊: from PriorityQueue import PriorityQueue [as 別名]
# 或者: from PriorityQueue.PriorityQueue import pop_min [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!"
開發者ID:davidmchris,項目名稱:machine-learning,代碼行數:46,代碼來源:AStarPlanner.py


注:本文中的PriorityQueue.PriorityQueue.pop_min方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。