Given https://machinelearninggeek.com/solving-staff-scheduling-problem-using-linear-programming/ this case on scheduling,
- Can someone explain constraints 1, the latter $3$?
- Where on constraints 2 is $x_3$ if $x_2$ is also considered?
I played around with the constraints and got a different answer and am not convinced the prose and example are correct. It's a while since I looked at LP. However, I am pretty sure this example is incorrect.
Staff Scheduling Problem as in the link
In this problem, a saloon owner wants to determine the schedule for staff members. The staff consists of the full-time shift of $9$ hours and part-time shift of $3$ hours. The saloon’s opening hours are divided into $4$ shifts of $3$ hours each. In each shift, different levels of demands are there that need the different number of staff members in each shift.
The required number of nurses for each shift is mentioned in the below table:
Shift Time Period Number of Employees
Morning 09 AM-12 PM 6
Afternoon 12-03 PM 11
Evening 03-06 PM 8
Night 06-09 PM 6
There is at least 1 full-time employee we need in each shift.
The full-time employee will get $150$ dollars for $9$ hours shift and the part-time employee will get $45$ dollars per shift.
The decision variables, objective function, constraints are as follows:
Decision Variables:
$x_I$ = Number of full-time employees scheduled in shift $I$.
$y_I$ = number of part-time employees scheduled in shift $I$.
Objective Function:
$\text{minimize} \; Z= 150( x_0 + x_1 + x_2 + x_3 ) + 45( y_0 + y_1 + y_2 + y_3 )$
Constraints 1:
Employee starting shift constraints
$x_0 + y_0 ≥ 6$
$x_0 + x_1 + y_1 \ge 8$
$x_1 + x_2 + y_2 \ge 11$
$x_2 + x_3 + y_3 \ge 6$
Constraints 2:
Minimum full-time employees during any shift/period
$x_0 \ge 1$
$x_1 \ge 1$
$x_2 \ge 1$
FINISH OF EXAMPLE ON INTERNET
MY SOLUTION BY HAND CALCULATION
Based on comments made by observer, on no-partial shifts for full-timers (although not that that is stated), then I think this is better approach:
# Import all classes of PuLP module
from pulp import *
# Initialize Class
model = LpProblem("StaffSchedulingProblem", LpMinimize)
# Create Shifts
shifts = list(range(4))
# Define Decision Variables
x = LpVariable.dicts('fulltimeshift_', shifts, lowBound=0, cat='Integer')
y = LpVariable.dicts('parttimeshift_', shifts, lowBound=0, cat='Integer')
# Define Objective
model += 150 * lpSum([x[i] for i in shifts]) + 45 * lpSum([y[i] for i in shifts])
# Define Constraints: For Employee starting the shift
model += x[0]+y[0]>=6
model += x[0]+x[1]+y[1]>=11
model += x[0]+x[1]+y[2]>=8
model += x[1]+y[3]>=6
# Define Constraints: At least full-time employee during any shift
model += x[0]>=1
model += x[1]>=1
# The problem is solved using PuLP's choice of Solver
model.solve()
# Print the variables optimized value
for v in model.variables():
print(v.name, "=", v.varValue)
# The optimised objective function value is printed to the screen
print("Total Cost of Staff = ", value(model.objective))
The model vs. hand calc agree.
So I am looking how the proposed example is more correct than my approach - which I believe it is not. I think it misses the overlapping shift aspect of a full-time employee. If so, then this is a poor showing.