我正在建立一个模拟器,在一个在线任务调度系统的任务间到达。
我必须在一段时间内运行模拟T
(以节拍数而不是时钟时间来衡量)
我得到了到达T
的任务数量,以及一些到达时间。在
我不知道每个实例有多少任务到达。在
这是我的密码。在
import numpy.random as R
t = 0
T = 2700 # i want to run the simulation for 2700 ticks (assume 1 tick = 1 minute)
N = 8000 # total number of tasks in the system is 8000 (Say)
mean = 5
arrivals = []
nextArrival = 0
arrivals.append(nextArrival)
while t < T:
nextArrival = arrivals[-1] + R.poisson(5)
# a task comes in here and i do some processing
# which is not relevant to the question here
arrivals.append(nextArrival)
t = nextArrival
print len(arrivals)
print "\n", arrivals
输出:(不确定这是否有帮助!)在
^{pr2}$上面打印的列表是任务的到达时间。
现在考虑到每次到达时有一个任务,我可以在2700分钟内生成563
个任务,而需要生成8000个任务。在
另一方面,如果我运行模拟直到生成如下所需数量的任务,则时间大约为40283。在
arrivals = []
nextArrival = 0
taskCount = 0
t = 0
arrivals.append(nextArrival)
while taskCount < N:
nextArrival = arrivals[-1] + R.poisson(5)
arrivals.append(nextArrival)
t = nextArrival
taskCount += 1
print t
$ python main.py
40283
正如我们所看到的,我所面临的(普遍的)问题是:
如果在每个到达时间我考虑一个任务,模拟结果是一些n < N
个任务,这是不正确的。如果我为N
任务运行模拟,时间将超过T
。在
附加问题:
如果这应该是一个泊松过程,条件是特定数量的到达,最简单的方法是生成80000个值,每个值从0均匀分布到27000个,然后对值进行排序。排序后的集合是事件时间,如果您愿意,它们之间的差异是事件间时间。在
相关问题 更多 >
编程相关推荐