I am trying to implement an employee (nurse) scheduling problem and seek some advice on how to implement a specific constraint.The problem is as follows: There is a set of employees and days (both labeled by integer numbers). Each employee can be assigned a day shift D[(i, j)] , nightshift N[(i, j)] or a day off V[(i, j)]. These are my decision variables:
D = LpVariable.dicts(name="Dagdienst", indexs=[(i, j) for i in employees for j in days], cat='Binary')
N = LpVariable.dicts(name="Nachtdienst", indexs=[(i, j) for i in employees for j in days], cat='Binary')
V = LpVariable.dicts(name="Vrij", indexs=[(i, j) for i in employees for j in days], cat='Binary')
An example constraint to enforce either a dayshift, nightshift or day-off for each day and each employee is the following.
for i in employees:
for j in days:
m += D[(i, j)] + N[(i, j)] + V[(i, j)] == 1
To give you some idea what I'm working with, two other constraints are the following:
for i in employees:
for j in range(1, len(days)-1):
m += N[(i, j)] + D[(i, (j + 1))] <= 1
m += N[(i, j)] + D[(i, (j + 2))] <= 1
max_consecutive_days = 4
for i in employees:
for j in range(1, (len(days)+1 - max_consecutive_days)):
m += D[(i, j)] + D[(i, j + 1)] + D[(i, j + 2)] + D[(i, j + 3)]+ D[(i, j + 4)] <= max_consecutive_days
Now I want to model two additional constraints. The first one should be fairly simple I hope. If an employee works on saturday (6th day of the week), he/she must also work on sunday (7th day of the week). The idea is that one either works all weekend, or is free all weekend. I tried the following:
for i in employees:
m += N[(i, 6)] - N[(i, 7)] >= 0
m += N[(i, 7)] - N[(i, 6)] >= 0
But these constraints turn out to be non-binding of course because when N[(i, 6)] = 0
and N[(i, 7)] = 0
the constraints are also satisfied. First question: how do I rewrite these constraints?
Then, on top of that I also want to implement a way to make sure that employees can only work odd or even weekends but don't really know where to start. I assume I must introduce two extra decision variables "works even-weekends" and "works odd-weekends" and set some constraints to enforce these. So the second question is: how could I implement this?
Ideally I'd rather be able to help myself with these kind of questions so reading materials (specific chapters/sections would be nice) are very welcome as well!