I have n tasks to be scheduled in a given period. 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? [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].
0
votes
1 Answers
0
votes
It should be very easy to model and solve with 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):
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
- OST: the optimum (ideal) start time of observation tasks
- LET: the latest end time of observation tasks
- D: the duration of observation tasks
- W: the temporal weight of observation tasks (weight for the distance to the optimum start time if the observation is scheduled)
- P: the penalty for not executing the observation tasks
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)