當前位置: 首頁>>代碼示例>>Python>>正文


Python PriorityQueue.put方法代碼示例

本文整理匯總了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
開發者ID:UMBC-AI,項目名稱:AIProject1,代碼行數:21,代碼來源:graph.py

示例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()
開發者ID:krohan100,項目名稱:pydssim,代碼行數:38,代碼來源:simdd.py


注:本文中的priorityQueue.PriorityQueue.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。