本文整理汇总了Python中priorityQueue.PriorityQueue.remove_task方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.remove_task方法的具体用法?Python PriorityQueue.remove_task怎么用?Python PriorityQueue.remove_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类priorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.remove_task方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bipartite
# 需要导入模块: from priorityQueue import PriorityQueue [as 别名]
# 或者: from priorityQueue.PriorityQueue import remove_task [as 别名]
def bipartite(w, discrepancy):
Ebp_edges = []
Q = PriorityQueue()
incident_edges = dict()
for e in w:
Q.add_task(e, -w[e])
incident_edges.setdefault(e[0], []).append((e[1], w[e]))
incident_edges.setdefault(e[1], []).append((e[0], w[e]))
processed_edges = []
while len(processed_edges) < len(w):
(e, weight) = Q.pop_item()
processed_edges.append(e)
try:
incident_edges[e[0]].remove((e[1], -weight))
incident_edges[e[1]].remove((e[0], -weight))
except ValueError:
pass
Ebp_edges.append(e)
# discard all edges in Q incident to b (i.e. e[1])
for (a, weight) in incident_edges[e[1]]:
try:
Q.remove_task((a,e[1]))
processed_edges.append((a,e[1]))
except KeyError:
pass
try:
incident_edges[a].remove((e[1], weight))
incident_edges[e[1]].remove((a, weight))
except ValueError:
pass
discrepancy[e[0]] += 1
discrepancy[e[1]] += 1
if -1 < discrepancy[e[0]] < .5:
for (x, _) in incident_edges[e[0]]:
try:
Q.remove_task((e[0], x))
except KeyError:
pass
new_weight = abs(discrepancy[e[0]]) + 2*abs(discrepancy[x]) - abs(discrepancy[e[0]]) - 1
if new_weight > 0:
Q.add_task((e[0], x), -new_weight)
else:
processed_edges.append((e[0], x))
elif discrepancy[e[0]] > .5:
for (x, _) in incident_edges[e[0]]:
try:
Q.remove_task((e[0], x))
processed_edges.append((e[0], x))
except KeyError:
pass
return Ebp_edges