确定飞机到达python之间的等待时间



我正在写一个程序,它需要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])

我之所以需要等待时间,是为了论证这个模拟机场建造另一条跑道是否合理。在这个项目中,我不在乎其他飞机从跑道上起飞。

这是一个单服务器排队系统,其中服务器是跑道。像这样的通用离散事件系统可以使用事件调度进行编程,基于优先级队列来确定下一步会发生什么。您可以在这个github存储库中阅读PDF文件,进行相当完整的讨论。

然而,单个服务器队列具有纯顺序逻辑,可以使用以下递归关系实现为循环:

  • 到达时间i←arrival_timei-1+到达时间i
  • start_landing_timei←max(arrival_timei,finish_landing_timei-1(
  • finish_landing_timei←start_landing_timei

换句话说,从飞机的角度来看

  1. 在最后一架飞机到达后,您有一个到达事件interarrival_time时间单位(这是您的泊松过程(
  2. 您可以在抵达时或前一架飞机完成降落时(以较晚者为准(开始降落程序;以及
  3. 着陆实际上是在您开始着陆后以CCD_ 2时间单位完成的

您可以将假想的第零架飞机的arrival_timefinish_landing初始化为0.0,将上面列出的逻辑放入循环中,并迭代指定数量的飞机或直到达到停止时间。由于逻辑是纯顺序的,因此可以丢失索引,只回收变量。在伪代码中,假设interarrival_time()landing_time()是迭代器,它们会根据需要生成相应的下一个值:

N = 200    # number of airplanes
arrival_time = finish_landing = 0.0
N times:
arrival_time += interarrival_time()
start_landing = max(arrival_time, finish_landing)
finish_landing = start_landing + landing_time()

如果你对飞机花了多长时间感兴趣,那么飞机的延误是CCD_;在行"中;,或者CCD_ 8,如果你想知道飞机有多长";在系统中";。将相应的语句放在循环中的适当位置,并使用您认为合适的结果数据。

最新更新