Advertisement
196040

VI Prv kolokvium Constraint problem

Jun 16th, 2021
1,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.02 KB | None | 0 0
  1. from constraint import *
  2.  
  3. def gethelp(x, y):
  4.     if x == "Mon_10" or x == "Wed_10" or "Fri_10" and y == "Tue_10" or "Thu_10":
  5.         return True
  6.     if x == "Mon_11" or x == "Wed_11" or "Fri_11" and y == "Tue_11" or "Thu_11":
  7.         return True
  8.    
  9. def diff(x,y):
  10.     x = x.split("_")
  11.     y = y.split("_") # split day and hour
  12.     if x[0] == y[0]: # if day is the same
  13.         if abs(int(x[1]) - int(y[1])) >=2 : # ako razlikata megu terminite e 2 ili pojse saata
  14.             return True # togi moze
  15.     if x[0] != y[0]: # ako ne e istiot dennnnn sta kaze
  16.         return True # mozeeeee
  17.    
  18.    
  19.    
  20. if __name__ == '__main__':
  21.     problem = Problem(BacktrackingSolver())
  22.     casovi_AI = input()
  23.     casovi_ML = input()
  24.     casovi_R = input()
  25.     casovi_BI = input()
  26.    
  27.     AI_predavanja_domain = ["Mon_11", "Mon_12", "Wed_11", "Wed_12", "Fri_11", "Fri_12"]
  28.     ML_predavanja_domain = ["Mon_12", "Mon_13", "Mon_15", "Wed_12", "Wed_13", "Wed_15", "Fri_11", "Fri_12", "Fri_15"]
  29.     R_predavanja_domain = ["Mon_10", "Mon_11", "Mon_12", "Mon_13","Mon_14", "Mon_15", "Wed_10", "Wed_11", "Wed_12", "Wed_13","Wed_14", "Wed_15", "Fri_10", "Fri_11", "Fri_12", "Fri_13","Fri_14", "Fri_15"]
  30.     BI_predavanja_domain = ["Mon_10", "Mon_11", "Wed_10", "Wed_11", "Fri_10", "Fri_11"]
  31.    
  32.     AI_vezbi_domain = ["Tue_10", "Tue_11", "Tue_12", "Tue_13", "Thu_10", "Thu_11", "Thu_12", "Thu_13"]
  33.     ML_vezbi_domain = ["Tue_11", "Tue_13", "Tue_14", "Thu_11", "Thu_13", "Thu_14"]
  34.     BI_vezbi_domain = ["Tue_10", "Tue_11", "Thu_10", "Thu_11"]
  35.    
  36.     # ---Tuka dodadete gi promenlivite--------------------
  37.     variables = []
  38.    
  39.     for i in range(0, int(casovi_AI)):
  40.         problem.addVariable("AI_cas_" + str(i+1), AI_predavanja_domain)
  41.         variables.append("AI_cas_" + str(i+1))
  42.     for i in range(0, int(casovi_R)):
  43.         problem.addVariable("R_cas_" + str(i+1), R_predavanja_domain)
  44.         variables.append("R_cas_" + str(i+1))
  45.     for i in range(0, int(casovi_ML)):
  46.         problem.addVariable("ML_cas_" + str(i+1), ML_predavanja_domain)
  47.         variables.append("ML_cas_" + str(i+1))
  48.     for i in range(0, int(casovi_BI)):
  49.         problem.addVariable("BI_cas_" + str(i+1), BI_predavanja_domain)
  50.         variables.append("BI_cas_" + str(i+1))
  51.     # voa ako e okej se farbam zelena
  52.    
  53.     problem.addVariable("AI_vezbi", AI_vezbi_domain)
  54.     variables.append("AI_vezbi")
  55.     problem.addVariable("BI_vezbi", BI_vezbi_domain)
  56.     variables.append("BI_vezbi")
  57.     problem.addVariable("ML_vezbi", ML_vezbi_domain)
  58.     variables.append("ML_vezbi")
  59.    
  60.    
  61.     # ---Tuka dodadete gi ogranichuvanjata----------------
  62.    
  63.     problem.addConstraint(gethelp, ("BI_cas_1", "BI_vezbi"))
  64.     for attempt1 in variables:
  65.         for attempt2 in variables:
  66.             if attempt1 != attempt2:
  67.                 problem.addConstraint(diff, (attempt1, attempt2))
  68.    
  69.     # ----------------------------------------------------
  70.     solution = problem.getSolution()
  71.    
  72.     print(solution)
  73.     #vade 2/3 ama jas bi si go priznala za tocno
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement