Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from constraint import *
- if __name__ == '__main__':
- problem = Problem(BacktrackingSolver())
- # ---------- Add variables and their domain ----------
- problem.addVariable("Marija_prisustvo", [0, 1])
- problem.addVariable("Simona_prisustvo", [0, 1])
- problem.addVariable("Petar_prisustvo", [0, 1])
- problem.addVariable("vreme_sostanok", range(12, 21))
- # ----------------------------------------------------
- # Time schedules
- simona_free_time = list(range(13, 15)) + list(range(16, 17)) + list(range(19, 20))
- marija_free_time = list(range(14, 16)) + list(range(18, 19))
- petar_free_time = list(range(12, 14)) + list(range(16, 20))
- # ------------------------------------- Constraints begin here -----------------------------------------
- # Simona must be there
- problem.addConstraint(InSetConstraint({1}), ["Simona_prisustvo"])
- # At least one other member should be there with Simona
- problem.addConstraint(SomeInSetConstraint({1}), ["Petar_prisustvo", "Marija_prisustvo"])
- # Constraints for the time schedule (e.g simona is available at those times)
- problem.addConstraint(lambda person, time: person == 1 and time in simona_free_time,
- ["Simona_prisustvo", "vreme_sostanok"])
- problem.addConstraint(lambda person, time: person == 1 if time in marija_free_time else person == 0,
- ["Marija_prisustvo", "vreme_sostanok"])
- problem.addConstraint(lambda person, time: person == 1 if time in petar_free_time else person == 0,
- ["Petar_prisustvo", "vreme_sostanok"])
- # ------------------------------------------------------------------------------------------------------
- [print(solution) for solution in problem.getSolutions()]
Add Comment
Please, Sign In to add comment