8
10execute(A,Sr) :- ask_execute(A,Sr).
11exog_occurs(A) :- ask_exog_occurs(A).
12
13fl(N) :- N=1; N=2; N=3; N=4; N=5; N=6. 14
16prim_action(down). 17prim_action(up). 18prim_action(toggle). 19prim_action(ring). 20prim_action(off(N)) :- fl(N). 21
22exog_action(heat). 23exog_action(cold). 24exog_action(smoke). 25exog_action(reset). 26exog_action(on(N)) :- fl(N). 27
29prim_fluent(floor). 30prim_fluent(temp). 31prim_fluent(fan). 32prim_fluent(alarm). 33prim_fluent(light(N)) :- fl(N). 34
35
37causes_val(up, floor, N, N is floor+1).
38causes_val(down, floor, N, N is floor-1).
39
40causes_val(heat, temp, X, X is temp+1).
41causes_val(cold, temp, X, X is temp-1).
42
43causes_val(toggle, fan, on, fan=off).
44causes_val(toggle, fan, off, fan=on).
45
46causes_val(on(N), light(N), on, true).
47causes_val(off(N), light(N), off, true).
48
49causes_val(smoke, alarm, on, true).
50causes_val(reset, alarm, off, true).
51
53poss(down, neg(floor=1)).
54poss(up, neg(floor=6)).
55poss(off(N), and(floor=N,light(N)=on)).
56poss(toggle, true).
57poss(ring, true).
58
60initially(floor,3).
61initially(temp,2).
62initially(fan,off).
63initially(light(_),off). 64initially(alarm,off).
65
67proc(too_hot, temp>2).
68proc(too_cold, -2>temp).
69proc(below_floor(N), floor<N).
70proc(above_floor(N), floor>N).
71proc(next_floor_to_serve(N), light(N)=on).
72
74proc(go_floor(N), while(neg(floor=N), if(below_floor(N),up,down))).
75proc(serve_floor(N), [go_floor(N), off(N)]).
76proc(control, prioritized_interrupts(
77 [interrupt(and(too_hot,fan=off), toggle),
78 interrupt(and(too_cold,fan=on), toggle),
79 interrupt(alarm=on, ring),
80 interrupt(n, next_floor_to_serve(n), serve_floor(n)),
81 interrupt(above_floor(1), down)]))