【发布时间】:2018-09-01 05:03:33
【问题描述】:
您好,我不明白这个错误是如何产生的。我在左侧有相同数量的约束,在右侧列表中有相同数量的元素。也许我错过了一个小标志或者我的逻辑是错误的。请帮我理解。
Machines = ["A", "B",]
Days= ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"]
desire_num={"A":5, "B":2,}
week1={"Monday":1, "Tuesday":1, "Wednesday":1, "Thursday":1,
"Friday":1, "Saturday":1, "Sunday":1}
status_list=['1', '1', '0', '1', '0', '1', '1', '0', '0', '1', '0',
'1', '0', '0']
avail = pulp.LpVariable.dicts("var", ((machine, day) for machine in
Machines for day in Days), cat="Binary")
##---problem is here. I have 14 variables on the left and 14 elements in the list on the right. The error says list index out of range.
status_list_iterator = 0
for machine, day in avail:
self.prob += avail[machine, day] ==
status_list[status_list_iterator]
status_list_iterator+=1
再次感谢您的澄清。
【问题讨论】:
标签: python-3.x list variables indexing pulp