我正在使用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工作
根据你的约束:
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()])