Skip to main content

model for shift scheduling

Answered

Comments

5 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.
  • Riley Clement
    • Gurobi Staff

    Hi niccc,

    Let's say Amy was rostered on shift 0.  This means you want to stop them from being rostered on shift 8, and shift 9 and so on, if I understand correctly?

    If you have a constraint

    x["Amy", 0] + x["Amy", 8] <= 1

    then Amy cannot be assigned to both shift 0 and shift 8.  In general, for each shift i, and each person p you will want the following constraints

    x[p, i] + x[p, j] <= 1, for all j such that j - i > 7

    I don't want to spoil the fun so I will leave this as an exercise for you.

    - Riley

    0
  • niccc
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Riley,

    thank you for your response and you support. 

    Yes, I want to reach exactly this constraint. 

    I changed the reqCts_1 to:

    reqCts_1 = m.addConstrs((x[w,i] + x[w,j] <= 1 for w, i in availability for p, j in availability if int(j) - int(i) > 7), name="__")

    knowing that this is not looking good. 

    I get a KeyError ("Amy", "8") because there is no ("Amy", "8") in availability.

    What did I get wrong? 

     

     

     

     

    0
  • Riley Clement
    • Gurobi Staff

    Hi niccc,

    There is no ("Amy", "8") in availability so we have to make sure we don't try and use this index pair in the formulation.

    Since you're generator expression is going through all keys in the dictionary, and it's a small problem we can just add the condition that w == p (in your current code p isn't doing anything).  This ensures that (w,j) is a key in availability, and hence x[w,j] exists.

    reqCts_1 = m.addConstrs(
    (x[w,i] + x[w,j] <= 1 for w, i in availability for p, j in availability
    if int(j) - int(i) > 7 and w==p),
    name="__",
    )


    - Riley

    0
  • niccc
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Riley,

    thank you, that works for me!

     

     

    0

Post is closed for comments.