You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the problem of 2 shops, the requirements per day per shop, N drivers and 7 days of week. My constraints are 1) a driver cannot work more than 6 days, i.e. 1 day-off ii) day requirement of drivers per shop must be satisfied and iii) a driver that has been allocated to work for shop 1 on day 1 cannot be allocated to work for shop 2 on day 2. I think that I have tackled constraints i and ii but I can't find a way to implement solution iii. Here's my code. Any help would be highly appreciated.
import numpy as np
import pulp
import pandas as pd
day_requirement = [[2, 5, 4, 2, 5, 3, 4], [5, 4, 2, 5, 3, 4, 2]]
# N = max(day_requirement) # The number of drivers
N = 15
D = 7 # The number of days in week
H = 2
var = pulp.LpVariable.dicts('VAR', (range(H), range(N), range(D)), 0, 1, 'Binary')
problem = pulp.LpProblem('shift', pulp.LpMinimize)
obj = None
for h in range(H):
for i in range(N):
obj += pulp.lpSum(var[h][i][j] for j in range(D))
problem += obj
# schedule must satisfy daily requirements
for j in range(D):
for h in range(H):
c = None
for i in range(N):
c += var[h][i][j]
problem += c == day_requirement[h][j]
# cannot work more than 6 days
for d in range(N):
for h in range(H):
problem += pulp.lpSum([var[h][d][j] for j in range(D)]) <= 6
print(problem)
# Solve problem.
status = problem.solve()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have the problem of 2 shops, the requirements per day per shop, N drivers and 7 days of week. My constraints are 1) a driver cannot work more than 6 days, i.e. 1 day-off ii) day requirement of drivers per shop must be satisfied and iii) a driver that has been allocated to work for shop 1 on day 1 cannot be allocated to work for shop 2 on day 2. I think that I have tackled constraints i and ii but I can't find a way to implement solution iii. Here's my code. Any help would be highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions