在文档和我可以找到的所有示例中......至少在护士安排方面,每个人都只在{1,4}的搜索空间内声明了移位值,比如说换班1,2,3,4。 ...
solver = pywrapcp.Solver("schedule_shifts")
num_nurses = 4
num_shifts = 4 # Nurse assigned to shift 0 means not working that day.
num_days = 7
# [START]
# Create shift variables.
shifts = {}
for j in range(num_nurses):
for i in range(num_days):
shifts[(j, i)] = solver.IntVar(0, num_shifts - 1, "shifts(%i,%i)" % (j, i))
shifts_flat = [shifts[(j, i)] for j in range(num_nurses) for i in range(num_days)]
# Create nurse variables.
nurses = {}
for j in range(num_shifts):
for i in range(num_days):
nurses[(j, i)] = solver.IntVar(0, num_nurses - 1, "shift%d day%d" % (j,i))
我想在调用solver.IntVar(lowerbound, upperbound, ...)
我想要IntSolver([available values that you can choose], ...)
我创建了一个包含所有班次的矩阵,作为从第一天到最后一天的列。我的行索引并不重要,但在每天/班次列中,我的护士索引值按照该班次最高出价的降序排列。我想创建一个约束,如果我选择一名护士,我会选择通过列中其他约束允许的最高出价,但是我不知道如何做到这一点,因为ortools与python有限的文档{ {1}}。
答案 0 :(得分:0)
你能尝试
solver.IntVar([values ...],'name')
应该可以。
请参见https://github.com/google/or-tools/blob/master/examples/python/einav_puzzle2.py