Advertisement
metalni

VI Vtora Labaratoriska - 2

Jun 30th, 2021
1,355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from constraint import *
  2.  
  3.  
  4. def check_Marija(prisustvo_marija, vreme_sostanok):
  5.     return prisustvo_marija != 1 or vreme_sostanok == 14
  6.  
  7.  
  8. def check_Petar(prisustvo_petar, vreme_sostanok):
  9.     return prisustvo_petar != 1 or vreme_sostanok == 16 or vreme_sostanok == 19 or vreme_sostanok == 13
  10.  
  11.  
  12. def check_Marija_Petar(prisustvo_marija, prisustvo_petar):
  13.     return prisustvo_marija != prisustvo_petar
  14.  
  15.  
  16. if __name__ == '__main__':
  17.     problem = Problem(BacktrackingSolver())
  18.  
  19.     # ---Dadeni se promenlivite, dodadete gi domenite-----
  20.     problem.addVariable("Marija_prisustvo", [0, 1])
  21.     problem.addVariable("Simona_prisustvo", [1])
  22.     problem.addVariable("Petar_prisustvo", [0, 1])
  23.     problem.addVariable("vreme_sostanok", [12, 13, 14, 15, 16, 17, 18, 19, 20])
  24.     # ----------------------------------------------------
  25.  
  26.     # ---Tuka dodadete gi ogranichuvanjata----------------
  27.  
  28.     # problem.addConstraint(lambda r1, r2: r1 != 1 or r2 == 13 or r2 == 14 or r2 == 16 or r2 == 19, ("Simona_prisustvo", "vreme_sostanok"))
  29.     problem.addConstraint(check_Marija, ("Marija_prisustvo", "vreme_sostanok"))
  30.     problem.addConstraint(check_Petar, ("Petar_prisustvo", "vreme_sostanok"))
  31.     problem.addConstraint(check_Marija_Petar, ("Marija_prisustvo", "Petar_prisustvo"))
  32.  
  33.     # ----------------------------------------------------
  34.     # [print(solution) for solution in problem.getSolutions()]
  35.  
  36.     solutions = problem.getSolutions()
  37.     for solution in solutions:
  38.         print("%s'Simona_prisustvo': %d, 'Marija_prisustvo': %d, 'Petar_prisustvo': %d, 'vreme_sostanok': %d%s" % (
  39.             "{", solution['Simona_prisustvo'], solution['Marija_prisustvo'], solution['Petar_prisustvo'],
  40.             solution['vreme_sostanok'], "}"))
  41.         # print("{}'Simona_prisustvo': {}, 'Marija_prisustvo': {}, 'Petar_prisustvo': {}, 'vreme_sostanok': {}{}".format("{", solution['Simona_prisustvo'], solution['Marija_prisustvo'], solution['Petar_prisustvo'], solution['vreme_sostanok'], "}"))
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement