模拟:T tim中的N个任务

2024-06-17 10:32:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在建立一个模拟器,在一个在线任务调度系统的任务间到达。 我必须在一段时间内运行模拟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。在

  • 据我所说,这两个都是不正确的,我们需要知道在每个时间实例生成的平均任务。我们如何确定?(有点相关的问题:Problems Simulating Interarrival Times
  • 我错过了什么大事吗?我对仿真和建模这一领域还不太熟悉。在
  • 如何实现目标?在

附加问题:

  • 我被要求为上述过程绘制直方图,这是否意味着我记录到达时间并绘制直方图?在

Tags: theto实例in数量hereis时间
1条回答
网友
1楼 · 发布于 2024-06-17 10:32:19

如果这应该是一个泊松过程,条件是特定数量的到达,最简单的方法是生成80000个值,每个值从0均匀分布到27000个,然后对值进行排序。排序后的集合是事件时间,如果您愿意,它们之间的差异是事件间时间。在

相关问题 更多 >