Skip to main content

No consecutive Day/Night shifts

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Maliheh Aramon
    • Gurobi Staff

    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
  • James Absolom
    • Gurobi-versary
    • First Question
    • First Comment

    Thankyou very much, I didnt think of that :D

     

    0

Post is closed for comments.