taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.2.5-6

Exercise 2.2.5-6

not stated yet in Lean solution written

Rating23
KindK5, design an algorithm: give a method for a task, often with a cost bound from the written solution
SectionSection 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 OUT>IN\mathrm{OUT} > \mathrm{IN} and down when OUT<IN\mathrm{OUT} < \mathrm{IN}.

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 NEUTRAL\mathrm{NEUTRAL}, or GOINGUP\mathrm{GOINGUP} and OUT>IN\mathrm{OUT} > \mathrm{IN}, or GOINGDOWN\mathrm{GOINGDOWN} and OUT<IN\mathrm{OUT} < \mathrm{IN}.

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 FLOOR=IN\mathrm{FLOOR} = \mathrm{IN} 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 FLOOR=IN\mathrm{FLOOR} = \mathrm{IN}, D1≠0D1 \ne 0 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 QUEUE[FLOOR]\mathrm{QUEUE}[\mathrm{FLOOR}] 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 D1D1 is set to zero.

The hall buttons stay as they are. When STATE=GOINGUP\mathrm{STATE} = \mathrm{GOINGUP} step E6 clears CALLUP\mathrm{CALLUP} and not CALLDOWN\mathrm{CALLDOWN} 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 GOINGDOWN\mathrm{GOINGDOWN} 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.