本文整理汇总了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;