A simple and not safety approved elevator simulator with an interactive UI.
- Java 23
- Maven
- Browser
mvn spring-boot:run
- Open Browser
- Navigate to localhost
Specify the number of floors and the elevator types (currently only standard and express) in the application.yaml
:
elevator:
number-of-floors: 4
elevators:
- StandardCar
- StandardCar
- StandardCar
- ExpressCar
This overly complex code but simple simulator was a fun challenge to make the service orchestration purely event driven and executable on a single thread. A REST API exists for rider inputs, but the service includes a registration endpoint for Server Sent Events to receive both service requested cues for the riders and elevator car state updates.
The operation should be similar to real-world elevators.
- Rider on a floor requests service (ServiceRequestEvent)
- Elevator Service selects an acceptable elevator car and dispatches to the floor.
- Car reaches the floor and Cues the Rider for the destination floors.
- Car goes on it's merry way.
ServiceRequestEvent's that cannot be scheduled to a specific car go into a queue that will automatically be checked once a car becomes available.
sequenceDiagram
Web UI->>Controller: What is the elevator configuration?
Controller->>Web UI: Number of floors and elevators
Web UI->>Controller: Register for Rider and Car Events
Web UI->>Controller: Service Requested to floor two
Controller->>Web UI: Service Request Information
Note over Controller: Asynchronously hand off service information and API returns immediately
Controller->>Elevator Service: Car Requested to floor two
Elevator Service->>Controller: Car State Update: Car Moving
Controller->>Web UI: Car Moving
Elevator Service->>Controller: Car Arrived, Need Rider Input
Controller->>Web UI: Cue Rider Input
- This was a fun challenge and could be solved a number of ways. I wanted to see if I could incorporate temporal delays for realism while still processing on a single thread.
- There are little, to no safety/realism checks. I'm sure you can request a floor that doesn't exist.
- Floor requests are only honored when the car responds to the origination floor of a service request. If a rider happens to jump on without pushing a request button, they do not get to select a floor.
- The
StandardCar
will attempt to honor additional service requests as long as they match the direction of the initial service request and the origination floor has not been passed by. - The
ExpressCar
honors only one service request at a time and will travel to all of the floor requests before accepting a new service request. - The cars will wait forever for a user to put in a floor request, probably a bad idea.
- The webpage is loaded on a fresh restart of the application, there is built-in frontend state assumptions of the backend data :grimacing
- Only one webpage may view at a time, there are some elevator button/door state mis-matches when multiple pages have the webpage visible
- Better initialization state page startup and button/door state management so multiple users can access the Web UI at the same time.
- Round Robin or Nearest Elevator Car Selection - currently the list is traversed from first to last, so inevitably the first car gets more requests.
- More Tests
- Better Status Reporting
- App Based Service Requests (set a time and floor for an elevator to be available!)