Exercise · Volume 1 · 2.2.5-6
Exercise 2.2.5-6
not stated yet in Lean solution written
| Rating | 23 |
|---|---|
| Kind | K5, design an algorithm: give a method for a task, often with a cost bound from the written solution |
| Section | Section 2.2.5 of Volume 1 |
The task
Say what must change in coroutines U and E if the elevator has indicator lights, so that people do not get in when its state is against their wish.
The exact wording is in your copy of the book.
Hints
Open one hint at a time. Try the exercise again after each.
Hint 1
A user wants to go up when and down when .
Hint 2
The tests that decide whether a user gets in are in U2, U4 and E4.
Solution
Show the solution
Call a user compatible with the state if the state is , or and , or and .
In step U2, the special treatments when the elevator is on the user's floor, which are reopening the doors at E6 and restarting E4, apply only if and the user is compatible. A user who is not compatible takes the general path, that is, the hall button is pressed.
In step U4 the same condition is used: the user stays only if , and the user is compatible. Otherwise the user may give up as usual.
In step E4, when the elevator looks for a person to let in, only a compatible user of is admitted. In a neutral elevator everybody is admitted. The search runs along the queue from the front and takes the first compatible user. If there is none, the queue counts as empty for E4, and is set to zero.
The hall buttons stay as they are. When step E6 clears and not on the floor, and this fits, since the down-going people did not enter and their call is still needed.
Check
With the changes, in the situation of Table 1 at time 1183 the elevator in state would not admit users 7 and 9, who want to go up, and the extra stop at floor 1 disappears.
Remarks
The text describes the Stanford elevator as having such lights, and its users get in whatever the lights show.
This solution is drafted, and a person has not reviewed it yet. The source.
In Lean
not stated yet The exercise is not stated in Lean yet.
The status is computed from the Lean build. The node of the map.
Something is wrong? Report it.