Single-Elevator Control Policy for a Four-Stop Building
System DesignModel answerLast updated
Design the scheduling logic for one elevator serving a basement plus three floors, covering objectives, state, dispatch strategy, data structures, and simulation.
The Problem
You are building the control software for a single elevator in a small building. The car stops at exactly four floors: B (basement), 1 (lobby), 2, and 3. There are no other stops.
Your job is to design the scheduling policy: the logic that decides, at every decision point, where the elevator should go next. This is not a hardware or distributed-systems problem — the interesting work is the decision policy, the state it depends on, and how you know the policy is good.
Address each of the following areas:
1. Objectives
What are you optimizing? Name the metrics (wait time, system time, tail latency, starvation), put rough numbers on them where useful, and explain the tensions between them.
2. Physical and operational constraints
What limits does the real world impose? Cover car capacity, travel times, door mechanics, safety interlocks, and anything else the scheduler must respect or treat as a hard boundary.
3. Inputs and internal state
What does the controller observe (calls, position, load, door state, mode signals)? What state does it maintain between decisions?
4. Dispatch strategy
How does the controller pick the next stop? Walk through your baseline algorithm, then layer on refinements: peak-traffic handling, anti-starvation, capacity-aware skipping, idle parking, and any optional enhancements. Justify each refinement with an argument about when it helps and when it is not worth the complexity.
5. Data structures and state machine
What concrete data structures back the logic? Sketch the controller's state machine with its key transitions.
6. Simulation and validation
How would you test that your policy is actually better than a simpler one? Describe the traffic scenarios, metrics, and validation approach.
A strong answer puts numbers on the physics early, spends most of its time on the policy and its trade-offs, and closes with a credible way to measure whether the policy works.
Hints
Hint 1
Start by sizing the physics: how long does a full B→3 round trip take? That number tells you whether routing cleverness or door/stop overhead is the bigger lever.
Hint 2
Think about what the elevator should do when there are no pending calls — the parking decision is one of the highest-value choices in a small building with bursty traffic.
Hint 3
Starvation is a policy correctness property, not just a performance property. Explain how your strategy guarantees every call is eventually served, not just how it usually serves calls quickly.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
How to Frame the Answer
Resist the urge to talk about distributed systems or message queues. This is a four-stop building with one car. The interesting decisions are the dispatch policy, the state machine that drives it, and the simulation that proves it works. A strong answer gets through the physics in two minutes and spends the rest of the time on those three things.
1. Objectives and Their Tensions
Define success with measurable targets before proposing any algorithm:
- Average wait time (AWT): from the moment a passenger presses a hall button to the moment the doors open in the right direction. Target: under 30 s off-peak, under 45 s during rush.
- Average system time: AWT plus the in-car ride. Useful for comparing policies that trade longer waits for shorter rides.
- Tail latency: P95/P99 wait. Set a hard cap — for example, no hall call waits more than 60 s. This is a correctness property as much as a performance one.
- Starvation freedom: every call is served within some finite bound, even under sustained load.
- Secondary: energy (fewer unnecessary starts and stops), door-cycle wear, and passenger comfort (no mid-trip direction reversals).
Tensions to name explicitly:
- Greedy nearest-call minimizes average wait but can starve the end floors (B and 3).
- Strict SCAN bounds tail latency but wastes time traveling to shaft ends where no one is waiting.
- Lobby or basement priority helps burst traffic but penalizes off-peak fairness.
- Skipping a hall call when the car is nearly full reduces in-car crowding but raises wait time for the skipped passengers.
Name these trade-offs before you propose anything — it signals that you understand there is no globally optimal policy.
2. Physical Constraints
Put numbers on the physics early; they drive every later decision.
- Car speed roughly 1 m/s, floor height roughly 3.5 m → about 4 seconds per floor including acceleration.
- Full shaft B→3: about 12 seconds of travel.
- Door open: 2 s. Door close: 3 s. Dwell: 3 s (extended by the light-curtain sensor).
- One stop adds roughly 8 seconds of overhead even if the car barely moves.
- Implication: with only four floors, door and stop overhead dominates travel time. A policy that avoids unnecessary stops matters more than clever routing math.
Safety interlocks are enforced by hardware, not the scheduler. Treat them as axioms: the car cannot move with an unlocked door, doors cannot open unless the car is level at a floor, an overloaded car does not depart. The scheduling layer should never try to reason around these.
Capacity: 8 people / roughly 630 kg. With 60–100 building occupants and up-peak demand of about 1–3 arrivals per minute, the car rarely fills up — but the policy still needs to handle it.
3. Inputs and Internal State
Observed inputs:
- Hall buttons: up-call and down-call at each floor where it makes sense (six physical buttons for B↑, 1↑, 1↓, 2↑, 2↓, 3↓).
- Car buttons: destination selection for each of the four floors.
- Position: current floor or, between floors, the last confirmed floor plus direction.
- Load from the weight sensor (continuous or bucketed: light / normal / near-full).
- Door state: open, closing, closed, obstructed.
- Mode signals: normal, fire recall, independent service, out-of-service.
Internal state the controller maintains:
- Pending calls with timestamps:
car_call[4],hall_up[4],hall_dn[4]. - Committed direction and committed next stop.
- Current state-machine state and active timers.
- A short ring buffer of recent calls by floor and direction, used to estimate traffic mode (up-peak, down-peak, off-peak).
4. Dispatch Strategy
Baseline: LOOK (directional collective)
Keep moving in the committed direction while any car call or same-direction hall call lies ahead. Stop at a floor if it has a car call, or a hall call matching the current direction. At the last pending request in this direction, also pick up an opposite-direction hall call at that same floor if present, then reverse. If nothing is pending, go idle.
LOOK turns around at the last actual request rather than the shaft end (that is what distinguishes it from SCAN). This bounds any call's wait to roughly one full round trip — about 50–60 s in this building — which gives anti-starvation almost for free under normal load.
Refinement 1: Idle parking policy
When the car goes idle, choose where to wait based on the traffic mode:
- Morning / start-of-day: park at floor 1 (lobby) or B (parking garage arrival window).
- Evening down-peak: park at an upper floor.
- Off-peak or uncertain: stay put — an unnecessary trip wastes energy and adds door cycles.
This is the single highest-value refinement in a small building. Cutting one unnecessary floor-crossing from the response to the first peak-hour call saves more average wait than any routing cleverness.
Refinement 2: Capacity-aware skipping
If the weight sensor reports load above roughly 80% of rated capacity, skip same-direction hall calls (leave them latched) and serve them on the return pass. Never skip a car call. This is rarely triggered with 60–100 occupants but important to handle correctly to avoid an overloaded car.
Refinement 3: Starvation aging
Each hall call accumulates age. Once a call's age crosses a threshold (e.g., 45 s), mark it must-serve. After delivering current passengers with in-car destinations, divert directly to the oldest must-serve call regardless of LOOK order. This guarantees the 60 s tail-latency cap even under sustained burst load.
Refinement 4: Peak modes
- Up-peak: after unloading passengers, return directly to 1 or B rather than chasing stray down-calls, unless those calls are aging.
- Down-peak: favor collecting down-calls top-to-bottom.
Estimate the current mode from the ring buffer of recent calls. A simple heuristic (majority of calls originating from lobby in the last 3 minutes) is enough for a four-stop building.
Optional: destination grouping
If the building installs destination-entry panels at each landing, the controller knows where each boarding passenger is going before they enter the car, and can batch passengers with the same destination. With one car and three upper floors this saves at most one or two intermediate stops per trip. Mention it, but validate with simulation before committing to the added UI complexity.
5. Data Structures and State Machine
With only four floors, arrays are the right choice. car_call[4], hall_up[4], and hall_dn[4] each hold an optional timestamp. "Calls ahead in current direction" is a simple O(4) scan. A small min-heap keyed by timestamp covers the starvation check efficiently, though with four floors even a linear scan is fine.
State machine (key states and transitions):
IDLE
└─ call arrives ──────────────────▶ MOVING(dir)
│
├─ can commit to next floor ──▶ DECELERATING
│
DECELERATING
└─ leveled at floor ──────────────▶ DOOR_OPENING
│
DOOR_OPENING
└─ doors fully open ──────────────▶ DWELL
│
DWELL
└─ timer expires & no obstruction ▶ DOOR_CLOSING
│
DOOR_CLOSING
└─ doors locked ──────────────────▶ (run next_target → MOVING or IDLE)
│
obstruction detected ────────────▶ DOOR_OPENING (reopen, nudge after N s)
The scheduling decision (next_target) is evaluated only when the car reaches the "doors locked" state, not continuously. This avoids mid-flight re-routing, which creates comfort problems and complicates safety reasoning.
6. Simulation and Validation
To compare the baseline LOOK policy against its refinements, simulate the following traffic scenarios:
- Off-peak: Poisson arrivals, roughly 1 call per 3 minutes, random origins and destinations.
- Up-peak: bursts of 3–5 arrivals per minute originating at B and 1, targeting upper floors.
- Down-peak: the reverse.
- Bursty: a pulse of 8–10 simultaneous calls to stress the starvation and capacity logic.
Metrics to track per scenario: mean AWT, mean system time, P95 and P99 AWT, maximum observed wait (starvation proxy), and number of door cycles (proxy for wear).
For validation: run each policy at 100× real-time for the equivalent of several workweeks. Compare policies with a two-sample test on mean AWT. Check that no run ever violates the 60 s cap. A useful sanity check is to also hand-trace the deterministic bursty scenario against what you expect the state machine to do — if the simulation and the trace disagree, the simulation has a bug.
Common Mistakes
- Proposing a distributed or microservices architecture for a one-car, four-stop problem.
- Forgetting that the parking decision dominates AWT in lightly loaded small buildings.
- Treating safety interlocks as scheduling concerns rather than hardware axioms.
- Claiming SCAN or LOOK "eliminates starvation" without adding explicit aging — under sustained load, either algorithm can indefinitely defer an end floor if new calls keep arriving in the other direction.
- Proposing destination grouping as a clear win without qualifying it with simulation evidence.