Lab Assignment #2

Elevator

Introduction

In this second assignment, we will use telingo to model an elevator of a building with N>1 floors. We will use the notation seen in class for modelling actions and fluents in temporal scenarios with predicate o(A) meaning "action A has occurred" and predicate h(F,V) meaning "fluent F holds value V". Using that notation, the possible actions the elevator can perform are:
  • move(up) : the elevator moves to the floor immediately above its current level
  • move(down) : the elevator moves to the floor immediately below its current level
  • open : the elevator opens the doors
  • close : the elevator closes the doors
  • rest : this means that the elevator simply does nothing
We will also fix the fluents as follows
  • level : has a value from 0 to N-1 and reflects the current floor of the elevator
  • door : is a value from {open;closed} an reflects the state of the elevator's door
In the initial situation, the elevator is at floor 0 and with the doors open.

The goal of the elevator is attending multiple calls that will go happening along time. We will use the predicate call(F) to represent that somebody has requested a stop at floor F. In the real world, this could happen because somebody waiting outside, pressed the elevator's call button at that floor, or because somebody inside the elevator pressed that floor button. Anyway, call(F) will not distinguish between these two situations.
  • Important: predicate call(F) must be kept true until the call is satisfied, that is, the elevator reaches the floor F and opens its door there. Once this happens, there is no need to maintain call(F) any more.

These are some constraints that the system must mandatorily satisfy:
  • The elevator cannot move up when at floor N-1 or move down when at floor 0
  • We cannot open the doors if they are already open. The same applies for closing the doors: they cannot be already closed.
  • The elevator cannot start moving with the doors open
  • At the final situation, there must be no remaining calls

On the other hand, these are some policies to obtain a more reasonable behaviour:

  • If you close the doors, it is for resting or moving
  • If there is a pending call, you cannot rest
  • Do not move in a direction if there are no pending calls towards it
  • If you have a call at the current level, do not delay it
  • Do not open the doors in a floor if there was no call before or there is no call now

What to do

Input files will contain a fragment of telingo code describing a sequence of calls. As an example:

#const floors=5.
#program initial.
&tel { &true ;> &true ;> call(2) ;> &true ;> call(4) ;> &true ;> &true ;> call(0) }.

describes a building of 5 floors and a trace where we have a call(2) at situation 2, call(4) at situation 4 and call(0) at situation 7. Another possible way to describe these sequences is, for instance:

#const floors=10.
#program initial.
&tel {
1> call(9)
& 5> call(2)
& 8> call(0)
& 10> call(5)
}.

where the construction "5>" means "at state 5" and so on. The two examples above can be downloaded as files dom01.lp and dom02.lp, respectively. You can also try example dom03.lp.

Encode the problem in telingo in a file called elevator.lp. You can use

telingo 0 elevator.lp dom01.lp

to obtain all the answer sets. In general, you may get multiple solutions: especially, if you don't implement all the policies recommended above. To visualize a given answer set, you may save the telingo output to a file plan01.txt and use the python visualizer elevator.py (that uses library pygame) as follows:

telingo --verbose=0 elevator.lp dom01.lp > plan01.txt
python elevator.py plan01.txt --floors 5

The visualizer will allow you to move back and forward along the trace. It is important that the telingo output shows all instances of predicates o/1, h/2 and call/1. Three examples of plan files are plan01.txt, plan02.txt and plan03.txt respectively corresponding to domains dom01.lp to dom03.lp.

Assessment & delivery

The maximum grade for this exercise is 10 points = 10% of the course. The deadline for delivery is Friday, December 11th, 2026 using the MOODLE assignment in each University. Exercises can be made by groups of 2 students at most. If so, only one student is required to deliver the files in moodle, but all source files must contain the names of the two group members.

Delivery: upload all files in a .zip including a README.txt with the student names and any additional comment you consider relevant.




Maintained by Pedro Cabalar