Google Or-Tools员工日程安排。该条件无法正常运行

时间:2019-03-11 10:55:10

标签: python scheduling constraint-programming or-tools

我正在使用that nurse scheduling example。我有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。护士2在第0天和第1班工作,第二天也在第1班工作

1 个答案:

答案 0 :(得分:1)

根据您的限制:

Id       category_name
1        Books
1        Subjects
1        Religion & Spirituality

更好的表述是

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

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

相关问题