有约束的航班到插槽的分配问题?

问题描述

我无法为到达机场的航班分配舱位(分配问题)。

我有以下信息:

time_slots = ['4:45','5:00','5:15','5:30','5:45','6:00']  

(这表示广告位1:“ 4:45”到“ 4:59”的时间间隔)

Capacity_each_slot = [1,2,1,3] 

(我们可以为每个广告位分配多少航班)

flights_arrivals = ['4:47','5:02','5:10','5:12','5:14','5:33','5:48','5:50','5:58']
Duration_flights = [500,400,1200,350,1000,250,300]`

我已经计算出:

Indices_for_arrivals = [0,3,4,4] 

(表示每个航班属于哪个插槽)`

因此,我需要在容量限制下将每个航班分配到各个广告位。例如,广告位1(4:45)不能乘坐超过一次航班,广告位2(5:00)不能乘坐超过两次航班。.etc。

在上面刚说明的约束下,我设法使用以下代码为每个航班分配了插槽:

def ration_by_schedule(flight_times,capacity,T):
    num_sched_flights = [0 for i in range(T)] # list to keep track of number of flights scheduled in each interval
    new_flight_schedule = [] # list to store new flight times 
    for t in flight_times:
        for s in range(t,T):
             if num_sched_flights[s] < capacity[s]:
                new_flight_schedule.append(s)
                num_sched_flights[s] += 1
                break
        else:
            raise RuntimeError ("Not enough capacity to schedule all flights")
    return new_flight_schedule

schedule = ration_by_schedule(Indices_for_arrivals,Capacity_each_slot,9)
print(schedule)

Output : [0,4]

我的问题是我想向另一个飞行时间超过10小时(Duration_flights> 1000)的航班实施优先级方案的约束。

我想我可以从豁免开始,并首先使用它们的索引将它们分配为:

exempted_flights_indices = [2,6]

在这种情况下,我的结果将是:

new_flight = [0,4]

如何在我的代码中添加持续时间约束?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)