• Gurobi Staff

Hi Sai,

It looks like you are missing the non-overlapping shifts constraints for $$i = len(Pt\_Shift\_Times)-1, len(Pt\_Shift\_Times)-2$$ and $$len(Pt\_Shift\_Times) -3$$.

For each $$i \in len(Pt\_Shift\_Times)$$, you can create the set of shifts overlapping with shift $$i$$, say $$overlappint\_shifts[i]$$, and then add the constraint

$\sum_{j \in overlapping\_shifts[i]}work\_pt_{e,d,j} \leq 1 \quad \forall \ e \in Pt\_Employees, d \in days, i \in len(Pt\_Shift\_Times)$

Best regards,
Simran

Hi Simran,

Would the model work with the below objective function? Do we need to change it?
# Objective Function: Minimize total wage coststotal_wages_ft = sum(work_ft[i, day, shift] * FT_HOURLY_WAGE * FT_SHIFT_LENGTH for i in range(FT_EMPLOYEES) for day in DAYS for shift in FT_SHIFT_TIMES)total_wages_pt = sum(work_pt[j, day, shift] * PT_HOURLY_WAGE * PT_SHIFT_LENGTH for j in range(PT_EMPLOYEES) for day in DAYS for shift in PT_SHIFT_TIMES)model.setObjective(total_wages_ft + total_wages_pt, GRB.MINIMIZE)

Or just adding the above mentioned constraint will work?

Thanks and Regards
Sai Arvind Atluri
• Gurobi Staff

Hi Sai,

There is no need to change the objective function. It is just minimizing the total wages paid to the full-time and part-time employees.

Adding the constraint will make sure that a part-time employee is not assigned to overlapping shifts in a day.

Best regards,
Simran

Hi Simran,

I understand that but we're having troubles in meeting the requirements of the part timers.

For the existing code we do not have any overlapping shifts but the requirements are not met. How can we make changes to the existing code so that the part time employee constraint requirements are met?

It's like we have a shifts for part timers assigned as below and during the 7am-3pm there should be 3 part timers working at all times and the same applies for 3pm-11pm. The requirements on each day are mentioned above in the initial question.

PT_SHIFT_TIMES = ["7am-11am", "8am-12pm", "9am-1pm", "10am-2pm", "11am-3pm", "12pm-4pm", "1pm-5pm", "2pm-6pm", "3pm-7pm", "4pm-8pm", "5pm-9pm", "6pm-10pm", "7pm-11pm"]

It would be of great help if you can help me in balancing this particular constraint. If i'm trying to make a change i'm getting infeasible solution.

Thanks and Regards
Sai Arvind Atluri
• Gurobi Staff

Hi Sai,

The overlapping_shifts[i] in my previous comment represented the set of shifts that overlap with the time of shift i. For example,

overlapping_shifts["7am-11am"] will be [ "7am-11am", "8am-12pm", "9am-1pm", "10am-2pm" ],overlapping_shifts["8am-12am"] will be [ "7am-11am", "8am-12pm", "9am-1pm", "10am-2pm", "11am-3pm" ], andoverlapping_shifts["9am-1pm"]  will be [ "7am-11am", "8am-12pm", "9am-1pm", "10am-2pm", "11am-3pm", "12pm-4pm" ]

i.e., in terms of indexes, we will have

overlapping_shifts[0] = [ 0, 1, 2, 3]overlapping_shifts[1] = [ 0, 1, 2, 3, 4 ] overlapping_shifts[2] = [  0, 1, 2, 3, 4, 5 ] and so on...

Please modify your code to construct these sets and add the non-overlapping constraint discussed in the previous comment. I hope this helps!

Best regards,
Simran

Hi Siman,

I have implemented this in the Colab but the daily and hourly requirements of the part-time employees aren't met and that's my main concern. When i'm printing the O/P for part time employees the no. of employees working on Monday from 7am-3pm has to be 3 at all times and that isn't satisfied. This condition has to be satisfied for everyday based on the requirements.

There's no overlap of shifts after implementing the above suggestion but how can i fix the hourly requirements.

Just to give you an idea we have 19 part time employees and each of them will be working in 4hour blocks.

Can you help with it? I hope you're understanding on what I'm trying to explain.

Thanks and Regards
Sai Arvind Atluri
• Gurobi Staff

Hi Sai,

If I understand correctly, your requirement is "for each day and each morning/evening shift, there should be at least PT_REQ_FALL_SPRING[day]["Morning"] / PT_REQ_FALL_SPRING[day]["evening"] part-time employees."

For this, we must create a constraint for each day and shift. Please replace the following constraints in your code:

for day in DAYS:
model.addConstr(sum(work_pt[j, day, shift] for j in range(PT_EMPLOYEES) for shift in PT_SHIFT_TIMES[:6]) >= PT_REQ_FALL_SPRING[day]["Morning"], f"pt_morning_coverage_{day}")
model.addConstr(sum(work_pt[j, day, shift] for j in range(PT_EMPLOYEES) for shift in PT_SHIFT_TIMES[6:]) >= PT_REQ_FALL_SPRING[day]["Evening"], f"pt_evening_coverage_{day}")

with

for day in DAYS:   for shift in PT_SHIFT_TIMES[:6]:      model.addConstr(gp.quicksum(work_pt[j, day, shift] for j in range(PT_EMPLOYEES) ) >= PT_REQ_FALL_SPRING[day]["Morning"], f"pt_morning_coverage_{day}_{shift}")  for shift in PT_SHIFT_TIMES[6:]         model.addConstr(gp.quicksum(work_pt[j, day, shift] for j in range(PT_EMPLOYEES) ) >= PT_REQ_FALL_SPRING[day]["Evening"], f"pt_evening_coverage_{day}_{shift}")

Please change the sense of the above constraints to equality if the requirement is to have exactly PT_REQ_FALL_SPRING[day]["Morning"] or PT_REQ_FALL_SPRING[day]["Evening"] number of constraints working in a shift.

Best regards,
Simran

Hi Simran,

Yes that's correct. 3 part time employees in the morning and 3 in the evening at every hour in a day during the mentioned hours 7am-11pm.

Is there a possibility to connect in a different way? I'm getting a infeasible solution when i try to replace this constraint.

How can we can balance this particular constraint with a feasible solution by taking everything into consideration?

Thanks and Regards
Sai Arvind Atluri
• Gurobi Staff

Hi Sai,

The infeasibility in your model could be due to the input data, i.e. there is no feasible solution possible with the given data, or a bug in the code. To troubleshoot this, I would suggest the following:

• check if you can create a feasible solution for your problem by hand or with a heuristic for the given input data
• export the model in readable form to an LP file, with model.write("model.lp") immediately before calling optimize(). inspect this LP file to see if the model is built as per your expectations.
• run the Model.ComputeIIS() method on the infeasible model. It will let you know the smallest set of variables and constraints that make your model infeasible. Have a look at the article How do I use 'compute IIS' to find a subset of constraints that are causing model infeasibility?

Best regards,
Simran

Hi Simran,

I ran the following and generated the ILP file.

My question might be stupid as I'm still new to working on Optimization models but how can we be troubleshoot from the file generated?

Thanks and Regards
Sai Arvind Atluri
• Gurobi Staff

Hi Sai,

You should be able to open the LP file with any text editor. You can cross-check that the constraints are built as you would have expected logically. This will help to rule out any obvious bugs in the code.

Running the run Model.ComputeIIS() method on the infeasible model will also help to point to the constraints that cause the infeasibility. The article How do I use 'compute IIS' to find a subset of constraints that are causing model infeasibility? has a good example on how to use the computeIIS method.

Best regards,
Simran

Hi Simran,

Yes i did check the LP file just now. However, it looks like the part time constraint isn't working as expected. It's just showing the subject to for the morning and evening coverage from Fri-Sun only and the no. of working hours less than or equal to 20 and bounds isn't set to anything.

Is there a way i can share the file with you so you can have a look? Unfortunately, this is something urgent and we need to fix it right-away.

Thanks and Regards
Sai Arvind Atluri

• Gurobi Staff

Hi Sai,

Now that you have identified the constraints that are not built correctly, please debug the part of your code that builds these constraints.

Best regards,
Simran