本文整理汇总了Python中Mistral.Solver.setVerbosity方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.setVerbosity方法的具体用法?Python Solver.setVerbosity怎么用?Python Solver.setVerbosity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mistral.Solver
的用法示例。
在下文中一共展示了Solver.setVerbosity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solveSchedule
# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import setVerbosity [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)
示例2: main
# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import setVerbosity [as 别名]
def main():
faculty_var_arrays = [get_prof(VISITORS) for prof in PROFESSORS]
model = Model()
model.add(get_visitor_consistency_constraints(faculty_var_arrays))
model.add(get_no_repeat_constraints(faculty_var_arrays))
# read faculty availability information
busyfile = open(sys.argv[2], 'rb')
busyreader = csv.reader(busyfile)
for r in busyreader:
if r[0] in PROFESSORS:
prof_index = PROFESSORS.index(r[0])
for i in range(1,NUM_SLOTS + 1):
if r[i] == "NO":
model.add(get_busy_constraint(i-1, prof_index, faculty_var_arrays))
else:
print "professor not found in list"
busyfile.close()
requestfile = open(sys.argv[1], 'rb')
reader = csv.reader(requestfile)
for r in reader:
row = [name for name in r if not (name == "," or name == "" or name == " ")]
if row[0] in VISITORS:
for i in range(1,len(row)):
if not (row[i] in PROFESSORS):
print "professor name mismatch: " + str(row[i])
else:
model.add(get_meeting_constraint(VISITORS.index(row[0]), PROFESSORS.index(row[i]), faculty_var_arrays))
elif row[0] in PROFESSORS:
for i in range(1,len(row)):
if not (row[i] in VISITORS):
print "visitor name mismatch in row " + str(row)
else:
model.add(get_meeting_constraint(VISITORS.index(row[i]), PROFESSORS.index(row[0]), faculty_var_arrays))
else:
print "requestor name mismatch in row " + str(row)
solver = Solver(model, [p[s] for p in faculty_var_arrays for s in range(NUM_SLOTS)])
solver.setVerbosity(2)
solver.solve()
# print(solver.solveAndRestart())
print "PROFESSOR SCHEDULES"
print "-------------------"
for i in range(len(PROFESSORS)):
print "---------------"
print "schedule for " + PROFESSORS[i]
for slot in faculty_var_arrays[i]:
if slot.get_value():
print VISITORS[slot.get_value()]
# print(solver)
requestfile.close()