-
Notifications
You must be signed in to change notification settings - Fork 0
/
second2.py
178 lines (116 loc) · 5.09 KB
/
second2.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import logic
import itertools
KB = logic.PropKB()
#initial state
# KB.tell(logic.expr("~At0SpareGround | At_0(Spare,Trunk) | ~At_0(Spare,Axle)"))
#
#
# KB.tell(logic.expr("At_0(Flat,Axle) | ~At_0(Flat,Ground) | ~At_0(Flat,Trunk)"))
KB.tell(logic.expr("~At0SpareGround"))
KB.tell(logic.expr("At_0(Spare,Trunk)"))
KB.tell(logic.expr("~At_0(Spare,Axle)"))
KB.tell(logic.expr("At_0(Flat,Axle)"))
KB.tell(logic.expr("~At_0(Flat,Ground)"))
KB.tell(logic.expr("~At_0(Flat,Trunk)"))
##do not include not possible actions,will keep model simpler
#first
KB.tell(logic.expr("~Remove0SpareTrunk | At_0(Spare,Trunk)"))
KB.tell(logic.expr("~Remove_0(Flat,Axle) | At_0(Flat,Axle)"))
KB.tell(logic.expr("~Remove_1(Spare,Trunk) | At_1(Spare,Trunk)"))
KB.tell(logic.expr("~Remove_1(Flat,Axle) | At_1(Flat,Axle)"))
#second
KB.tell(logic.expr("~Remove0SpareTrunk | At_1(Spare,Ground)"))
KB.tell(logic.expr("~Remove_0(Flat,Axle) | At_1(Flat,Ground)"))
KB.tell(logic.expr("~Remove_1(Spare,Trunk) | At_2(Spare,Ground)"))
KB.tell(logic.expr("~Remove_1(Flat,Axle) | At_2(Flat,Ground)"))
#third
KB.tell(logic.expr("~Remove0SpareTrunk | ~At_1(Spare,Trunk)"))
KB.tell(logic.expr("~Remove_0(Flat,Axle) | ~At_1(Flat,Axle)"))
KB.tell(logic.expr("~Remove_1(Spare,Trunk) | ~At_2(Spare,Trunk)"))
KB.tell(logic.expr("~Remove_1(Flat,Axle) | ~At_2(Flat,Axle)"))
#fourth from false to true
KB.tell(logic.expr("At0SpareGround | ~At_1(Spare,Ground) | Remove0SpareTrunk"))
# KB.tell(logic.expr("At_0(Spare,Trunk) | ~At_1(Spare,Trunk)"))
# KB.tell(logic.expr("At_0(Spare,Axle) | ~At_1(Spare,Axle)"))
# KB.tell(logic.expr("At_0(Flat,Axle) | ~At_1(Flat,Axle)"))
KB.tell(logic.expr("At_0(Flat,Ground) | ~At_1(Flat,Ground) | Remove_0(Flat,Axle)"))
# KB.tell(logic.expr("At_0(Flat,Trunk) | ~At_1(Flat,Trunk)"))
KB.tell(logic.expr("At_1(Spare,Ground) | ~At_2(Spare,Ground) | Remove_1(Spare,Trunk)"))
# KB.tell(logic.expr("At_1(Spare,Trunk) | ~At_2(Spare,Trunk)"))
# KB.tell(logic.expr("At_1(Spare,Axle) | ~At_2(Spare,Axle)"))
# KB.tell(logic.expr("At_1(Flat,Axle) | ~At_2(Flat,Axle)"))
KB.tell(logic.expr("At_1(Flat,Ground) | ~At_2(Flat,Ground) | Remove_1(Flat,Axle)"))
# KB.tell(logic.expr("At_1(Flat,Trunk) | ~At_2(Flat,Trunk)"))
#fifth from true to false
# KB.tell(logic.expr("~At0SpareGround | At_1(Spare,Ground)"))
KB.tell(logic.expr("~At_0(Spare,Trunk) | At_1(Spare,Trunk) | Remove0SpareTrunk"))
# KB.tell(logic.expr("~At_0(Spare,Axle) | At_1(Spare,Axle)"))
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)"))
# KB.tell(logic.expr("~At_0(Flat,Trunk) | At_1(Flat,Trunk)"))
# KB.tell(logic.expr("~At_1(Spare,Ground) | At_2(Spare,Ground)"))
KB.tell(logic.expr("~At_1(Spare,Trunk) | At_2(Spare,Trunk) | Remove_1(Spare,Trunk)"))
# KB.tell(logic.expr("~At_1(Spare,Axle) | At_2(Spare,Axle)"))
KB.tell(logic.expr("~At_1(Flat,Axle) | At_2(Flat,Axle) | Remove_1(Flat,Axle)"))
# KB.tell(logic.expr("~At_1(Flat,Ground) | At_2(Flat,Ground)"))
# KB.tell(logic.expr("~At_1(Flat,Trunk) | At_2(Flat,Trunk)"))
#list of all possible actions
actions = ["Remove0SpareTrunk","Remove_0(Flat,Axle)"]
actions2 = ["Remove_1(Spare,Trunk)","Remove_1(Flat,Axle)"]
#sixth,this can somewhat be automated
for elem in actions:
for elem2 in actions:
if elem != elem2:
print(logic.expr("~"+elem+" | ~"+elem2))
KB.tell(logic.expr("~"+elem+" | ~"+elem2))
for elem in actions2:
for elem2 in actions2:
if elem != elem2:
print(logic.expr("~"+elem+" | ~"+elem2))
KB.tell(logic.expr("~"+elem+" | ~"+elem2))
# for elem in itertools.combinations(actions,2):
# # print(logic.expr("~"+elem[0]+" | ~"+elem[1]))
# KB.tell(logic.expr("~"+elem[0]+" | ~"+elem[1]))
#
#
# for elem in itertools.combinations(actions2,2):
# KB.tell(logic.expr("~"+elem[0]+" | ~"+elem[1]))
#seventh,can be also automated
seventh = ""
KB.tell(logic.expr("Remove0SpareTrunk | Remove_0(Flat,Axle)"))
# for elem in actions:
# seventh = seventh + elem + " | "
# seventh = seventh[:-2]
# print(logic.expr(seventh))
#
# KB.tell(logic.expr(seventh))
seventh = ""
KB.tell(logic.expr("Remove_1(Spare,Trunk) | Remove_1(Flat,Axle)"))
# for elem in actions2:
# seventh = seventh + elem + " | "
# seventh = seventh[:-2]
# print(logic.expr(seventh))
# KB.tell(logic.expr(seventh))
#add goal
# KB.tell(logic.expr("Remove_0(Flat,Axle) & Remove_1(Spare,Trunk)"))
# KB.tell(logic.expr("Remove0SpareTrunk"))
# KB.tell(logic.expr("Remove_0(Flat,Axle)"))
# KB.tell(logic.expr("At_2(Flat,Ground) & At_2(Spare,Ground)"))
KB.tell(logic.expr("At_2(Flat,Ground)"))
KB.tell(logic.expr("At_2(Spare,Ground)"))
#some manual cnf
string = ""
for elem in KB.clauses:
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))