Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from constraint import *
- def gethelp(x, y):
- if x == "Mon_10" or x == "Wed_10" or "Fri_10" and y == "Tue_10" or "Thu_10":
- return True
- if x == "Mon_11" or x == "Wed_11" or "Fri_11" and y == "Tue_11" or "Thu_11":
- return True
- def diff(x,y):
- x = x.split("_")
- y = y.split("_") # split day and hour
- if x[0] == y[0]: # if day is the same
- if abs(int(x[1]) - int(y[1])) >=2 : # ako razlikata megu terminite e 2 ili pojse saata
- return True # togi moze
- if x[0] != y[0]: # ako ne e istiot dennnnn sta kaze
- return True # mozeeeee
- if __name__ == '__main__':
- problem = Problem(BacktrackingSolver())
- casovi_AI = input()
- casovi_ML = input()
- casovi_R = input()
- casovi_BI = input()
- AI_predavanja_domain = ["Mon_11", "Mon_12", "Wed_11", "Wed_12", "Fri_11", "Fri_12"]
- ML_predavanja_domain = ["Mon_12", "Mon_13", "Mon_15", "Wed_12", "Wed_13", "Wed_15", "Fri_11", "Fri_12", "Fri_15"]
- 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"]
- BI_predavanja_domain = ["Mon_10", "Mon_11", "Wed_10", "Wed_11", "Fri_10", "Fri_11"]
- AI_vezbi_domain = ["Tue_10", "Tue_11", "Tue_12", "Tue_13", "Thu_10", "Thu_11", "Thu_12", "Thu_13"]
- ML_vezbi_domain = ["Tue_11", "Tue_13", "Tue_14", "Thu_11", "Thu_13", "Thu_14"]
- BI_vezbi_domain = ["Tue_10", "Tue_11", "Thu_10", "Thu_11"]
- # ---Tuka dodadete gi promenlivite--------------------
- variables = []
- for i in range(0, int(casovi_AI)):
- problem.addVariable("AI_cas_" + str(i+1), AI_predavanja_domain)
- variables.append("AI_cas_" + str(i+1))
- for i in range(0, int(casovi_R)):
- problem.addVariable("R_cas_" + str(i+1), R_predavanja_domain)
- variables.append("R_cas_" + str(i+1))
- for i in range(0, int(casovi_ML)):
- problem.addVariable("ML_cas_" + str(i+1), ML_predavanja_domain)
- variables.append("ML_cas_" + str(i+1))
- for i in range(0, int(casovi_BI)):
- problem.addVariable("BI_cas_" + str(i+1), BI_predavanja_domain)
- variables.append("BI_cas_" + str(i+1))
- # voa ako e okej se farbam zelena
- problem.addVariable("AI_vezbi", AI_vezbi_domain)
- variables.append("AI_vezbi")
- problem.addVariable("BI_vezbi", BI_vezbi_domain)
- variables.append("BI_vezbi")
- problem.addVariable("ML_vezbi", ML_vezbi_domain)
- variables.append("ML_vezbi")
- # ---Tuka dodadete gi ogranichuvanjata----------------
- problem.addConstraint(gethelp, ("BI_cas_1", "BI_vezbi"))
- for attempt1 in variables:
- for attempt2 in variables:
- if attempt1 != attempt2:
- problem.addConstraint(diff, (attempt1, attempt2))
- # ----------------------------------------------------
- solution = problem.getSolution()
- print(solution)
- #vade 2/3 ama jas bi si go priznala za tocno
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement