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