Google Or-Tools员工排班。条件无法正常工作

2024-02-15

我在用着那个护士调度的例子 https://developers.google.com/optimization/scheduling/employee_scheduling。我有 3 名员工,2 班次,7 天,我有一个条件,如果一名员工在 1 班工作,他/她第二天就不能在 0 班工作。这是我的代码,它不起作用。

    for n in all_nurses:
      for d in all_days:
        model.Add(sum(shifts[(n, d, s)] for s in range(0,1))+sum(shifts[(n, (d+1)%6, s)] for s in range(1,2)) <= 1)

这是output https://i.stack.imgur.com/5G82A.png。护士 2 在第 0 天和第 1 班工作,第二天也在第 1 班工作


根据你的约束:

for n in all_nurses:
    for d in all_days:
        model.Add(sum([shifts[(n, d, 1)], shifts[(n, (d+1)%7, 0)]]) <= 1)

更好的表述是

for n in all_nurses:
    for d in all_days:
        model.AddBoolOr([shifts[(n, d, 1)].Not(), shifts[(n, (d + 1) % 7, 0)].Not()])

ref: https://github.com/google/or-tools/blob/aa0c6c42a523ee4c23633585b86fb6d3e090f8c8/ortools/sat/samples/bool_or_sample_sat.py#L23-L28 https://github.com/google/or-tools/blob/aa0c6c42a523ee4c23633585b86fb6d3e090f8c8/ortools/sat/samples/bool_or_sample_sat.py#L23-L28

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google Or-Tools员工排班。条件无法正常工作 的相关文章

随机推荐