Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
按照此处的护士调度示例,我正在尝试为问题添加更多约束。例如:护士 A 不能在星期一工作 2 和 3 班,护士 B 只能工作 1 和 3 班。
如何实施这样的约束?
如果在 OR-tools 中不可能,请就如何实现这样的东西提出建议。
对于您的示例,您需要做的就是添加一个约束,以防止将班次分配给该特定护士:
solver.Add(shifts[(2, 1)] != 3) # Nurse 2 cannot be assigned shift 3 on day 1
更普遍:
solver.Add(shifts[(j, i)] != n) # Nurse j cannot be assigned shift n on day i
显然,如果可能,您将希望在循环中执行此操作以简化它。