繁体   English   中英

Google Or-Tools Employee Scheduling . 条件不能正常工作

[英]Google Or-Tools Employee Scheduling .The condition does not work properly

我正在使用那个护士调度示例 我有 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)

这是输出 护士 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()])

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM