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


Python PriorityDict.append方法代碼示例

本文整理匯總了Python中prioritydict.PriorityDict.append方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityDict.append方法的具體用法?Python PriorityDict.append怎麽用?Python PriorityDict.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在prioritydict.PriorityDict的用法示例。


在下文中一共展示了PriorityDict.append方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calculate_shortest_paths_from

# 需要導入模塊: from prioritydict import PriorityDict [as 別名]
# 或者: from prioritydict.PriorityDict import append [as 別名]
    def calculate_shortest_paths_from(self, source_id):
        distance = {}
        previous = {}
        q = None
        if self.use_priority_queue:
            q = PriorityDict()
        else:
            q = []
        ind = []
        distance[source_id] = 0
        for x in self.nodes:
            if x is not source_id:
                distance[x] = float("inf")
                previous[x] = None
            if self.use_priority_queue:
                q[x] = distance[x]
            else:
                q.append(x)

        while len(q):
            u = None
            if self.use_priority_queue:
                u = q.pop_smallest()
            else:
                u = self.get_node_with_minimum_distance(q, distance, ind)
                index = ind.pop()
                if type(index) is int:
                    del q[index]
                else:
                    break

            if isinstance(self.edges[u], dict):
                for v in self.edges[u]:
                    if v in q:
                        alt = distance[u] + self.edges[u][v].strength
                        if alt < distance[v]:
                            distance[v] = alt
                            previous[v] = u
                            if self.use_priority_queue:
                                q[v] = distance[v]
        if not self.num_threads:
            self.shortest_paths[source_id] = distance
            self.shortest_paths_guide[source_id] = previous
        else:
            self.lock.acquire()
            self.shortest_paths[source_id] = distance
            self.shortest_paths_guide[source_id] = previous
            self.lock.release()
        return
開發者ID:sushanttripathy,項目名稱:graphene,代碼行數:51,代碼來源:dijkstra.py


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