8
10execute(A,Sr) :- ask_execute(A,Sr).
11exog_occurs(_) :- fail.
12
13fl(N) :- N=1; N=2; N=3; N=4; N=5; N=6. 14
16prim_action(down). 17prim_action(up). 18prim_action(off(N)) :- fl(N). 19prim_action(open). 20prim_action(close). 21
23prim_fluent(floor). 24prim_fluent(light(N)) :- fl(N). 25
27causes_val(up, floor, N, N is floor+1).
28causes_val(down, floor, N, N is floor-1).
29causes_val(off(N), light(N), off, true). 30
32poss(down, neg(floor=1)).
33poss(up, neg(floor=6)).
34poss(off(N), and(floor=N,light(N)=on)).
35poss(open, true).
36poss(close, true).
37
39initially(floor,3).
40initially(light(1), off).
41initially(light(2), on).
42initially(light(3), off).
43initially(light(4), off).
44initially(light(5), on).
45initially(light(6), off).
46
48proc(below_floor(N), floor<N).
49proc(above_floor(N), floor>N).
50
52proc(go_floor(N), while(neg(floor=N), if(below_floor(N),up,down))).
53proc(serve_floor(N), [ go_floor(N), open, close, off(N) ]).
54
55proc(handle_reqs(Max), 56 ndet( [?(and(neg(some(n,light(n)=on)),Max>=floor-1)), go_floor(1), open],
57 pi(n, pi(m, [ ?(and(light(n)=on, m is Max-abs(floor-n))),
58 ?(m > 0),
59 serve_floor(n),
60 handle_reqs(m) ] )))).
61
62proc(minimize_motion(Max), 63 ndet( handle_reqs(Max), pi(m, [?(m is Max+1), minimize_motion(m)]))).
64
65proc(dumb_control, minimize_motion(0) ). 66proc(smart_control, search(minimize_motion(0)) ).