我试图显示项目列表,但我遇到了功能pulp.value()的问题,但它不起作用,如果有人可以帮助我,我也不知道问题出在哪里
我的列表:
exams={'Exam PL':30,
'Exam Graphe':30,
'Exam Angular':60,
'Exam English':90,
'Frensh Exam':60,}
slots=[('A',0,30),('A',30,60),
('A',90,60),('B',0,30),
('B',30,90),('B',120,30),
('C',0,90),('C',90,60),]
assign={(exam,slot):pulp.LpVariable('%r in slot %r'%(exam,slot),cat=pulp.LpBinary) for exam in exams for slot in slots}
赋值函数:
for slot in slots:
problem.addConstraint
(sum(assign[(exam,slot)]
for exam in exams)<= 1)
我要显示的循环:
print('Exam assignement:')
print('-'*72)
for(exam,slot),assigned in sorted(assign.items()):
if pulp.value(assigned):
print('Exam %r assigned to Slot %r' %(exam,slot))
print('')
如果条件不起作用,我不知道为什么在示例中我从中取得了效果