A simple elevator system implementation in Go that simulates multiple elevators serving multiple floors.
- Multiple elevator support
- Smart elevator selection based on proximity and direction
- Handles both pickup and dropoff requests
- Tracks number of people in each elevator
- Supports up and down movements
- Maximum capacity per elevator
-
Lift (Elevator)
- Tracks current floor, direction, and stops
- Manages pickup and dropoff points
- Handles movement logic
- Maximum capacity: 10 people
-
LiftManager
- Manages multiple elevators
- Handles new lift requests
- Selects the most appropriate elevator for each request
- Coordinates elevator movements
// Initialize system with 6 floors and 2 elevators
manager := NewLiftManager()
manager.Init(6, 2)
// Request elevator from floor 0 to floor 3
elevatorId := manager.RequestNewLift(0, 3)
// Move elevators one tick
manager.Tick()
// Get current state of all elevators
states := manager.GetLiftStates()RequestNewLift(start, dest int) int: Request an elevator from start floor to destination floorTick(): Move all elevators one stepGetLiftStates() []string: Get current state of all elevatorsGetNumberOfPeopleOnLift(liftId int) int: Get number of people in specified elevatorGetLiftsStoppingOnFloor(floor int, dir rune) []int: Get elevators stopping at specified floor
go build
./elevator-design