当前位置: 首页>>代码示例>>Python>>正文


Python PriorityQueue.pop方法代码示例

本文整理汇总了Python中priorityQueue.PriorityQueue.pop方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.pop方法的具体用法?Python PriorityQueue.pop怎么用?Python PriorityQueue.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在priorityQueue.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.pop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: color_most_constrained_first

# 需要导入模块: from priorityQueue import PriorityQueue [as 别名]
# 或者: from priorityQueue.PriorityQueue import pop [as 别名]
def color_most_constrained_first(graphs, color):
    global spills, unspillable, num_unused, used_registers

    #print 'starting color_most_constrained_first'
    
    for v in graphs.vertices():
        used_registers[v] = set([])
        num_unused[v] = len(registers) - len(used_registers[v])

    left = set(graphs.vertices()) - set(reserved_registers) - set(registers)
    queue = PriorityQueue(left, avail_reg_then_unspill)

    while not queue.empty():
        v = queue.pop()
        if debug:
            print 'next to color is ' + v
        if v not in color.keys():
            c = choose_color(v, color, graphs,False)
            color[v] = c
            for u in graphs.interferes_with(v):
                #if u in graphs.vertices():
                queue.update(u)
                used_registers[u] |= set([c])
                num_unused[u] = len(registers) - len(used_registers[u])
                
            if not is_reg(c):
                spills += 1

    return color
开发者ID:parthmishra,项目名称:p0,代码行数:31,代码来源:registerAlloc1.py

示例2: xrange

# 需要导入模块: from priorityQueue import PriorityQueue [as 别名]
# 或者: from priorityQueue.PriorityQueue import pop [as 别名]
# Build a list of all possible reversals.
allrevs = [(i,j) for i in xrange(n-1) for j in xrange(i+1, n)]

# The queue is implemented as a list of dictionaries. Each dictionary holds items of
# the same score (0...n-1).
queue = PriorityQueue(n)
queue.insert(initialState)
maxQueueLen = len(queue)

while True:
    l = len(queue)
    if l % 1000 <= 5:
        print l
        
    incumbent = queue.pop()
    if incumbent == None: break
    
    #print "Popping ", incumbent
    if (incumbent[0] >= bestScore):
        #print "Rejecting ", incumbent
        continue

    if isSolution(incumbent):
        print "Found new best: ", incumbent
        bestScore = incumbent[0]
        bestState = incumbent
        continue
    
    for r in breakpointReversals(incumbent[2]) :
        newstate = applyReversal(incumbent, r)
开发者ID:,项目名称:,代码行数:32,代码来源:

示例3: Animation

# 需要导入模块: from priorityQueue import PriorityQueue [as 别名]
# 或者: from priorityQueue.PriorityQueue import pop [as 别名]
class Animation(Iterator):
	def __init__(self, app, length, fps, synchronous):
		self.__app = app
		self.__events = PriorityQueue()
		self.__spf = 1/fps # seconds per frame
		self.__frame = 0
		self.__frameTime = -self.__spf
		self.__length = length
		self.__synchronous = synchronous


	def __dequeue(self):
		# increase frame data
		try:
			time, event = self.__events.pop()
		except IndexError:
			print "No events left."
			raise StopIteration

		if time < self.__frameTime:
			raise Exception("Cannot go back in time: %s requested %s after %s." % (repr(event.__name__), time, self.__frameTime))
		return (time, event)
		
	def __updateQueue(self, event):
		# update the queue
		try:
			t = event.next()
			self.__events.push((self.__sync(t), event))
		except StopIteration:
			pass

	def next(self):
		if self.__frameTime > self.__length:
			print "Reached end time."
			raise StopIteration

		if self.__frameTime == -self.__spf:
			time = 0
			event = iter(())
		else:
			time, event = self.__dequeue()

		if time == self.__frameTime:
			raise Exception("Double Frame: %s requested %s again." % (repr(event.__name__), time))

		self.__frame += 1
		self.__frameTime = time
		self.__updateQueue(event)

		while self.__events and self.__events[0][0] < self.nextTime:
			time, event = self.__dequeue()
			self.__updateQueue(event)


		return (self.__frame, time)

	def __sync(self, time):
		if self.__synchronous:
			return time - (time % self.__spf)
		else:
			return time

	def addEvent(self, eventFn):
		generator = eventFn(self, self.__app.camera, self.__app.canvas)
		time = generator.next()
	
		event = (self.__sync(time), generator)

		self.__events.push(event)

	@property
	def nextTime(self):
		return self.__frameTime + self.__spf

	@property
	def time(self):
		return self.__frameTime
开发者ID:redyeti,项目名称:camela-2.5D,代码行数:79,代码来源:animation.py


注:本文中的priorityQueue.PriorityQueue.pop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。