當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。