Work Scheduling Problem: Post Office Problem

FROM - Operations Research: Applications and Algorithms 4th Edition, p72, Wayne L. Winston

A post office requires different numbers of full-time employees on different days of the week. The number of full-time employees required on each day is given in Table 4. Union rules state that each full-time employee must work five consecutive days and then receive two days off. For example, an employee who works Monday to Friday must be off on Saturday and Sunday. The post office wants to meet its daily requirements using only fulltime employees. Formulate an LP that the post office can use to minimize the number of full-time employees who must be hired.

Day Number of Full-Time Emplyees Requiremed
Mon 17
Tue 13
Wed 15
Thur 19
Fri 14
Sat 16
Sun 11

In [4]:
from gurobipy import *

days = ["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"]


assignment_FTE = [
                [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],
                [0,0,1,1,1,1,1]
            ]

requried_FTE = [17,13,15,19,14,16,11]

# Model
m = Model("post_office_problem")

day_assignment = []
for l in range(len(days)):
    day_assignment.append(
        m.addVar(obj = 1, vtype=GRB.INTEGER, name="(%s)" % (days[l])))

m.modelSense = GRB.MINIMIZE
m.update()


for l in range(len(days)):
    m.addConstr(
        quicksum(assignment_FTE[l][c] * day_assignment[c]for c in range(len(days))) >= requried_FTE[l], 
        "day requirment %s" % days[l])



m.optimize()

for v in m.getVars():
    print (v.varName, v.x)
    

print (m.getObjective().getValue())


Optimize a model with 7 rows, 7 columns and 35 nonzeros
Variable types: 0 continuous, 7 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+01, 2e+01]
Found heuristic solution: objective 35
Presolve time: 0.00s
Presolved: 7 rows, 7 columns, 35 nonzeros
Variable types: 0 continuous, 7 integer (0 binary)

Root relaxation: objective 2.233333e+01, 5 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0   22.33333    0    4   35.00000   22.33333  36.2%     -    0s
H    0     0                      23.0000000   22.33333  2.90%     -    0s

Explored 0 nodes (5 simplex iterations) in 0.02 seconds
Thread count was 8 (of 8 available processors)

Solution count 2: 23 35 
Pool objective bound 23

Optimal solution found (tolerance 1.00e-04)
Best objective 2.300000000000e+01, best bound 2.300000000000e+01, gap 0.0000%
(Mon) 7.0
(Tue) 5.0
(Wed) 1.0
(Thur) 7.0
(Fri) -0.0
(Sat) 3.0
(Sun) -0.0
23.0

In [ ]: