当前位置: 首页>>代码示例>>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;未经允许,请勿转载。