-
Notifications
You must be signed in to change notification settings - Fork 0
/
second.py
106 lines (62 loc) · 2.68 KB
/
second.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import logic
import itertools
KB = logic.PropKB()
#initial state
KB.tell(logic.expr("At_0(Flat, Axle) & ~At_0(Flat, Ground) & ~At_0(Flat, Trunk)"))
KB.tell(logic.expr("~At_0(Spare, Axle) & ~At_0(Spare, Ground) & At_0(Spare, Trunk)"))
# KB.tell(logic.expr("At_0(Flat, Axle) & At_0(Spare, Trunk)"))
# #initial locations imply parts are not elsewhere at the same time
# KB.tell(logic.expr("~At_0(Flat, Axle) | (~At_0(Flat, Trunk) & ~At_0(Flat, Ground))"))
#first
KB.tell(logic.expr("~Remove_0(Flat, Axle) | At_0(Flat, Axle)"))
KB.tell(logic.expr("~PutOn_0(Flat, Axle) | At_0(Flat, Ground) "))
KB.tell(logic.expr("~PutOn_0(Flat, Axle) | ~At_0(Flat, Axle) "))
KB.tell(logic.expr("~Remove_0(Flat, Trunk) | At_0(Flat, Trunk)"))
#second
KB.tell(logic.expr("~Remove_0(Flat, Axle) | At_1(Flat, Ground)"))
KB.tell(logic.expr("~PutOn_0(Flat, Axle) | At_1(Flat, Axle)"))
KB.tell(logic.expr("~Remove_0(Flat, Trunk) | At_1(Flat, Ground)"))
#third
KB.tell(logic.expr("~Remove_0(Flat, Axle) | ~At_1(Flat, Axle)"))
KB.tell(logic.expr("~PutOn_0(Flat, Axle) | ~At_1(Flat, Ground)"))
KB.tell(logic.expr("~Remove_0(Flat, Trunk) | ~At_1(Flat, Trunk)"))
#fourth
KB.tell(logic.expr("At_0(Flat, Axle) | ~At_1(Flat, Axle) | PutOn_0(Flat, Axle)"))
KB.tell(logic.expr("At_0(Flat, Ground) | ~At_1(Flat, Ground) | Remove_0(Flat, Axle) | Remove_0(Flat, Trunk)"))
KB.tell(logic.expr("At_0(Flat, Trunk) | ~At_1(Flat, Trunk)"))
#fifth
KB.tell(logic.expr("~At_0(Flat, Axle) | At_1(Flat, Axle) | Remove_0(Flat, Axle)"))
KB.tell(logic.expr("~At_0(Flat, Ground) | At_1(Flat, Ground) | PutOn_0(Flat, Axle)"))
KB.tell(logic.expr("~At_0(Flat, Trunk) | At_1(Flat, Trunk) | Remove_0(Flat, Trunk)"))
#list of all possible actions
actions = ["Remove_0(Flat, Axle)", "PutOn_0(Flat, Axle)", "Remove_0(Flat, Trunk)"]
#sixth, this can somewhat be automated
for elem in itertools.combinations(actions, 2):
KB.tell(logic.expr("~"+elem[0]+" | ~"+elem[1]))
# KB.tell(logic.expr("~Remove_0(Flat, Axle) | ~PutOn_0(Flat, Axle)"))
# KB.tell(logic.expr("~PutOn_0(Flat, Axle) | ~Remove_0(Flat, Axle)"))
#seventh, can be also automated
seventh = ""
for elem in actions:
seventh = seventh + elem + " | "
seventh = seventh[:-2]
KB.tell(logic.expr(seventh))
#add goal
KB.tell(logic.expr("At_1(Flat, Ground)"))
#some manual cnf
string = ""
for elem in KB.clauses:
# print(elem)
elem = logic.to_cnf(str(elem))
string = string + str(elem) + " & "
string = string[:-2]
# print(string)
#print only true values
answer = logic.dpll_satisfiable(string)
if answer != False:
for elem in answer:
if answer[elem]:
print(str(elem)+ " : " +str(answer[elem]))
else:
print(answer)
# print(logic.dpll_satisfiable(string))