The Golog Elevator
TO GRASP the nitty-gritty of this program, I’m going to refer you to “Knowledge In Action” by Raymond Reiter, from which this example is taken (minus the graphics). I’ve not altered the Golog portion
of the code with the exception of adding an execute/1
predicate that takes a situation as its argument and proceedes to call the appropriate JavaScript functions to animate the graphical elevator. This is built with
P5.js providing the graphics and Tau-Prolog providing the Prolog that interacts with the JavaScript.
The Golog Elevator
SOME ADDITIONAL suggested queries to play with:
do(open_doors : close_doors, s0, S).
Sequence with no execution.do(control, s0, S), holds(currentFloor(N), S).
Check what floor the elevator is on at completion.do(down(1), s0, S), execute(S).
Execute primitive actionsprimitive_action(A), poss(A, s0), do(A, s0, S), execute(S).
Find a possible action and execute it.do(up(2) # down(2), s0, S), execute(S).
Non-deterministic choice of up or down to floor 2.do(control, s0, S), execute(S).
Run the main control loop.
The Elevator Program
THERE’S PLENTY to parse and play with in here. Firstly there’s some limitations, only the primitive actions declared will have any effect on the graphical elevator when executed as these are the only actions encoded in the JavaScript. This is also the simplest elevator program from the book, with no online planning or exogenous events.
To start playing, start by altering the initial situation (s0): Look for the predicates on(X, s0)
, these you can add, remove and change. Also currentFloor(X, s0)
, you can change this one too.
From there how about we make the elevator safe?
do(up(7), s0, S).
should fail, the top floor is number 6. Try adding a constraint toposs
.do(down(0), s0, S).
should also fail, the bottom floor is number 1.do(open_doors: down(1) # up(6), s0, S).
should fail! You’ll need a new fluent for doors and new conditions.do(open_doors : down(1), s0, do(down(1), do(close_doors, do(open_doors, s0)))).
Would be nice, anif
in the rightproc
can achieve this.
More demo than explanation, but I hope you’ll enjoy playing with a little bit of Golog and consider investigating this fascinating language further.
Until next time, happy gologing. Paul