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