本文整理匯總了Python中prioritydict.PriorityDict.pop_smallest方法的典型用法代碼示例。如果您正苦於以下問題:Python PriorityDict.pop_smallest方法的具體用法?Python PriorityDict.pop_smallest怎麽用?Python PriorityDict.pop_smallest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prioritydict.PriorityDict
的用法示例。
在下文中一共展示了PriorityDict.pop_smallest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: calculate_shortest_paths_from
# 需要導入模塊: from prioritydict import PriorityDict [as 別名]
# 或者: from prioritydict.PriorityDict import pop_smallest [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