-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM.lisp
574 lines (511 loc) · 12.1 KB
/
FM.lisp
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
(asdf:operate 'asdf:load-op 'ae2sbvzot)
(use-package :trio-utils)
; List of avaialble positions in the Map.
; Such list of positions can be seen as a 5x5 grid
; due to the definition of the adjacency
;
; 0, 1, 2, 3, 4
; 5, 6, 7, 8, 9
; 10, 11, 12, 13, 14
; 15, 16, 17, 18, 19
; 20, 21, 22, 23, 24
;
(defvar pos `(pos_0 pos_1 pos_2 pos_3 pos_4
pos_5 pos_6 pos_7 pos_8 pos_9
pos_10 pos_11 pos_12 pos_13 pos_14
pos_15 pos_16 pos_17 pos_18 pos_19
pos_20 pos_21 pos_22 pos_23 pos_24)
)
; The adjacency matrix of our 5x5 grid.
; Such matrix is used as a definition for the concept adjacency,
; in order to impose constraints on the movement of both Robot and Operator
(setf adjacency (make-array '(25 25)
:initial-contents '(
(0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
(1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0)
(1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0)
(0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0)
(0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0)
(0 0 0 1 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0)
(0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0)
(0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0 0)
(0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0 0)
(0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0 0 0 0)
(0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0)
(0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 1 0 0 0)
(0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0 0)
(0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1 0)
(0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 1 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1)
(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0)
)
)
)
; An utility function to
(defun array-slice (arr row)
(make-array (array-dimension arr 1)
:displaced-to arr
:displaced-index-offset (* row (array-dimension arr 1))
)
)
; Converts an array to list
(defun 2d-array-to-list (array)
(map 'list #'identity array)
)
; wrapper for generating variable name
(defun get_variable_name (prefix suffix) (
read-from-string (format nil prefix suffix))
)
; The Work Station tile and the Global Bin tile,
; respectively pos_20 and pos_4, are not walkable.
; This means that such tiles cannot be the position
; of either the Operator or the Robot
(defvar non_walkable_tiles
(Alw
(&&
(!! (-P- operator_in_pos_20))
(!! (-P- operator_in_pos_4))
(!! (-P- robot_in_pos_20))
(!! (-P- robot_in_pos_4))
)
)
)
; Robot must have at least one position at each time.
; This means that robot_in_pos_i is True for at least one value of i
(defvar at_least_one_robot_position
(Alw
(eval
(append `(||)
(loop for loc in pos collect
`(-P- , (get_variable_name "robot_in_~A" loc))
)
)
)
)
)
; Robot must have one single position at each time.
; This means that robot_in_pos_i is True for no more than one value of i
(defvar one_robot_postion_at_a_time
(Alw
(eval
(append `(&&)
(loop for loc1 in pos
append (loop for loc2 in pos
when (not(eq loc1 loc2))
collect
`(-> (-P- , (get_variable_name "robot_in_~A" loc1))
(!!
(-P- ,(get_variable_name "robot_in_~A" loc2))
)
)
)
)
)
)
)
)
; The robot is either moving o still
(defvar robot_has_moving_state
(Alw
(&&
(|| (-P- robot_still) (-P- robot_moving))
(<-> (-P- robot_still) (!!(-P- robot_moving)))
))
)
; The robot has one and only one of the following direction state:
; - To Global Bin
; - To Work Station
; - No Direction
(defvar robot_has_direction
(Alw
(&&
(|| (-P- direction_to_bin) (-P- direction_to_ws) (-P- no_direction))
(<-> (-P- direction_to_bin) (!!( || (-P- direction_to_ws) (-P- no_direction) )))
(<-> (-P- direction_to_ws) (!!( || (-P- direction_to_bin) (-P- no_direction) )))
(<-> (-P- no_direction) (!!( || (-P- direction_to_ws) (-P- direction_to_bin) )))
))
)
; The Robot is moving if and only if it will be in an adjecent tile at the next time instant
(defvar robot_movement_moving
(Alw
(<-> (-P- robot_moving)
(eval
(append `(||)
(loop for i upto (- (list-length pos) 1)
append (loop for j upto (- (list-length pos) 1)
when (not(eq (nth j(2d-array-to-list (array-slice adjacency i))) 0))
collect
`(&& (-P- , (get_variable_name "robot_in_pos_~A" i))
(Futr
(-P- ,(get_variable_name "robot_in_~A" (nth j pos))) 1
)
)
)
)
)
)
))
)
; The Robot is still if and only if it will be in the same tile at the next time instant
(defvar robot_movement_still
(Alw
(<-> (-P- robot_still)
(eval
(append `(||)
(loop for loc in pos collect
` (&& (-P- , (get_variable_name "robot_in_~A" loc))
(Futr
(-P- ,(get_variable_name "robot_in_~A" loc)) 1
)
)
)
)
)
)
)
)
; Operator must have at least one position at each time.
; This means that operator_in_pos_i is True for at least one value of i
(defvar at_least_one_operator_position
(Alw
(eval
(append `(||)
(loop for loc in pos collect
`(-P- , (get_variable_name "operator_in_~A" loc))
)
)
)
)
)
; Operator must have one single position at each time.
; This means that operator_in_pos_i is True for no more than one value of i
(defvar one_operator_postion_at_a_time
(Alw
(eval
(append `(&&)
(loop for loc1 in pos
append (loop for loc2 in pos
when (not(eq loc1 loc2))
collect
`(-> (-P- , (get_variable_name "operator_in_~A" loc1))
(!!
(-P- , (get_variable_name "operator_in_~A" loc2))
)
)
)
)
)
)
)
)
; At each time, the operator can either be in the same tile as the previus time instant
; or it can be in an adjecent tile
(defvar operator_movement
(Alw
(eval
(append `(||)
(loop for i upto (- (list-length pos) 1)
append (loop for j upto (- (list-length pos) 1)
when (not(eq (nth j (2d-array-to-list (array-slice adjacency i))) 0))
collect
`(&& (-P- , (get_variable_name "operator_in_pos_~A" i))
(Futr
(||
(-P- ,(get_variable_name "operator_in_~A" (nth j pos)))
(-P- ,(get_variable_name "operator_in_pos_~A" i))
) 1
)
)
)
)
)
)
)
)
; Operator and robot cannot be in the same tile.
; This means that, if i=j, robot_in_pos_i and operator_in_pos_j
; cannot be both true
(defvar no_op_robot_same_tile
(Alw
(eval
(append `(&&)
(loop for loc in pos collect
`(->
(-P- , (get_variable_name "robot_in_~A" loc))
(!! (-P- , (get_variable_name "operator_in_~A" loc)) )
)
)
)
)
)
)
; If the Robot is still if the operator is Adjacent
(defvar still_if_operator_adjacent_or_working
(Alw
(<-> (-P- robot_still)
(eval
(append `(||)
(loop for i upto (- (list-length pos) 1)
append (loop for j upto (- (list-length pos) 1)
when (not(eq (nth j(2d-array-to-list (array-slice adjacency i))) 0))
collect
`(||
(&&
(-P- , (get_variable_name "robot_in_pos_~A" i))
(-P- , (get_variable_name "operator_in_~A" (nth j pos)))
)
(||
(&&
(-P- robot_in_pos_15)
(-P- direction_to_ws)
)
(&&
(-P- robot_in_pos_9)
(-P- direction_to_bin)
)
)
)
)
)
)
)
)
)
)
; When the direction is towards the Work Station and
; the robot is in the tile 15 i.e. the Working Zone,
; at the next time instant the working procedure starts
(defvar when_arrived_in_ws_work
(Alw
(<->
(&&
(-P- direction_to_ws)
(-P- robot_in_pos_15)
)
(&&
(Lasts_ei(-P- working) 6)
)
)
)
)
; Simply the varius phases of working
(defvar working_procedure
(Alw
(&&
(<->
(&&
(!!(Past(-P- working) 1))
(-P- working)
)
(-P- started_working)
)
(<->
(&&
(Past(-P- working) 1)
(!!(Past(-P- working) 2))
(-P- working)
)
(-P- picked_piece_from_local_bin)
)
(<->
(&&
(Past(-P- working) 2)
(!!(Past(-P- working) 3))
(-P- working)
)
(-P- extended_arm_in_ws)
)
(<->
(&&
(Past(-P- working) 3)
(!!(Past(-P- working) 4))
(-P- working)
)
(-P- piece_elaborated)
)
(<->
(&&
(Past(-P- working) 4)
(!!(Past(-P- working) 5))
(-P- working)
)
(-P- arm_retracted_from_ws)
)
(<->
(&&
(Past(-P- working) 5)
(!!(Past(-P- working) 6))
(-P- working)
)
(-P- finished_working)
)
)
)
)
; When the direction is towards the Global Bin and
; the robot is in the tile 9 i.e. the Loading Zone,
; at the next time instant the loading procedure starts
(defvar when_arrived_in_bin_load
(Alw
(<->
(&&
(-P- direction_to_bin)
(-P- robot_in_pos_9)
)
(&&
(Lasts_ei(-P- loading) 6)
)
)
)
)
; Simply the varius phases of loading
(defvar loading_procedure
(Alw
(&&
(<->
(&&
(!!(Past(-P- loading) 1))
(-P- loading)
)
(-P- started_loading)
)
(<->
(&&
(Past(-P- loading) 1)
(!!(Past(-P- loading) 2))
(-P- loading)
)
(-P- arm_extended_in_global_bin)
)
(<->
(&&
(Past(-P- loading) 2)
(!!(Past(-P- loading) 3))
(-P- loading)
)
(-P- picked_piece_from_global_bin)
)
(<->
(&&
(Past(-P- loading) 3)
(!!(Past(-P- loading) 4))
(-P- loading)
)
(-P- arm_retracted_from_global_bin)
)
(<->
(&&
(Past(-P- loading) 4)
(!!(Past(-P- loading) 5))
(-P- loading)
)
(-P- placed_piece_in_local_bin)
)
(<->
(&&
(Past(-P- loading) 5)
(!!(Past(-P- loading) 6))
(-P- loading)
)
(-P- finished_loading)
)
)
)
)
; The working state is active only in pos_15, i.e. the Working Zone
; The loading state is active only in pos_9, i.e. the Loading Zone
(defvar work_and_load_only_in_assigned_zone
(Alw
(&&
(->
(-P- working)
(&&
(-P- robot_in_pos_15)
)
)
(->
(-P- loading)
(&&
(-P- robot_in_pos_9)
)
)
)
)
)
; During working or loading the direction state is no_direction
; and the direction state is no_direction only while working or loading
(defvar no_direction_while_operating
(Alw
(<->
(-P- no_direction)
(||
(-P- working)
(-P- loading)
)
)
)
)
; After working the direction state changes to direction_to_bin
; until the destination is reached which will happen at some point in the future
; After loading the direction state changes to direction_to_ws
; until the destination is reached which will happen at some point in the future
(defvar direction_change
(Alw
(&&
(->
(&&
(Past(-P- working) 1)
(!!(-P- working))
)
(&&
(until_ii (-P- direction_to_bin) (-P- robot_in_pos_9))
(SomF (-P- robot_in_pos_9))
)
)
(->
(&&
(Past(-P- loading) 1)
(!!(-P- loading))
)
(&&
(until_ii (-P- direction_to_ws) (-P- robot_in_pos_15))
(SomF (-P- robot_in_pos_15))
)
)
)
)
)
(ae2sbvzot:zot 50
(yesterday(&&
non_walkable_tiles
at_least_one_robot_position
at_least_one_operator_position
one_robot_postion_at_a_time
one_operator_postion_at_a_time
robot_movement_moving
robot_movement_still
robot_has_moving_state
operator_movement
still_if_operator_adjacent_or_working
no_op_robot_same_tile
robot_has_direction
no_direction_while_operating
direction_change
work_and_load_only_in_assigned_zone
when_arrived_in_ws_work
when_arrived_in_bin_load
working_procedure
loading_procedure
; Starting Conditions
(-P- robot_in_pos_15)
(-P- direction_to_ws)
))
)