我是 ORTools 的新手,并尝试使用 ORTools 为涉及多个班次和工作中心的员工调度问题实施算法,
https://notebook.community/google/or-tools/examples/notebook/sat/schedule_requests_sat ,
https://github.com/google/or-tools/blob/master/examples/python/shift_scheduling_sat.py ,
等等......对于给定的工作中心,需要在给定轮班期间对员工的需求(例如:3名员工上班,2名员工上下午班和1名员工上晚班。目标是分配选择员工轮班和工作中心。我在下面为 40 名员工、10 个工作中心和一个月做了类似的事情,但解决方案以一些员工 42 小时和其他 7 小时结束......
shift = {}
for n in all_nurses:
for s in all_shifts: # range(num_shifts):
for d in all_days:
for l in all_sites:
shift[(n, s, d, l)] = model.NewBoolVar(
'shift_n%is%id%il%i' % (n, s, d, l))
每位护士每天最多工作一班。
for n in all_nurses:
for d in all_days:
model.Add(sum(shift[(n, s, d, l)]
for s in range(num_shifts) for l in all_sites) <= 1)
每位护士每周工作 5 天
for n in all_nurses:
week = []
for l in all_sites:
for s in all_shifts:
for d in all_days:
week.append(shift[(n, s, d, l)])
# week.append(sum(shifts[(n,d,s)] for s in all_shifts))
# print(week)
model.Add(sum(week) == 5)
站点 l 轮班 s 中第 d 天的护士人数应小于或等于 week_cover_demands[l][d][s]
for l in all_sites:
for d in all_days:
for s in range(num_shifts):
model.Add(sum(shift[(n, s, d, l)]
for n in all_nurses) <= weekly_cover_demands[l][d][s])
model.Maximize(
sum(shift[(n, s, d, l)]
for l in all_sites for d in all_days for n in all_nurses for s in range(num_shifts)))