2.1 KiB
2.1 KiB
Logic
Details:
Stylised text in green represents the actual lift metaphor
Red represents significant changes to the program
Initial State:
- Lifts all at the bottom of the building
- People all outside the building
- not waiting on an arrow
- not in a lift
Loop:
These are performed simulataneously, with a thread for each instance
-
Lift Thread - this is a black-box as far as the metaphor goes
- While there are people to unload at this floor, unload them
- Call
get_into_lift(Lift, Direction)
, to load people from the apporopriate waiting queue (up | down) from the current floor - Redraw
- Change position
get_into_lift()
- Fetch the correct semaphor for our queue
- Get the number of waiting people on that queue
- While there are people waiting:
- If the lift is empty, change our direction to the supplied direction
- A semaphore is used before the conditional to help ensure the correct value of
in progress
transfers is correct
- While the lift is not full, and we have people waiting:
- Keep track of the number of
in progress
waiting people
- Add a person to the lift.
- Redraw the waiting queue
- Remove the person from the waiting queue
- Signal person to actually get into the lift
- Keep track of the number of
-
Person Thread - this is modelled around the actual metaphor
- Choose a floor to enter
- Decide if the floor is above or below the current position
- Add ourselves to the appropriate move (up | down) group Press the
call elevator
button - Wait for the lift to arrive on the appropriate spot (up | down); no metaphor for this concept
- Enter the lift that is waiting
- Move to the waiting group for the target floor Press the target floor button
- Wait until the lift reaches our destination floor and leave when it is our turn to exit.