当前位置: 首页>>代码示例>>Python>>正文


Python Solver.solve方法代码示例

本文整理汇总了Python中Mistral.Solver.solve方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.solve方法的具体用法?Python Solver.solve怎么用?Python Solver.solve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mistral.Solver的用法示例。


在下文中一共展示了Solver.solve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [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()
开发者ID:davidpwilliamson,项目名称:orie_visit_day_scheduler,代码行数:55,代码来源:visit_day_scheduler.py

示例2: testOr_2

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testOr_2(self):
     var1 = Variable(0, 2)
     dur1 = 1
     
     var2 = Variable(0, 4)
     dur2 = 2
     
     var3 = Variable(0, 6)
     dur3 = 3
     
     model = NativeModel()
     
     #model.add( NoOverlap( (var1, var2), (dur1, dur2) ) )
     #model.add( NoOverlap( (var1, var3), (dur1, dur3) ) )
     #model.add( NoOverlap( (var2, var3), (dur2, dur3) ) )
     
     ur = UnaryResource ( [ NoOverlap( (var1, var2), (dur1, dur2) ),
                                  NoOverlap( (var1, var3), (dur1, dur3) ),
                                  NoOverlap( (var2, var3), (dur2, dur3) ) ] )
     
     model.add( ur )
     
     solver = Solver(model)
     
     assert(solver.solve())
     
     assert ( (var1.get_value() + dur1 < var2.get_value ) or
         ( var2.get_value() + dur2 < var1.get_value  ) )
开发者ID:eomahony,项目名称:Numberjack,代码行数:30,代码来源:SolverTests.py

示例3: testSumConstant

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testSumConstant(self):
      obj1 = Variable(list(range(0,6)))
      obj2 = Variable(list(range(0,8)))
      obj3 = Variable(list(range(0,11)))
 
      capacity = Variable(list(range(34,35)))
      volumes = [7, 5, 3]
 
      model = NativeModel()
 
      vol_sum = Sum(((obj1, obj2, obj3), volumes))
 
      model.add_variable((obj1, obj2, obj3, vol_sum, capacity))
 
      model.add_constraint(Leq((vol_sum, capacity)))
      
      solver = Solver(model)
     
      '''
      obj1.print_domain()
      obj2.print_domain()
      obj3.print_domain()
      vol_sum.print_domain()
      capacity.print_domain()
      '''
      
      assert( solver.solve() )
      
      '''
开发者ID:eomahony,项目名称:Numberjack,代码行数:31,代码来源:SolverTests.py

示例4: testMinusOverNativeModelOp

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testMinusOverNativeModelOp(self):
     var1, var2 = (Variable(range(0,4)), Variable(range(0,4)))
     
     model = NativeModel()
     
     model << (var1 == var2 - 3)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例5: testTimesOver

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testTimesOver(self):
     var1, var2 = (Variable(range(1,4)), Variable(range(0,4)))
     
     model = NativeModel()
     
     model.add_constraint(var1 == var2 * 2)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:AbdullahMohammad,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例6: testTimesOverNativeModelOp

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testTimesOverNativeModelOp(self):
     var1, var2 = (Variable(list(range(1,4))), Variable(list(range(0,4))))
     
     model = NativeModel()
     
     model << (var1 == var2 * 2)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例7: testMinusOver

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testMinusOver(self):
     var1, var2 = (Variable(list(range(0,4))), Variable(list(range(0,4))))
     
     model = NativeModel()
     
     model.add_constraint(var1 == var2 - 3)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例8: testAtMostUNSAT_2

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testAtMostUNSAT_2(self):
     model = NativeModel()
     var1, var2 = (Variable(2,2), Variable(0,1))
     
     model << (AtMost(([var1, var2], 2, 2)))
     
     solver = Solver(model)
     
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例9: testOperatorOVerloading

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testOperatorOVerloading(self):
     var1 = Variable(list(range(0,4)))
     var2 = Variable(list(range(0,4)))
     
     model = NativeModel()
     model.add_constraint(var1 != var2)
                          
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例10: testExactlyUNSAT_2

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testExactlyUNSAT_2(self):
     model = NativeModel()
     var1, var2 = (Variable(0,5), Variable(0,5))
     
     model << (Exactly(((var1, var2), 2, 3)))
     
     solver = Solver(model)
     
     assert(not solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例11: testAtLeastUNSAT_2

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testAtLeastUNSAT_2(self):
     model = NativeModel()
     var1, var2 = (Variable(0,5), Variable(0,5))
     
     model << (AtLeast(([var1, var2], 0, 3)))
     
     solver = Solver(model)
     
     assert(not solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:11,代码来源:SolverTests.py

示例12: testGTOver

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testGTOver(self):
     var1, var2, var3 = (Variable(list(range(0,3))) for x in range(0,3))
     model = NativeModel()
     
     model.add_constraint(var1 < var2)
     model.add_constraint(var2 < var3)
     model.add_constraint(var1 < var3)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:12,代码来源:SolverTests.py

示例13: testEqualOver

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testEqualOver(self):
     var1 = Variable([0])
     var2 = Variable(list(range(0,1)))
     
     model = NativeModel()
     
     model.add_constraint(var1 == var2)
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:12,代码来源:SolverTests.py

示例14: testEqual

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testEqual(self):
     var1 = Variable([0])
     var2 = Variable(list(range(0,1)))
     
     model = NativeModel()
     
     model.add_variable((var1, var2))
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:12,代码来源:SolverTests.py

示例15: testMinus

# 需要导入模块: from Mistral import Solver [as 别名]
# 或者: from Mistral.Solver import solve [as 别名]
 def testMinus(self):
     var1, var2 = (Variable(list(range(0,4))), Variable(list(range(0,4))))
     
     model = NativeModel()
     model.add_variable((var1, var2))
     
     model.add_constraint(Equal((var1, Minus(var2, 3))))
     
     solver = Solver(model)
     assert(solver.solve())
开发者ID:eomahony,项目名称:Numberjack,代码行数:12,代码来源:SolverTests.py


注:本文中的Mistral.Solver.solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。