本文整理汇总了Python中Mistral.Solver.setTimeLimit方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.setTimeLimit方法的具体用法?Python Solver.setTimeLimit怎么用?Python Solver.setTimeLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mistral.Solver
的用法示例。
在下文中一共展示了Solver.setTimeLimit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solveSchedule
# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import setTimeLimit [as 别名]
def solveSchedule():
# Parse the data in a way that seems easy at 2am
profTimes = dict(map( lambda x: (x[0], x[1:]),
map( lambda x:
map(str, x.replace('"','').strip().split(",")),
open(sys.argv[1]).readlines())))
students = dict(map(lambda z: (z[0], z[1:]),
map( lambda y: filter(lambda x: len(x) > 0, y),
map(lambda x: x.strip().split(","),
open(sys.argv[2]).readlines()))))
model = Model()
# Set up the professors as lists of variables
profResources = {}
for prof in visit_day_scheduler.PROFESSORS:
profResources[prof] = [Variable(i, i)
for i in range(len(profTimes[prof]))
if profTimes[prof][i].find('NO') == 0]
# Now add meetings
studentMeetings = {}
obj = []
for s in visit_day_scheduler.VISITORS:
# 4 is a magic number which seems to make things SAT so mistral stays happy
studentMeetings[s] = [Variable(0, 4*visit_day_scheduler.NUM_SLOTS) for i in students[s]]
for i in range(len(students[s])):
if profResources.has_key(students[s][i]):
profResources[ students[s][i] ].append(studentMeetings[s][i])
if len(studentMeetings[s]) > 1: model.add(AllDiff(studentMeetings[s]))
# try to put meetings in actual slots, not fake ones
obj_test = [i > visit_day_scheduler.NUM_SLOTS - 1 for i in studentMeetings[s]]
obj.extend(obj_test)
model.add([AllDiff(x) for x in profResources.values() if len(x) > 1])
model.add(Minimize(Sum(obj)))
solver = Solver(model)
solver.setVerbosity(2)
solver.setTimeLimit(10)
if solver.solve() or True:
outfile = open("out.csv", "wb")
outwriter = csv.writer(outfile)
outwriter.writerow(header)
for s in visit_day_scheduler.VISITORS:
outRow = [s] + ["" for i in range(visit_day_scheduler.NUM_SLOTS)]
for i in range(len(studentMeetings[s])):
if profResources.has_key(students[s][i]):
meeting = int(str(studentMeetings[s][i]))
if meeting < visit_day_scheduler.NUM_SLOTS: # only output real meetings
outRow[meeting + 1] = str(students[s][i])
outwriter.writerow(outRow)