A sophisticated autonomous vehicle simulation that demonstrates advanced B-tree data structure usage for real-time sensor data processing and intelligent driving decisions.
- Real-time sensor data indexing using composite keys (car_id * 10000 + timestamp)
- Efficient search and retrieval of surrounding vehicle data
- In-order traversal for chronological data analysis
- Memory-efficient storage with proper node splitting and balancing
- Multi-phase overtaking state machine:
- Detection: Identifies slower vehicles ahead
- Lane Change: Safely changes to overtaking lane
- Acceleration: Increases speed to pass
- Passing: Maintains speed while overtaking
- Return: Safely returns to original lane
- Intelligent lane selection (prefers left lane for overtaking)
- Safety checks using B-tree sensor data for lane clearance
- 3-lane highway with proper lane management
- Traffic signals with realistic timing cycles
- Dynamic vehicle behavior with speed variations and lane changes
- Collision detection and emergency braking
- Realistic physics with proper acceleration/deceleration
- Real-time visualization of all vehicles and lanes
- Live decision display with color-coded status
- B-tree data monitoring showing inserted keys
- Distance tracking over time
- Traffic signal status with visual indicators
pip install streamlit pandas altair# Auto-launch with browser opening
python3 run_app.py
# Or run directly
streamlit run professional_simulation.py# Run comprehensive tests
python3 test_btree.py- Manages B-tree operations for sensor data
- Handles insertions, searches, and traversals
- Maintains chronological order of sensor readings
- Processes B-tree data for decision making
- Identifies surrounding vehicles by lane and distance
- Provides lane clearance checks for safe maneuvers
- Implements intelligent driving decisions
- Manages overtaking state machine
- Handles emergency situations and traffic signals
- Realistic vehicle physics and behavior
- Speed control with acceleration/deceleration
- Lane management and position updates
Sensor Readings โ B-tree Insert โ Data Processing โ Decision Making โ Vehicle Control
โ โ โ โ โ
JSONL Logs Composite Keys Surrounding Cars State Machine Position Update
key = car_id * 10000 + timestamp- Car ID: Ensures unique identification
- Timestamp: Maintains chronological order
- Scalability: Supports up to 10,000 cars per second
@dataclass
class SensorRecord:
timestamp: int
object_id: int
object_type: str
position: Tuple[float, float, float]
velocity: float
distance_to_our_car: float
lane_id: int- Insert: O(log n) complexity for sensor data insertion
- Search: O(log n) complexity for vehicle lookup
- Traversal: O(n) complexity for chronological data access
- Latest: O(log n) complexity for most recent data
The system includes comprehensive tests covering:
- โ Insert operations with composite keys
- โ Search functionality
- โ In-order traversal
- โ Latest record retrieval
- โ Surrounding vehicle detection
- โ Lane clearance verification
- โ Distance calculations
- โ Decision making logic
- โ Overtaking state machine
- โ Emergency handling
- โ Traffic signal compliance
- 1Hz sensor updates with immediate B-tree insertion
- Sub-second decision making using cached sensor data
- Efficient memory usage with B-tree node management
- Multi-vehicle support with unique identification
- Extensible lane system (currently 3 lanes)
- Configurable parameters for different scenarios
โถ๏ธ Start: Begin the simulation- โธ๏ธ Pause/Resume: Control simulation flow
- ๐ Reset: Restart with fresh state
- Decision Display: Shows current driving action
- B-tree Keys: Displays recent sensor data keys
- Car Status: Real-time vehicle positions and speeds
- Traffic Signal: Current signal state
max_speed: float = 80.0 # Maximum speed (km/h)
acceleration: float = 2.0 # Acceleration (m/sยฒ)
deceleration: float = 4.0 # Deceleration (m/sยฒ)overtaking_distance: float = 100.0 # Detection distance (m)
lane_change_gap: float = 30.0 # Required gap for lane change (m)
overtaking_speed_boost: float = 1.5 # Speed multiplier during overtakingGREEN: 100 ticks # ~10 seconds
YELLOW: 30 ticks # ~3 seconds
RED: 70 ticks # ~7 seconds- Emergency braking when vehicles are too close
- Safe following distance maintenance
- Lane change safety checks using B-tree data
- Traffic signal adherence with proper stopping distances
- Speed limit compliance with realistic acceleration
- Lane discipline with proper lane change procedures
{"timestamp": 123, "object_id": 1, "object_type": "car", "position": [150.0, 0.0, 0.0], "velocity": 50.0, "distance_to_our_car": 50.0, "lane_id": 2}- Professional logs:
logs_professional/readings.jsonl - Timestamped directories for different runs
- Append-only format for data integrity
This simulation demonstrates:
- Data Structures: B-tree implementation and usage
- Algorithms: Search, insertion, and traversal operations
- Real-time Systems: Sensor data processing and decision making
- State Machines: Overtaking maneuver management
- Software Architecture: Modular design with clear separation of concerns
- Machine Learning: AI-based decision making
- Multi-lane highways: Support for more lanes
- Weather conditions: Rain, fog, and visibility effects
- Vehicle types: Trucks, motorcycles, and emergency vehicles
- Network simulation: V2V and V2I communication
Built with โค๏ธ for demonstrating advanced data structures in autonomous vehicle applications