No consecutive Day/Night shifts
AnsweredIm working off of example "workforce5" in python and was wondering if there was a constaint that could be added to make it so that workers can't do consecutive shifts. This is because our model has day/ night shifts and the workers shouldnt work a day after a night or vice versa.
Any help would be appreciated :)
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi James,
Let us define the set \(S\), \(S = \{(s_i, s_j) | s_i ~\mbox{and} ~s_j ~ \mbox{are consecutive shifts}\}\), containing tuples of consecutive shifts. Given \(x_{ws}\) is a binary decision variable being equal to 1 if worker \(w\) is assigned to shift \(s\), the constraint below ensures worker \(w\) cannot be assigned to consecutive shifts .
\[x_{ws_i} + x_{ws_j} \leq 1, ~~ (s_i, s_j) \in S, ~ w \in W\]
The code snippet below shows how to implement this constraint in workforce5.py example.
consecutiveShifts = [
("Mon1", "Mon8"),
("Mon8", "Tue2"),
("Tue2", "Tue9"),
("Tue9", "Wed3"),
("Wed3", "Wed10"),
("Wed10", "Thu4"),
("Thu4", "Thu11"),
("Thu11", "Fri5"),
("Fri5", "Fri12"),
("Fri12", "Sat6"),
("Sat6", "Sat13"),
("Sat13", "Sun7"),
("Sun7", "Sun14"),
("Sun14", "Mon1"),
]
# Constraint: each worker is not assigned to consecutive shifts
model.addConstrs(
(x[w, s1] + x[w, s2] <= 1 for s1, s2 in consecutiveShifts for w in Workers),
name="noConsecutiveShifts",
)Best regards,
Maliheh
1 -
Thankyou very much, I didnt think of that :D
0
Post is closed for comments.
Comments
3 comments