本文整理汇总了Python中PriorityQueue.PriorityQueue.deQueue方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.deQueue方法的具体用法?Python PriorityQueue.deQueue怎么用?Python PriorityQueue.deQueue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.deQueue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: primsAlgorithm
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
def primsAlgorithm(graph, start, surface):
for v in graph:
v.setStatus(0)
v.setParent(None)
pq = PriorityQueue()
#heapq.heappush(pq, (0, start))
pq.enQueue((0, start))
while (not pq.isEmpty()):
current = pq.deQueue()[1]
current.setStatus(2)
if(current.getParent() != None):
graph.drawEdge(current.getParent(), current, surface, "yellow")
time.sleep(0.5)
#print(str(current.getParent().getId()) + "->" + str(current.getId()))
for neighbour in current.getNeighbours():
if (neighbour.getStatus() == 0):
neighbour.setStatus(1)
neighbour.setParent(current)
neighbour.setpqWeight(current.neighbours[neighbour])
#print(str(neighbour.getpqWeight()))
pq.enQueue((neighbour.getpqWeight(), neighbour))
elif (neighbour.getStatus() == 1):
if (neighbour.getpqWeight() > current.neighbours[neighbour]):
old = (neighbour.getpqWeight(), neighbour)
neighbour.setpqWeight(current.neighbours[neighbour])
pq.updatePriority(old, (neighbour.getpqWeight(), neighbour))
neighbour.setParent(current)
"""
示例2: prims
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
def prims(self, graph, start, canvas):
for v in graph:
v.setStatus(0)
v.setParent(None)
pq = PriorityQueue()
pq.enQueue((0, start))
while (not pq.isEmpty()):
current = pq.deQueue()[1]
current.setStatus(2)
if(current.getParent() != None):
graph.drawEdge(current.getParent(), current, canvas, "yellow")
canvas.update()
time.sleep(0.5)
for neighbour in current.getNeighbours():
if (neighbour.getStatus() == 0):
# Encountered a new vertex
neighbour.setStatus(1)
neighbour.setParent(current)
neighbour.setpqWeight(current.neighbours[neighbour])
pq.enQueue((neighbour.getpqWeight(), neighbour))
elif (neighbour.getStatus() == 1):
if (neighbour.getpqWeight() > current.neighbours[neighbour]):
# Found smaller weight, update accordingly
old = (neighbour.getpqWeight(), neighbour)
neighbour.setpqWeight(current.neighbours[neighbour])
pq.updatePriority(old, (neighbour.getpqWeight(), neighbour))
neighbour.setParent(current)
示例3: dijkstrasAlgorithm
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
def dijkstrasAlgorithm(graph, start):
for v in graph:
v.setStatus(0)
#start.setStatus(2)
start.setDistance(0)
pq = PriorityQueue()
#heapq.heappush(pq, (0, start))
pq.enQueue((0, start))
while (not pq.isEmpty()):
current = pq.deQueue()[1]
current.setStatus(2)
#if(current.getParent() != None):
# print(str(current.getParent().getId()) + "->" + str(current.getId()))
for neighbour in current.getNeighbours():
if (neighbour.getStatus() == 0):
neighbour.setStatus(1)
neighbour.setParent(current)
neighbour.setpqWeight(current.neighbours[neighbour])
neighbour.setDistance(current.getDistance() + current.neighbours[neighbour])
pq.enQueue((neighbour.getpqWeight(), neighbour))
elif (neighbour.getStatus() == 1):
if (neighbour.getDistance()) > (current.getDistance() + current.neighbours[neighbour]):
#old = (neighbour.getpqWeight(), neighbour)
#neighbour.setpqWeight(current.neighbours[neighbour])
#pq.updatePriority(old, (neighbour.getpqWeight(), neighbour))
neighbour.setParent(current)
neighbour.setDistance(current.getDistance() + current.neighbours[neighbour])
示例4: dijkstrasAlgorithm
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
def dijkstrasAlgorithm(graph, start, surface):
pq = PriorityQueue()
for v in graph:
v.setStatus(0)
v.setDistance(float("inf"))
#print((v.getDistance(), v))
pq.enQueue((v.getDistance(), v))
#start.setStatus(2)
start.setDistance(0)
pq.updatePriority((float("inf"), start), (0, start))
#heapq.heappush(pq, (0, start))
#pq.enQueue((0, start))
#while (not pq.isEmpty()):
for i in range(0, graph.order):
current = pq.deQueue()[1]
current.setStatus(2)
if(current.getParent() != None):
graph.drawEdge(current.getParent(), current, surface, "blue")
time.sleep(0.5)
#if(current.getParent() != None):
# print(str(current.getParent().getId()) + "->" + str(current.getId()))
for neighbour in current.getNeighbours():
"""
if (neighbour.getStatus() == 0):
neighbour.setStatus(1)
neighbour.setParent(current)
#neighbour.setpqWeight(current.neighbours[neighbour])
neighbour.setDistance(current.getDistance() + current.neighbours[neighbour])
pq.enQueue((neighbour.getDistance(), neighbour))
"""
#elif (neighbour.getStatus() == 1):
if (neighbour.getDistance()) > (current.getDistance() + current.neighbours[neighbour]):
old = (neighbour.getDistance(), neighbour)
#neighbour.setpqWeight(current.neighbours[neighbour])
#pq.updatePriority(old, (neighbour.getpqWeight(), neighbour))
neighbour.setParent(current)
neighbour.setDistance(current.getDistance() + current.neighbours[neighbour])
pq.updatePriority(old, (neighbour.getDistance(), neighbour))
"""
示例5: dijkstras
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
def dijkstras(self, graph, start, canvas):
pq = PriorityQueue()
for v in graph:
v.setStatus(0)
v.setDistance(float("inf"))
pq.enQueue((v.getDistance(), v))
start.setDistance(0)
pq.updatePriority((float("inf"), start), (0, start))
for i in range(0, graph.order):
current = pq.deQueue()[1]
current.setStatus(2)
if(current.getParent() != None):
graph.drawEdge(current.getParent(), current, canvas, "blue")
canvas.update()
time.sleep(0.5)
for neighbour in current.getNeighbours():
if (neighbour.getDistance()) > (current.getDistance() + current.neighbours[neighbour]):
# Found smaller weight, update accordingly.
old = (neighbour.getDistance(), neighbour)
neighbour.setParent(current)
neighbour.setDistance(current.getDistance() + current.neighbours[neighbour])
pq.updatePriority(old, (neighbour.getDistance(), neighbour))
示例6: PriorityQueue
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import deQueue [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PriorityQueue import PriorityQueue
s = PriorityQueue()
s.enQueue(2,1)
s.enQueue(3,1)
s.enQueue("sxw1",3)
s.enQueue("sxw2",3)
s.enQueue("sxw3",3)
s.enQueue("sxw4",3)
s.enQueue(1.14,2)
s.enQueue(2.14,2)
s.enQueue(3.14,2)
s.enQueue(4.14,2)
while not s.isEmpty():
item = s.deQueue()
print("length:", len(s),"value:", item.value)