-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlocksWorldActionLanguage
More file actions
253 lines (169 loc) · 7.68 KB
/
BlocksWorldActionLanguage
File metadata and controls
253 lines (169 loc) · 7.68 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Class hierachy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
is_subclass(#animate, #thing)
is_subclass(#innimate, #thing)
is_subclass(#person, #animate)
is_subclass(#robot, #animate)
is_subclass(#object, #inanimate)
is_subclass(#door, #inanimate)
%% hierachies of locations
is_subclass(#building, #location)
is_subclass(#floor, #building)
is_subclass(#door, #floor)
is_subclass(#room, #floor)
is_subclass(#area, #room)
%%membership rules
member_of(#object, #class) if is_a(#object, #class)
member_of(#object, #class1) if is_a(#object, #class2)^is_subclass(#class2, #class1)
-member_of(#object, #class) if not member_of(#object, #class)
%% subclass relation rules
-is_subclass(#class1, #class2) if not is_subclass(#class1, #class2)
%% sibling rules
%if both classes have the same parent class, then they are siblings
siblings(C1, C2) if is_subclass(C1, C3), is_subclass(C2, C3)
%% if not defined to be a sibling, then not
-siblings(C1, C2) if not siblings(C1, C2)
%% location membership rules
belongs_to(L1, L2) if is_subclass(L1, L2)
belongs_to(L1, L3) if belongs_to(L1, L2), belongs_to(L2, L3), is_subclass(L2, L3)
-belongs_to(L1, L2) if not belongs_to(L1, L2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% AL BEGINS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Statics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
belongs_to(#location, #location) %% rooms consist of areas and doors, floors consist of rooms, buildings consist of floors
is_connected(#location, #location) %% is physically connected
%% Object Predicates
has_size(#real, #size)
has_colour(#real, #colour)
has_shape(#real, #shape)
has_surface(#real, #surface)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Fluents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Inertial Fluents
has_location(#thing, #location)
has_object(#animate, #inanimate)
is_open(#door)
is_on(#real, #surface)
has_state(#real, #state)
%% Defined Fluents
can_move_to(#animate, #location)
is_above(#real, #real)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Actions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
travel(#animate, #location)
pick_up(#animate, #object)
put_down(#animate, #object, #location)
open_door(#animate, #door)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Causal laws
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% robot can travel to a location
travel(R, L2) causes has_location(R, L2)
travel(R, L2) causes -has_location(R, L1) @I+1 if has_location(R,L1) @ I
%% robot can pick up an object
pick_up(R, O) causes has_object(R, O)
%% If you pick up an object then it is no longer where it was
pick_up(R,O1) causes -is_on(O1, S2) @ I+1 if is_on(O1, S2) @I, has_surface(O2, S2)
%% robot can put down an object
put_down_object(R, O, L) causes -has_object(R, O)
%% if a robot puts down an object at a location and there is already an object O2 there, O1 is on O2.
put_down_object(R,O, S2) causes is_on(O1,S2) if has_location(Robot, L), has_location(O2, L), has_surface(O2, S2)
%% robot can open a door
open_door(R, D) causes is_open(D)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% State constraints
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% if a thing is in a specific location, it is also in the locations above it in the hierachy
has_location(Th, L2) if has_location(Th, L1), belongs_to(L1, L2)
%% an thing can only be in one sort of location at a time
-has_location(Th, L1) if has_location(Th, L2), siblings(L1, L2)
%% if a animate being has an object, the object's location is that of the being
has_location(O,L) if has_location(A,L), has_object(A,O)
%% If areas are in the same room, then they are connected
is_connected(A1, A2) if belongs_to(A1, R1), belongs_to(A2, R1)
%% If rooms have the same door, then they are connected
is_connected(R1, R2) if belongs_to(D1, R1), belongs_to(D2, R2)
%% Locations are not connected unless you explicitly say they are
-is_connected(L1, L2) if not is_connected(L1, L2)
%% Location are communitive
is_connected(L1, L2) if is_connected(L2, L1)
%% If areas are connected, then you can move between them
can_move_between(A1, A2) if is_connected(A1, A2)
%% If rooms are connected and the door between them is open, you can move between them
can_move_between(R1, R2) if is_connected(R1, R2), is_open(D)
%% If doors belong to the same room, you can move between them
can_move_between(D1, D2) if belongs_to(D1, R1), belongs_to(D2, R1)
%% If an area and a door belong to the same room, you can travel to the door
can_move_to(R, D1) if belongs_to(A1, R1), is_connected(D1, R1), has_location(R, A1)
%% If an room and a door belong to the same room, you can travel to the door
can_move_to(R, D1) if is_connected(D1, R1), has_location(R, R1)
%% If an area and a door belong to the same room, you can travel between them
can_move_between(A1, D1) if belongs_to(A1, R1), belongs_to(D1, R1)
%% If a room and a door belong to the same room, you can travel from a door
can_move_to(R, R1) if is_connected(D1, R1), has_location(R, D1), is_open(D1)
%% If you are in a room R2 and A1 is directly in R2, you can travel to A1 directly.
can_move_to(R, A1) if belongs_to(A1, R2), has_location(R, R2)
%% Real things can only have 1 state at a time - inertial_fluent
-has_state(R, S1) if has_state(R, S2), S1!=S2
%% If an something O1 is on something O2, then O1 has the location of O2
has_location(O1, L1) if is_on(O1, S2), has_location(O2, L1), has_surface(O2, S2)
%% If an something O1 is on something O2, and O2 is on something O3, then O1 is above O3.
above(O1, O3) if on(O1, O2), on(O2, O3)
%% If O1 is above O2 and O2 is above O3 then O1 is above O3.
above(O1,O3) if above(O1, O2), above(O2, O3)
%% a object cannot be on itself
-is_on(O1, S2) if has_surface(O2, S2), O1 = O2
%% a object cannot be above itself
-above(O1, O2) is O1 = O2
%% only one object can have a surface
-has_surface(O2, S1) if has_surface(O1, S1)
%% Rules to be added in
%% Only can place on block on another block
%% no block can be placed on a triangular block
%% A table is not a movable object?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Executability constraints
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% do not plan to travel to where you are
impossible travel(R, L) if has_location(R, L)
%% robot can pick up an object if they are at same location
impossible pick_up(R, O) if has_location(R, L1), has_location(O, L2), L1!=L2
%% robot cannot pick up an object if they have it
impossible pickup(R,O) if has_object(R,O)
%% cannot put down an object that is not being held
impossible put_down(R, O, L)if not has_object(R, O)
%% Cannot open door from a distance
impossible open_door(R, D) if -has_location(R, D)
%%Don't plan to open a door when you don't where the agent is
impossible open_door(R, D) if not has_location(R, D)
%% Do not try to open a door if it is open
impossible open_door(R,D) if is_open(D)
%% We can't travel between areas that you can't move between
impossible travel(R, L2) if -can_move_between(L1, L2), has_location(R, L1)
%% cannot put down an object that is not being held
impossible put_down(R, O, L) if -has_object(R, O)
%% robot can only hold one object at a time
impossible pick_up(R,O1) if has_object(R,O2)
%robot cannot pick up an object if there is something on top of it
impossible pick_up(R,O1) if is_on(O2, O1).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% AL ENDS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Not AL but here anyway
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% CWA for defined fluents and actions
-holds(F, I) :- not holds(F, I), #defined_fluent(F)
-occurs(A, I) :- not occurs(A, I)
%% Inertial axioms
holds(F, I+1) :- holds(F, I), not -holds(F, I+1), #inertial_fluent(F)
-holds(F, I+1) :- -holds(F, I), not holds(F, I+1), #inertial_fluent(F)
%% Any inertial fluent that does not hold initially is set to not hold
-holds(F, 0) :- not holds(F, 0), #inertial_fluent(F)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%