Advertisement
dzocesrce

[VI] Meeting

Jan 23rd, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. from constraint import *
  2.  
  3.  
  4. def check_attendance(M,P,S):
  5.     if S==0:
  6.         return False
  7.     if M==0 and P==0:
  8.         return False
  9.     return True
  10.  
  11. def check_simona(S,V):
  12.     if (V>=13 and V<15) or V==16 or V==19:
  13.         return True
  14.     return False
  15.  
  16. def check_marija(M,V):
  17.     if M==0:
  18.         return True
  19.     else:
  20.         if (V>=14 and V<16) or V==18:
  21.             return True
  22.         return False
  23.  
  24. def check_petar(P,V):
  25.     if P==0:
  26.         return True
  27.     else:
  28.         if (V>=12 and V<14) or (V>=16 and V<20):
  29.             return True
  30.         return False
  31. if __name__ == '__main__':
  32.     problem = Problem(BacktrackingSolver())
  33.  
  34.     # ---Dadeni se promenlivite, dodadete gi domenite-----
  35.     problem.addVariable("Marija_prisustvo", [0,1])
  36.     problem.addVariable("Simona_prisustvo", [0,1])
  37.     problem.addVariable("Petar_prisustvo", [0,1])
  38.     problem.addVariable("vreme_sostanok", [12,13,14,15,16,17,18,19])
  39.     # ----------------------------------------------------
  40.  
  41.     # ---Tuka dodadete gi ogranichuvanjata----------------
  42.     problem.addConstraint(check_simona,("Simona_prisustvo","vreme_sostanok"))
  43.     problem.addConstraint(check_attendance,("Marija_prisustvo","Petar_prisustvo","Simona_prisustvo"))
  44.     problem.addConstraint(check_marija,("Marija_prisustvo","vreme_sostanok"))
  45.     problem.addConstraint(check_petar, ("Petar_prisustvo", "vreme_sostanok"))
  46.  
  47.     # ----------------------------------------------------
  48.  
  49.     [print(solution) for solution in problem.getSolutions()]
  50.  
  51. #tocna e ali ne mi printa vo soodveten redosled guess treba da si doktor za toa da go postignes na olku prosta zadaca
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement