We now import the AMPL Python Module and other Python libraries.
Helper Functions
We first create a function that helps us to generate an employee availability table based on different work schedules
Generate the availability table and take a look at the table
[[0 0 1 1 1 1 1]
[0 1 0 1 1 1 1]
[0 1 1 0 1 1 1]
[0 1 1 1 0 1 1]
[0 1 1 1 1 0 1]
[0 1 1 1 1 1 0]
[1 0 0 1 1 1 1]
[1 0 1 0 1 1 1]
[1 0 1 1 0 1 1]
[1 0 1 1 1 0 1]
[1 0 1 1 1 1 0]
[1 1 0 0 1 1 1]
[1 1 0 1 0 1 1]
[1 1 0 1 1 0 1]
[1 1 0 1 1 1 0]
[1 1 1 0 0 1 1]
[1 1 1 0 1 0 1]
[1 1 1 0 1 1 0]
[1 1 1 1 0 0 1]
[1 1 1 1 0 1 0]
[1 1 1 1 1 0 0]]
Set up the model and solve
Overwriting employee_sch.mod
Gurobi 11.0.1: Gurobi 11.0.1: optimal solution; objective 246100
10 simplex iterations
1 branching node
Take a look at the results on number of employees on the payroll
___Optimal employees on each shift________
The number of employee on shift 0 is 0
The number of employee on shift 1 is 0
The number of employee on shift 2 is 10
The number of employee on shift 3 is 0
The number of employee on shift 4 is 0
The number of employee on shift 5 is 31
The number of employee on shift 6 is 37
The number of employee on shift 7 is 0
The number of employee on shift 8 is 46
The number of employee on shift 9 is 0
The number of employee on shift 10 is 1
The number of employee on shift 11 is 0
The number of employee on shift 12 is 23
The number of employee on shift 13 is 0
The number of employee on shift 14 is 0
The number of employee on shift 15 is 0
The number of employee on shift 16 is 0
The number of employee on shift 17 is 17
The number of employee on shift 18 is 0
The number of employee on shift 19 is 0
The number of employee on shift 20 is 53
The total number of emploee is 218
Take a look at the staffing coverage for each day of the week.
____Actual coverage on each day_____
The number of employee on shift 0 is 177 where demand is 177
The number of employee on shift 1 is 134 where demand is 134
The number of employee on shift 2 is 158 where demand is 158
The number of employee on shift 3 is 191 where demand is 191
The number of employee on shift 4 is 149 where demand is 149
The number of employee on shift 5 is 165 where demand is 165
The number of employee on shift 6 is 116 where demand is 116
###A variant of the model where employees must take two consequtive days off.
The mathematical model remains identical, where the only change is the availability table: instead of C(7,2)=21 rows, we now only have C(7,1)=7 rows. See below for details. Thus, there is no need to setup a separate mathematical model.
First compute the availability table.
Generate the availability table and take a look.
[[0 0 1 1 1 1 1]
[1 0 0 1 1 1 1]
[1 1 0 0 1 1 1]
[1 1 1 0 0 1 1]
[1 1 1 1 0 0 1]
[1 1 1 1 1 0 0]
[0 1 1 1 1 1 0]]
Setup the model
HiGHS 1.7.0: HiGHS 1.7.0: optimal solution; objective 259100
8 simplex iterations
1 branching nodes
Take a look at the number of employees hired.
___Optimal employees on each shift________
The number of employee on shift 0 is 3
The number of employee on shift 1 is 73
The number of employee on shift 2 is 0
The number of employee on shift 3 is 40
The number of employee on shift 4 is 0
The number of employee on shift 5 is 66
The number of employee on shift 6 is 49
The total number of emploee is 231
Take a look at the actual coverage.
____Actual coverage on each day_____
The number of employee on shift 0 is 179 where demand is 177
The number of employee on shift 1 is 155 where demand is 134
The number of employee on shift 2 is 158 where demand is 158
The number of employee on shift 3 is 191 where demand is 191
The number of employee on shift 4 is 191 where demand is 149
The number of employee on shift 5 is 165 where demand is 165
The number of employee on shift 6 is 116 where demand is 116
As we can see, when the employee schedules are less flexible (two consequtive days off), the company needs to hire more people to satisfy daily demand. This is consistent with the theoretical predication: when more constraints are imposed, the objective can only get worse.