2021-04-27 20:34:24 +12:00

2.0 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

    1. While there are people to unload at this floor, unload them
    2. Call get_into_lift(Lift, Direction), to load people from the apporopriate waiting queue (up | down) from the current floor
    3. Redraw
    4. Change position
  • get_into_lift()
    1. Fetch the correct semaphor for our queue
    2. Get the number of waiting people on that queue
    3. While there are people waiting:
      1. If the lift is empty, change our direction to the supplied direction
      2. While the lift is not full, and we have people waiting:
        • Keep track of the number of in progress waiting people
        1. Add a person to the lift.
        2. Redraw the waiting queue
        3. Remove the person from the waiting queue
        4. Signal person to actually get into the lift

  • Person Thread - this is modelled around the actual metaphor

    1. Choose a random floor to enter
    2. Decide if the floor is above or below the current position
    3. Add ourselves to the appropriate move (up | down) group Press the call elevator button
    4. Wait for the lift to arrive on the appropriate spot (up | down); no metaphor for this concept
    5. Enter the lift that is waiting
    6. Move to the waiting group for the target floor Press the target floor button
    7. Wait until the lift reaches our destination floor and leave when it is our turn to exit.