简体   繁体   English

优化的加权间隔调度算法

[英]Optimised Weighted Interval Scheduling Algorithms

I have n tasks to be scheduled in a given period. 在给定的时间段内,我要安排n个任务。 Each task has an earliest start time, an optimum start time, a latest end time, a duration, and a priority weighting. 每个任务都有最早的开始时间,最佳的开始时间,最近的结束时间,持续时间和优先权重。 Tasks cannot overlap. 任务不能重叠。 The requirement is to schedule as many tasks as possible, as close as possible to their optimum start times and giving priority to higher weighted tasks where not all tasks can be accommodated. 要求是计划尽可能多的任务,并尽可能接近其最佳开始时间,并优先处理那些不能容纳所有任务的加权较高的任务。 I've read up on interval scheduling and also weighted interval scheduling but I've not come across algorithms that also include the concept of optimum start times. 我已经阅读了间隔调度和加权间隔调度,但是我没有碰到也包含最佳启动时间概念的算法。 Can anyone point me to a Python library that can do this, or a description of a suitable algorithm that I could code myself? 谁能指出我可以执行此操作的Python库,或者说明我可以自己编写的合适算法? [the application is the scheduling of astronomical imaging, with the start and end times being the times when each object rises and sets in the Sky and the optimum time being when the object is at its maximum altitude; [应用程序是天文影像的排程,开始和结束时间是每个物体在天空中升起和落下的时间,最佳时间是在其最大高度时的时间; with the weighting being the priority assigned by the astronomers to each object]. 权重是天文学家分配给每个物体的优先级]。

It should be very easy to model and solve with CP Optimizer ( https://pypi.org/project/docplex/ ). 使用CP Optimizer( https://pypi.org/project/docplex/ )进行建模和求解应该非常容易。 With this tool all you need is to formulate your problem as a combinatorial optimization problem and the automatic search will solve it (and prove optimality of the solution if the instance is not too large). 使用此工具,您所需要做的就是将问题表达为组合优化问题,自动搜索将解决该问题(并在实例不太大的情况下证明解决方案的最优性)。

Here is an example how I would formulate this problem in CP Optimizer (I'm giving a small instance): 这是一个示例,我将如何在CP Optimizer中解决这个问题(我给出一个小实例):

N = range(20)

EST = [166, 157, 118, 254, 213, 73, 100, 38, 113, 84, 43, 257, 74, 246, 73, 242, 207, 223, 242, 122] 
OST = [205, 195, 134, 256, 252, 157, 106, 44, 167, 84, 85, 266, 121, 256, 110, 310, 229, 262, 286, 162] 
LET = [259, 233, 172, 267, 269, 175, 111, 48, 197, 91, 97, 292, 147, 289, 127, 313, 238, 319, 346, 177] 
D = [9, 7, 5, 1, 9, 9, 4, 2, 3, 2, 9, 8, 3, 1, 7, 2, 3, 4, 4, 2] 
W = [0.254, 0.811, 0.479, 0.27, 0.968, 0.036, 0.373, 0.887, 0.855, 0.61, 0.855, 0.708, 0.376, 0.434, 0.834, 0.978, 0.354, 0.4, 0.128, 0.208] 
P = [1.46, 1.47, 9.29, 0.32, 5.43, 5.02, 8.1, 8.35, 7.79, 0.79, 3.86, 4.33, 7.16, 0.86, 5.82, 1.88, 2.16, 0.04, 9.37, 9.36]

# PROBLEM FORMULATION

from docplex.cp.model import *
model = CpoModel()

# Decision variables: x[i] is the ith observation
x = [ interval_var(size=D[i], optional=True) for i in N]

# Cost expression
cost = sum([start_eval(x[i], CpoSegmentedFunction((-W[i],0),[(OST[i],0,W[i])]), P[i]) for i in N])

# Objective: minimize cost
model.add(minimize(cost))

# Constraints
model.add([EST[i] <= start_of(x[i], EST[i])] for i in N)
model.add([end_of(x[i]) <= LET[i]] for i in N)
model.add(no_overlap(x))

# PROBLEM RESOLUTION

sol = model.solve(trace_log=True, LogPeriod=1000000, TimeLimit=30)

# DISPLAY OF SOLUTION

for i in N:
    s = sol.get_var_solution(x[i])
    if s.is_absent():
        print('Task ' + str(i) + ' not scheduled')
    else:
        print('Task ' + str(i) + ' scheduled on [' + str(s.get_start()) + ',' +  str(s.get_end()) + ')')

In the data: 在数据中:

  • EST: the earliest start time of observation tasks EST:最早的观测任务开始时间
  • OST: the optimum (ideal) start time of observation tasks OST:观测任务的最佳(理想)开始时间
  • LET: the latest end time of observation tasks LET:观察任务的最新结束时间
  • D: the duration of observation tasks D:观察任务的持续时间
  • W: the temporal weight of observation tasks (weight for the distance to the optimum start time if the observation is scheduled) W:观测任务的时间权重(如果安排了观测,则为到最佳开始时间的距离的权重)
  • P: the penalty for not executing the observation tasks P:不执行观察任务的罚款

The execution looks like this: 执行如下所示:


 ! ----------------------------------------------------------------------------
 ! Minimization problem - 21 variables, 41 constraints
 ! LogPeriod            = 1000000
 ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
 !  . Log search space  : 83.4 (before), 83.4 (after)
 !  . Memory usage      : 476.1 kB (before), 476.1 kB (after)
 ! Using parallel search with 8 workers.
 ! ----------------------------------------------------------------------------
 !          Best Branches  Non-fixed    W       Branch decision
                        0         21                 -
 + New bound is 0
 ! Using iterative diving.
 ! Using temporal relaxation.
 *      92.86000       21  0.04s        1      (gap is 100.0%)
 *      7.209000      176  0.04s        1      (gap is 100.0%)
 *      7.208000      231  0.04s        1      (gap is 100.0%)
 *      5.831000      284  0.04s        1      (gap is 100.0%)
 *      2.114000      470  0.04s        1      (gap is 100.0%)
        2.114000      470          1    1   F        -
 + New bound is 2.113788 (gap is 0.01%)
 ! ----------------------------------------------------------------------------
 ! Search completed, 5 solutions found.
 ! Best objective         : 2.114000 (optimal - effective tol. is 0.0002114)
 ! Best bound             : 2.113788
 ! ----------------------------------------------------------------------------
 ! Number of branches     : 171602
 ! Number of fails        : 9172
 ! Total memory usage     : 4.3 MB (4.2 MB CP Optimizer + 0.0 MB Concert)
 ! Time spent in solve    : 0.06s (0.06s engine + 0.00s extraction)
 ! Search speed (br. / s) : 2860024.7
 ! ----------------------------------------------------------------------------
Task 0 scheduled on [205,214)
Task 1 scheduled on [195,202)
Task 2 scheduled on [134,139)
Task 3 not scheduled
Task 4 scheduled on [252,261)
Task 5 scheduled on [153,162)
Task 6 scheduled on [106,110)
Task 7 scheduled on [44,46)
Task 8 scheduled on [167,170)
Task 9 not scheduled
Task 10 scheduled on [85,94)
Task 11 scheduled on [266,274)
Task 12 scheduled on [121,124)
Task 13 not scheduled
Task 14 scheduled on [110,117)
Task 15 scheduled on [310,312)
Task 16 scheduled on [229,232)
Task 17 scheduled on [262,266)
Task 18 scheduled on [286,290)
Task 19 scheduled on [162,164)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM