我正在编写一个程序,需要 200 架飞机在 12 小时内以泊松分布分布,这些飞机需要降落在只有 1 条跑道的机场。我使用指数分布的反向 CDF 方法来确定到达间隔时间。但是,我似乎无法计算在空中的等待时间。
例如,一架飞机在 100 秒到达,需要 75 秒降落,并在 175 秒完成。飞机 2 到达 150 秒,必须等待 175-150 = 25 秒。如何编程我的函数可以输出的变量,考虑到等待时间也可以是 0 秒?
import math
import random
import numpy as np
def variable(amount_of_planes):
plane_number = []
time_between_planes = []
plane_arrival_time = []
plane_arrival = 0
time_for_landing = np.array(random.choices([15, 45, 75, 105, 135, 165, 195, 225, 255, 285], weights=[0, 8, 16.5, 30.5, 20.5, 12.5, 5, 4, 3, 0], k=amount_of_planes))
waiting_time = []
for i in range(amount_of_planes):
plane_number.append(i)
waiting_time.append(i)
#Take a random value from a uniform spread probability from 0 to 1
n = random.random()
#Generate time between plane arrivals by using the reverse cdf method
time_between_planes = -math.log(1.0 - n) / 0.00462962962
plane_arrival_time.append(time_between_planes)
#Add the inter-event time to the running sum to get the next absolute event time
plane_arrival = plane_arrival + time_between_planes
plane_arrival_time.append(plane_arrival)
#My attemt at determining waiting time
done_with_landing = 0
if done_with_landing > plane_arrival:
plane_waiting_time = done_with_landing - plane_arrival
else:
plane_waiting_time = 0
done_with_landing = plane_arrival + plane_waiting_time + time_for_landing[i]
print(plane_arrival, done_with_landing, abs(plane_waiting_time), time_for_landing[i])
我需要等待时间的原因是争论这个模拟机场建造另一条跑道是否有意义。在这个项目中,我不关心从跑道起飞的其他飞机。