确定飞机到达之间的等待时间 [英] Determine waiting times between plane arrivals python

查看:29
本文介绍了确定飞机到达之间的等待时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个程序,它需要200架分布在泊松分布的飞机在12个小时内,这些飞机需要降落在一个只有一条跑道的机场。利用指数分布的反向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])

我需要等待时间的原因是为了争论这个模拟机场建造另一条跑道是否有意义。在这个项目中,我不在乎其他飞机从跑道上起飞。

推荐答案

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

但是,单个服务器队列具有纯粹的顺序逻辑,并且可以使用以下递归关系将其实现为循环:

  • 到达时间I←到达时间I-1+到达间隔时间I
  • START_LANDING_TIMEI←MAX(到达时间I,完成着陆时间I-1)
  • 完成着陆时间I←开始着陆时间I+着陆时间I

换句话说,从飞机的角度

  1. 您在最后一架飞机到达后有一个到达事件interarrival_time时间单位(这是您的泊松过程);
  2. 您可以在到达时开始降落程序,也可以在前一架飞机降落完成时开始降落程序,以较晚的时间为准;以及
  3. 着陆在您开始着陆后实际完成landing_time个时间单位。
您可以将虚构的第0架飞机的arrival_timefinish_landing初始化为0.0,将上面概述的逻辑放入循环中,然后迭代指定数量的飞机或直到到达停止时间。因为逻辑是纯顺序的,所以您可以丢弃索引,只循环使用变量。在伪代码中,并假设interarrival_time()landing_time()是按需产生相应NEXT值的迭代器:
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()

如果您对飞机排队等待的时间感兴趣,则start_landing - arrival_time飞机的延迟时间为finish_landing - arrival_time;如果您想要了解飞机在系统中的等待时间,则为finish_landing - arrival_time。将相应的语句放在循环中的适当位置,并以您认为合适的方式使用结果数据。

这篇关于确定飞机到达之间的等待时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆