• i know designing an elevator is a common System Design problem, but I was motivated to actually look into this after waiting for lots of elevators during my first japan trip

initial thoughts

start basic and naive before optimizing

considering a single elevator for the building

  • naive approach:
    • just FIFO on requests, obviously inefficient
      • IN: floor 1 (wants to go to 9) floor 3 (wants to go to floor 7)
      • OUT: 1397
    • sort by closest floor
      • IN: floor 1 (wants to go to 9) floor 3 (wants to go to floor 7)
      • OUT: 1379
      • problems
        • if super naive, obvi inefficient to keep flipping directions (go up, down, up)
  • thoughts/observations
    • it seems like elevators complete everything in one direction before flipping…?
  • hypothesis
    • priority queue checking
      • direction matches current direction
      • sort by an input request’s starting floor, then input request’s destination floor
    • edge cases
      • consider input requests as [STARTEND]
      • what if we have requests [19, 37] and as the elevator moves, we have a new request [46]? we should stop at floor 4 and 6 before 7 and 9
        • OUT: 134679
      • a request going in the opposite direction (such as 32) is blocked

what about 2 elevators? more complicated when we have multiple elevators available - which to allocate?

  • base case: two unused elevators - arbitrary which to allocate
  • base case: one elevator going up, one unused - allocate unused
  • both elevators higher and going up, new request elevator that finishes highest request first will be sent

what is the optimization goal?

  • minimize energy spent
  • minimize wait times / maximize speed