本文整理匯總了Python中priorityQueue.PriorityQueue.put方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityQueue.put方法的具體用法?Python PriorityQueue.put怎麽用?Python PriorityQueue.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類priorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.put方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: solveUCS
# 需要導入模塊: from priorityQueue import PriorityQueue [as 別名]
# 或者: from priorityQueue.PriorityQueue import put [as 別名]
def solveUCS(self):
# return ["A","B","C"]
visited = [self.start]
q = PriorityQueue()
if self.start == self.end:
print("Graph already solved! start and end nodes are the same!")
else:
#Build Queue
startNode = self.findNode(self.start)
for child in startNode.children:
print("ADDING",child,"PARENT",startNode.name)
q.put((child,startNode.name,startNode.children[child]))
visited.append(child)
#Recursively solve
path = []
self.rsolveUCS(q,path,visited)
path.append(self.start)
return path
示例2: __init__
# 需要導入模塊: from priorityQueue import PriorityQueue [as 別名]
# 或者: from priorityQueue.PriorityQueue import put [as 別名]
class Sim:
def __init__(self):
self.q = PriorityQueue()
self.time = 100
self.nodes = {}
self.actors = []
self.done = False
def add_actor(self, actor):
actor.sim = self
self.actors.append(actor)
def at(self, event):
if event.time < self.time:
print "ERROR, time warp"
else:
self.q.put(event, event.time)
def process(self):
while not self.q.empty():
event = self.q.get()
self.time = event.time
try:
(result, actor) = event.process(self)
actor.send(result)
except StopIteration:
pass
print "Sim done"
def prime(self):
for a in self.actors:
a.prime()
def go(self):
self.prime()
self.process()