Search code examples
linear-programmingcplexinteger-programmingopl

How to avoid scheduling conflicts for a timetable problem


I'm trying to create a schedule for shifts for each employee given employee shift availability. I have a tuple defined to include shift start time, shift end time, max people on shift. The input also includes a list of arrays for employee shift preferences, For example [[1 0 0 1 1],...] which represents that employee 1 is available for shifts 1, 4, 5 but not 2, 3. Note that shift times are not mutually exclusive and can overlap.

I have a decision variable x[i,j] which is 1 if employee i is staffed for shift j, 0 otherwise. After I execute, I'm expecting x[i,j] to be a matrix indicating for each employee which shift they are assigned to. I have my other constraints including shift capacity. But I'm stuck on how to create the constraint to make sure that assigned shifts are not overlapping.

One idea I have is to do compare x[i,j] and x[i,k] where j =/= k and see if they checking if start time of i > end time of j OR start time of j > end time of i. But I'm not sure how to implement this in OPL.


Solution

  • If I understand correctly, the start and end time of each shift j are known constants. Let me call them start[j] and end[j]. So you should be able to use these to specify, using the forall construct, the pairs (j,k) such that the shifts j and k don't overlap.

    You will find examples of using forall in the examples installed with the product in the sub-directories of [InstallDir]/opl/examples/opl. More specifically, models that include constructs that you can look at are models/Staffing/staffing.mod, timetabling/timetabling.mod, and teambuilding/teambuilding.mod.