非常新的python并尝试使用我在网上排队时间的简单脚本。当我使用“监视器”时,我收到了一个名称错误 - 我认为这是SimPy的一部分。我还应该从其他地方导入监视器吗?
提前感谢您的帮助!
见下文:
#!/usr/bin/env python
from __future__ import generators
import simpy
from multiprocessing import Queue, Process
from random import Random,expovariate,uniform
# MMC.py simulation of an M/M/c/FCFS/inft/infty queue
# 2004 Dec updated and simplified
# $Revision: 1.1.1.5 $ $Author: kgmuller $ $Date: 2006/02/02 13:35:45 $
"""Simulation of an M/M/c queue
Jobs arrive at random into a c-server queue with
exponential service-time distribution. Simulate to
determine the average number and the average time
in the system.
- c = Number of servers = 3
- rate = Arrival rate = 2.0
- stime = mean service time = 1.0
"""
__version__='\nModel: MMC queue'
class Generator(Process):
""" generates Jobs at random """
def execute(self,maxNumber,rate,stime):
##print "%7.4f %s starts"%(now(), self.name)
for i in range(maxNumber):
L = Job("Job "+`i`)
activate(L,L.execute(stime),delay=0)
yield hold,self,grv.expovariate(rate)
class Job(Process):
""" Jobs request a gatekeeper and hold it for an exponential time """
def execute(self,stime):
global NoInSystem
arrTime=now()
self.trace("Hello World")
NoInSystem +=1
m.accum(NoInSystem)
yield request,self,server
self.trace("At last ")
t = jrv.expovariate(1.0/stime)
msT.tally(t)
yield hold,self,t
yield release,self,server
NoInSystem -=1
m.accum(NoInSystem)
mT.tally(now()-arrTime)
self.trace("Geronimo ")
def trace(self,message):
if TRACING:
print "%7.4f %6s %10s (%2d)"%(now(),self.name,message,NoInSystem)
TRACING = 0
print __version__
c = 3
stime = 1.0
rate = 2.0
print "%2d servers, %6.4f arrival rate,%6.4f mean service time"%(c,rate,stime)
grv = Random(333555) # RV for Source
jrv = Random(777999) # RV for Job
NoInSystem = 0
m=Monitor()
mT=Monitor()
msT=Monitor()
server=Resource(c,name='Gatekeeper')
initialize()
g = Generator('gen')
activate(g,g.execute(maxNumber=10,rate=rate,stime=stime),delay=0)
simulate(until=3000.0)
print "Average number in the system is %6.4f"%(m.timeAverage(),)
print "Average time in the system is %6.4f"%(mT.mean(),)
print "Actual average service-time is %6.4f"%(msT.mean(),)
答案 0 :(得分:0)
您目前正在收到$("input[type='text'][name='Worksheet-Problem']").focus(function(){
$(".button-add").fadeIn(300);
})
$("input[type='text'][name='Worksheet-Problem']").hover(function(){
$(".button-add").fadeIn(300);
})
$("input[type='text'][name='Worksheet-Problem']").mouseout(function(){
$(".button-add").fadeOut(300);
})
$(".button-bullet").hover(function(){
$(this).hide();
$(".button-remove").fadeIn(300);
})
$(".button-remove").mouseout(function(){
$(this).fadeOut(300);
$(".button-bullet").fadeIn(300);
})
,因为您的脚本中目前尚未定义name error
。要使用Monitor
中的Monitor
,您需要将simpy
更改为import simpy
或将from simpy import Monitor
添加到您当前使用的位置simpy.Monitor
函数。
例如:
Monitor
或(第71-73行):
#!/usr/bin/env python
from __future__ import generators
from simpy import Monitor