🏢 Elevator Dispatch Model - Efficient passenger transportation through precise elevator control algorithms
Visualization Mode (with Web Interface):
start.batHeadless Mode (Algorithm Only):
start_no_gui.batVisualization Mode:
chmod +x start.sh
./start.shHeadless Mode:
chmod +x start_no_gui.sh
./start_no_gui.shThe startup scripts will automatically:
- Check Python version (requires 3.10+)
- Install all dependencies
- Launch the elevator controller
start.batFeatures:
- Launches FastAPI Web server (port 5173)
- Real-time elevator status visualization via WebSocket
- Shows elevator position, direction, passenger queues
- Supports pause, speed control, and other playback features
Access: http://127.0.0.1:5173
Workflow:
GUI Launch
↓
Web Server Startup (FastAPI)
↓
GUIController connects to simulator (registers as "gui" client)
↓
Receives simulator callbacks, pushes real-time data to WebSocket
↓
Frontend displays live elevator movement
start_no_gui.batFeatures:
- Pure algorithm execution, no Web interface
- Directly connects to simulator (registers as "algorithm" client)
- Executes LOOK V2 scheduling algorithm
- Real-time floor decision making for each elevator
Workflow:
Algorithm Launch
↓
LookV2Controller connects to simulator
↓
Immediately starts LOOK V2 algorithm
↓
Dynamically decides next target floor for each elevator
.
├── controller.py # Main entry point - launches GUI or Algorithm based on env var
├── start.bat / start.sh # Launcher (GUI Mode)
├── start_no_gui.bat / start_no_gui.sh # Launcher (Algorithm Mode)
├── CLAUDE.md # Coding standards
├── README.md # This document
│
├── elevator/ # Core modules
│ ├── client/
│ │ ├── api_client.py # HTTP client (communicates with simulator)
│ │ ├── base_controller.py # Controller base class
│ │ ├── gui_controller.py # GUI mode (listen-only)
│ │ └── proxy_models.py # Data proxy objects
│ ├── core/
│ │ └── models.py # Data models and enums
│ ├── utils/
│ │ └── debug.py # Debug utilities
│ └── visualization/
│ ├── web_server.py # FastAPI Web server
│ ├── recorder.py # Simulation recorder
│ └── static/
│ ├── index.html # Frontend page
│ ├── app.js # Frontend logic
│ └── style.css # Styles
│
├── client_examples/ # User-defined algorithm examples
│ └── simple_example.py # Simple algorithm example
│
├── traffic/ # Traffic files
│ └── *.json # Passenger arrival schedules
│
└── requirements.txt # Python dependencies
A real-time decision-making variant of the classic LOOK elevator scheduling algorithm:
- Idle Priority: When elevator is empty, move to the nearest floor with waiting passengers
- LOOK Scanning: When elevator has passengers, follow the scanning direction (up/down)
- Direction Matching: Only pick up passengers going in the current direction
- Natural Cycling: Avoids complex direction switching logic
- Algorithm Controller:
LookV2Controllerincontroller.py - Core Logic:
_select_next_floor_look()method inon_elevator_stopped()
- ✅ No deadlocks
- ✅ Minimized wait times
- ✅ Clean and understandable code
The system supports running two different controllers simultaneously:
Step 1: Launch your visualization
set ELEVATOR_CLIENT_TYPE=gui
python controller.pyStep 2: Launch their algorithm (in another terminal)
cd /path/to/other_repo
set ELEVATOR_CLIENT_TYPE=algorithm
python controller.pyResult:
- Your GUI controller only receives events (listen-only)
- Their algorithm controller controls the elevators
- Web interface (5173) displays their algorithm's results
Step 1: Launch their visualization
cd /path/to/other_repo
set ELEVATOR_CLIENT_TYPE=gui
python controller.py
# Visit their web interfaceStep 2: Launch your algorithm (in another terminal)
set ELEVATOR_CLIENT_TYPE=algorithm
python controller.pyResult:
- Their GUI controller only receives events
- Your algorithm controller controls the elevators
- Their web interface displays your algorithm's results
from elevator.client.base_controller import ElevatorController
from elevator.client.proxy_models import ProxyElevator, ProxyFloor, ProxyPassenger
from elevator.core.models import Direction, SimulationEvent
from typing import List
class MyAlgorithmController(ElevatorController):
"""My custom elevator scheduling algorithm"""
def on_init(self, elevators: List[ProxyElevator], floors: List[ProxyFloor]) -> None:
"""Initialize algorithm"""
print(f"Initialized: {len(elevators)} elevators, {len(floors)} floors")
def on_elevator_stopped(self, elevator: ProxyElevator, floor: ProxyFloor) -> None:
"""Decide next target floor when elevator stops"""
next_floor = self.decide_next_floor(elevator, floor)
elevator.go_to_floor(next_floor)
def on_passenger_call(self, passenger: ProxyPassenger, floor: ProxyFloor, direction: str) -> None:
"""Handle new passenger call"""
pass
def on_elevator_idle(self, elevator: ProxyElevator) -> None:
"""Handle idle elevator"""
pass
def on_passenger_board(self, elevator: ProxyElevator, passenger: ProxyPassenger) -> None:
"""Handle passenger boarding"""
pass
def on_passenger_alight(self, elevator: ProxyElevator, passenger: ProxyPassenger, floor: ProxyFloor) -> None:
"""Handle passenger alighting"""
pass
def on_event_execute_start(self, tick: int, events: List[SimulationEvent],
elevators: List[ProxyElevator], floors: List[ProxyFloor]) -> None:
"""Before event processing"""
pass
def on_event_execute_end(self, tick: int, events: List[SimulationEvent],
elevators: List[ProxyElevator], floors: List[ProxyFloor]) -> None:
"""After event processing"""
pass
def on_elevator_passing_floor(self, elevator: ProxyElevator, floor: ProxyFloor, direction: str) -> None:
"""Optional: handle elevator passing floor"""
pass
def on_elevator_approaching(self, elevator: ProxyElevator, floor: ProxyFloor, direction: str) -> None:
"""Optional: handle elevator approaching floor"""
pass- Place your algorithm in
client_examples/directory - Modify
controller.pyto import your algorithm class - Run
start_no_gui.bat
- Python >= 3.10
- fastapi >= 0.100.0
- uvicorn >= 0.23.0
- websockets >= 11.0.0
- pydantic >= 2.0.0
All dependencies are automatically installed when running the startup scripts.
| Variable | Value | Description |
|---|---|---|
ELEVATOR_CLIENT_TYPE |
gui |
Launch visualization mode |
ELEVATOR_CLIENT_TYPE |
algorithm |
Launch algorithm mode |
ELEVATOR_SERVER_URL |
Default: http://127.0.0.1:8000 |
Simulator server address |
- Check if Python process is running
- Ensure port 5173 is not in use
- Check firewall settings
- Open browser developer tools (F12) to check Console for errors
- Confirm simulator service is running (usually at http://127.0.0.1:8000)
- Check network connection
- Look for connection errors in command line output
- Ensure both controllers are connected to the same simulator
- Verify correct client type registration (gui or algorithm)
- Check command line logs for error messages
See also:
CLAUDE.md- Coding standards and design principles- Code comments - Key functions have detailed explanations
MIT License - See LICENSE file for details
Made with ❤️ by the Team