-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEinsteinTest.py
63 lines (50 loc) · 1.93 KB
/
EinsteinTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from Backtracking import *
country = ["Norweg", "Anglik", "Duńczyk", "Niemiec", "Szwed"]
color = ["czerwony", "zielony", "biały", "żółty", "niebieski"]
tobacco = ["light", "cygaro", "fajka", "bez filtra", "menthol"]
drink = ["herbata", "mleko", "woda", "piwo", "kawa"]
breed = ["koty", "ptaki", "psy", "konie", "rybki"]
variables = country + color + tobacco + drink + breed
house = [1, 2, 3, 4, 5]
problem = Problem()
for variable in variables:
problem.add_variable(variable, house)
single_constraints = [
(lambda a: a == 1, "Norweg"),
(lambda a: a == 3, "mleko")
]
double_constraints = [
(lambda a, b: a == b, ["Anglik", "czerwony"]),
(lambda a, b: a - b == -1, ["zielony", "biały"]),
(lambda a, b: a == b, ["Duńczyk", "herbata"]),
(lambda a, b: abs(a-b) == 1, ["light", "koty"]),
(lambda a, b: a == b, ["żółty", "cygaro"]),
(lambda a, b: a == b, ["Niemiec", "fajka"]),
(lambda a, b: abs(a-b) == 1, ["light", "woda"]),
(lambda a, b: a == b, ["bez filtra", "ptaki"]),
(lambda a, b: a == b, ["Szwed", "psy"]),
(lambda a, b: abs(a-b) == 1, ["Norweg", "niebieski"]),
(lambda a, b: abs(a-b) == 1, ["konie", "żółty"]),
(lambda a, b: a == b, ["menthol", "piwo"]),
(lambda a, b: a == b, ["zielony", "kawa"])
]
multiple_constraints = [
(lambda a, b: a != b, country),
(lambda a, b: a != b, color),
(lambda a, b: a != b, tobacco),
(lambda a, b: a != b, drink),
(lambda a, b: a != b, breed),
]
for constraint, domain in single_constraints:
problem.add_single_constraint(constraint, domain)
for constraint, domain in double_constraints:
problem.add_double_constraint(constraint, domain)
for constraint, domain in multiple_constraints:
problem.add_multiple_constraint(constraint, domain)
problem.solve()
print(problem.solutions)
for i in range(1, 6):
print(f"\ndomek {i}:")
for var in problem.solutions[0]:
if var[1] == i:
print(var[0])