当前位置: 首页>>代码示例>>Python>>正文


Python PriorityQueue.find方法代码示例

本文整理汇总了Python中PriorityQueue.PriorityQueue.find方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.find方法的具体用法?Python PriorityQueue.find怎么用?Python PriorityQueue.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PriorityQueue.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: astarSearch_Q

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import find [as 别名]
    def astarSearch_Q( self, start, goal, cSpace, imgsurface=None ):
        def backtrace( node, pardict ):
            path = []
            path.append( node )
            while( pardict.has_key(str(node))):
                path.append( pardict[str(node)] );
                node = pardict[str(node)];
            path.reverse();
            return path;

        openList = PriorityQueue();
        closedList = PriorityQueue();

        parentDict = defaultdict();
        sphereDict = defaultdict();
        GDict = defaultdict();

        ownerShpere = self.findOwnerSphere( start[0],start[1], cSpace.mScaledWidth, cSpace.mScaledHeight);
        startNode = AstarNode( start[0], start[1], None, ownerShpere );
        start_mF =  self.distance( start, goal, cSpace.mScaledWidth, cSpace.mScaledHeight );
        openList.push( startNode.mPosition,  start_mF );
        sphereDict[str(startNode.mPosition)] = ownerShpere;
        GDict[str(startNode.mPosition)] = 0;

        while( not openList.isEmpty() ):
            current, curr_mF = openList.pop();
            if current == goal:
                return backtrace( current, parentDict );
            if( imgsurface is not None ):
                for event in pygame.event.get():
                    pass;
                pygame.draw.circle( imgsurface, (0,255,0), (int(current[0]), int(current[1])), 2 );
                pygame.display.update();

            #openList.remove_task( current );
            currOwnerSphere = sphereDict[str(current)];
            successors = self.getSphereBoundaries(currOwnerSphere, goal, cSpace.mScaledWidth, cSpace.mScaledHeight);
            closedList.push( current, curr_mF );

            for suc in successors:
                sucSamp = suc[0];
                if( closedList.find( sucSamp ) ):
                    continue;
                sucOwnerSphere = suc[1];
                sucNode = AstarNode( sucSamp[0], sucSamp[1], current, sucOwnerSphere )
                sphereDict[str(sucNode.mPosition)] = sucOwnerSphere;

                #if sucSamp == goal:
                #    parentDict[str(sucNode.mPosition)] = current;
                #    return backtrace( sucSamp, parentDict );
                sucNode.mG = GDict[str(current)] + self.distance( sucSamp, current, cSpace.mScaledWidth, cSpace.mScaledHeight );

                sameOpen = openList.find( sucNode.mPosition );
                if( sameOpen is None or GDict[str(sucNode.mPosition)] > sucNode.mG):
                    parentDict[str(sucNode.mPosition)] = sucNode.mParentNode;
                    GDict[str(sucNode.mPosition)] = sucNode.mG;
                    sucNode_mH = self.distance( sucSamp, goal, cSpace.mScaledWidth, cSpace.mScaledHeight );
                    sucNode_mF = sucNode.mG + sucNode_mH;
                    openList.push( sucNode.mPosition, sucNode_mF );
                pass
            pass
        return None;
开发者ID:IanZhang1990,项目名称:Robotics-MotionPlanning,代码行数:64,代码来源:AstarSearcher.py


注:本文中的PriorityQueue.PriorityQueue.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。