So im trying to code the following model from the paper in JuMP to determine optimal number of staff for 3 shifts daily for 7 days a week where staff must work atleast 1 shift per day
This is the code:
using JuMP
using HiGHS
Wjk = [
19 16 22 22 22 22 22
19 16 22 22 22 22 22
14 11 16 16 16 16 16
]
J, K = size(Wjk)
Ajk = 8
N = 100 #Upper limit
model = Model(HiGHS.Optimizer)
@variable(model, x[1:N, 1:J, 1:K], Bin)
@variable(model, y[1:N], Bin)
@objective(model, Min, sum(x))
@constraint(model, [i in 1:N], sum(x[i, :, :]) <= J * K * y[i]) # y[i] is 1 if employee i is used
@constraint(model, [i in 2:N], y[i-1] >= y[i]) # Ordering on y[i]. If we don't use y[i-1], then we can't use y[i]
@constraint(model, [i in 1:N, k in 1:K], x[i,1,k] + x[i,2,k] + x[i,3,k] <= 2) # Constraint (8)
@constraint(model, [i in 1:N, k in 1:K], x[i,2,k] + x[i,3,k] + x[i,1,k%7+1] <= 2) # Constraint (9)
@constraint(model, [i in 1:N, k in 1:K], x[i,3,k] + x[i,1,k%7+1] + x[i,2,k%7+1] <= 2) # Constraint (10)
@constraint(model, [j in 1:J, k in 1:K], sum(x[:,j,k]) >= Wjk[j,k]) # Constraint (11)
@constraint(model, [j in 1:J, k in 1:K], sum(x[:,j,k]) <= Wjk[j,k] + Ajk) # Constraint (12)
@constraint(model, [i in 1:N], sum(x[i,j,(i-1)%7+1] + x[i,j,i%7+1] for j in 1:J) == 0) # Constraint (13)
@constraint(model, [i in 1:N, k in 1:5], sum(x[i,j,(i+k)%7+1] for j in 1:J) >= y[i]) # Constraint (14)
optimize!(model)
status = termination_status(m)
println("Solution status: ", status)
println("Number of Employees: ", N)
println("Optimal Shift Allocation:")
for i in 1:N, j in 1:J, k in 1:K
if value(x[i, j, k]) > 0.5
println("Employee $i, Shift $j on Day $k")
end
end
Although its producing results, the model is infeasible and the number of employees is always the upper limit of 100