An advanced, LLM-controlled power grid simulation system integrating electrical power flow analysis, traffic management, electric vehicle simulation, and Vehicle-to-Grid (V2G) energy trading. Built for Manhattan's power infrastructure with AI-driven scenario orchestration, natural language control, and realistic time-of-day simulations.
🚀 What's New: Unlike traditional grid simulators, this system features LLM-to-Map commands allowing natural language control of the entire simulation, dynamic rush hour scenarios with time-based vehicle patterns, weather integration, and AI-orchestrated time progression.
This project extends the base SumoXPypsa framework with groundbreaking LLM integration that brings unprecedented control and realism:
| Feature | Base SumoXPypsa | This Project (LLM Enhanced) |
|---|---|---|
| Control Interface | Manual API calls | Natural language commands via AI |
| Traffic Patterns | Static vehicle count | Dynamic, time-based vehicle scaling |
| Scenarios | Basic failure testing | Rush hour, weather, time-of-day orchestration |
| Load Modeling | Fixed loads | Temperature-sensitive, time-varying loads |
| System Integration | Separate components | AI-orchestrated unified scenarios |
| User Experience | Technical commands | Conversational, intelligent control |
Example: Instead of making multiple API calls to configure a morning rush hour scenario, simply tell the AI: "Simulate morning rush hour with hot weather" and watch the system intelligently configure vehicles, loads, temperature, and traffic patterns.
- Natural Language Commands: Control the entire system through conversational AI
- "Set time to rush hour and increase temperature to 95°F"
- "Show me morning traffic with 200 vehicles"
- "Simulate a heatwave scenario"
- AI Scenario Orchestration: Chatbot intelligently manages complex scenarios
- Dynamic Time Control: LLM changes time of day, triggering realistic traffic patterns
- Weather Integration: Temperature-based load adjustments and traffic changes
- Smart Suggestions: AI recommends scenarios and system optimizations
- Rush Hour Scenarios:
- Morning Rush (7-9 AM): 200+ vehicles, high commercial loads, EV charging demand
- Midday (11 AM-2 PM): Moderate traffic, peak commercial activity
- Evening Rush (5-7 PM): Maximum vehicle density, residential load surge
- Night (10 PM-6 AM): Minimal traffic, reduced loads, off-peak charging
- Automatic Vehicle Scaling: Vehicle count changes realistically with time of day
- Load Profile Dynamics: Commercial/residential loads follow realistic daily patterns
- Weather-Responsive: Traffic and load adjust based on temperature/conditions
- PyPSA Integration: Real-time DC power flow analysis
- 8 Substations: Realistic Manhattan power infrastructure
- Distribution Network: 13.8kV primary and 480V secondary systems
- Dynamic Load Management: Temperature-sensitive and time-based load balancing
- Scenario-Aware: Grid responds to LLM-commanded scenarios
- SUMO Integration: Eclipse SUMO traffic simulation
- Time-Based Fleet: Vehicle count adapts to time of day (50-250 vehicles)
- Electric Vehicle Fleet: Configurable EV percentage (0-100%)
- Battery Management: SOC-based routing and charging behavior
- Weather-Aware Routing: Traffic patterns adjust to weather conditions
- Bidirectional Energy Flow: EVs provide power back to grid
- Emergency Response: Automatic V2G activation during outages
- Dynamic Pricing: Market-based energy trading
- Revenue Optimization: Maximize EV owner earnings
- Scenario Integration: V2G responds to LLM-triggered events
- LLM Command Interface: Full system control via natural language
- Machine Learning: Demand prediction and optimization
- Scenario Intelligence: AI understands context and makes smart decisions
- Real-time Insights: Grid performance analytics
- Predictive Maintenance: Failure prediction and prevention
- Typo Correction: Smart chatbot understands misspellings and variations
- Glassmorphic Design: Modern, premium UI/UX
- Real-time Visualization: Live map with Mapbox integration
- Scenario Controls: Easy access to preset scenarios (rush hour, heatwave, etc.)
- Interactive Controls: Comprehensive system management
- Time/Weather Display: Live scenario indicators
- Responsive Design: Works on desktop and mobile
# Python 3.8+ required
python --version # Should be 3.8+
# SUMO Traffic Simulator
# Download from: https://eclipse.org/sumo/
# Add SUMO_HOME to your environment variables-
Clone the repository
git clone https://github.com/yourusername/manhattan-power-grid.git cd manhattan-power-grid -
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration -
Run the application
python main_complete_integration.py
-
Open your browser
http://localhost:5000
Control the entire system using natural language through the AI chatbot:
"Set time to morning rush hour"
→ System sets to 8 AM, spawns 200 vehicles, increases commercial loads
"Make it a hot summer day, 95 degrees"
→ Temperature rises, AC loads increase, traffic patterns adjust
"Show me evening traffic with 150 vehicles"
→ Time changes to 6 PM, 150 vehicles spawn, residential loads peak
"Simulate a weekend night"
→ Minimal traffic (50 vehicles), low loads, off-peak mode
"What happens during a heatwave at rush hour?"
→ AI creates combined scenario: high temp + high traffic
- Morning Rush - 7-9 AM, 200+ vehicles, high commercial activity
- Midday Normal - 11 AM-2 PM, moderate traffic, balanced loads
- Evening Rush - 5-7 PM, maximum traffic, residential peak
- Night Quiet - 10 PM-6 AM, minimal traffic, low loads
- Heatwave - 95°F+, maximum AC loads, stressed grid
- Winter Peak - Cold weather, heating loads, reduced EV range
- Weekend - Lighter traffic, shifted load patterns
-
Start Vehicle Simulation
- Click "Start Vehicles" in the control panel OR use chatbot
- Configure EV percentage and battery ranges
- Watch real-time vehicle movement and charging
- Try: "Start 100 vehicles with 80% EVs"
-
Test Power Grid Scenarios
- Click on substations to trigger failures OR use chatbot
- Observe traffic light responses (yellow = caution mode)
- Monitor EV station impacts
- Try: "Fail Times Square substation"
-
Enable V2G Emergency Response
- Fail a substation to create power deficit
- Enable V2G for that substation OR use chatbot
- Watch high-SOC EVs provide backup power
- Try: "Enable V2G for all failed substations"
-
Use AI Analytics
- Access ML dashboard for insights
- Chat with AI assistant for recommendations
- Generate comprehensive system reports
- Try: "Analyze current grid performance"
-
Time & Weather Control ⭐ NEW
- Use chatbot to change time of day
- Set temperature and weather conditions
- Watch system respond with realistic changes
- Try: "Fast forward to evening rush hour"
# In the web interface
EV Percentage: 70% # 70% of vehicles are electric
Battery SOC Range: 20-90% # Battery state of charge range# Automatic V2G activation during emergencies
Emergency Threshold: 90% # Substation loading threshold
V2G Power Rate: 250kW # Power per vehicle
Market Price: $0.15/kWh # Energy trading price┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Web Frontend │ │ Flask Backend │ │ SUMO Simulator │
│ │◄───┤ │◄───┤ │
│ • Mapbox Maps │ │ • REST API │ │ • Vehicle Sim │
│ • Real-time UI │ │ • WebSocket │ │ • Traffic Mgmt │
│ • Controls │ │ • Data Processing│ │ • Route Planning│
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ PyPSA Grid │ │ ML Engine │ │ V2G Manager │
│ │ │ │ │ │
│ • Power Flow │ │ • Demand Pred │ │ • Energy Trade │
│ • Load Analysis │ │ • Optimization │ │ • Market Pricing │
│ • Grid Stability│ │ • AI Insights │ │ • Route Planning │
└─────────────────┘ └─────────────────┘ └─────────────────┘
manhattan-power-grid/
├── 📁 api/ # API endpoints (organized)
├── 📁 core/ # Core system components
│ ├── power_system.py # PyPSA power grid
│ └── sumo_manager.py # SUMO integration
├── 📁 static/ # Web assets
│ ├── styles.css # Main stylesheet
│ └── script.js # Frontend JavaScript
├── 📁 data/ # Data files and configs
├── 📁 docs/ # Documentation
├── 📁 tests/ # Test suites
├── main_complete_integration.py # Main application
├── integrated_backend.py # Backend systems
├── v2g_manager.py # V2G functionality
├── ml_engine.py # ML analytics
├── ai_chatbot.py # AI assistant
├── index.html # Main web interface
└── requirements.txt # Dependencies
GET /api/statusReturns complete system status including vehicles, grid state, and performance metrics.
GET /api/network_stateReturns detailed network topology with real-time component states.
POST /api/sumo/start
Content-Type: application/json
{
"vehicle_count": 10,
"ev_percentage": 0.7,
"battery_min_soc": 0.2,
"battery_max_soc": 0.9
}POST /api/fail/Times%20SquareTriggers substation failure simulation.
POST /api/restore/Times%20SquareRestores failed substation.
POST /api/v2g/enable/Times%20SquareEnables V2G for specified substation.
GET /api/v2g/statusReturns V2G system status and active sessions.
POST /api/ai/chat
Content-Type: application/json
{
"message": "Set time to morning rush hour",
"user_id": "operator_1"
}POST /api/scenario/set
Content-Type: application/json
{
"scenario": "rush_hour_morning",
"temperature": 75,
"vehicle_count": 200
}GET /api/scenario/currentReturns current scenario state (time of day, temperature, active scenario)
# Unit tests
python -m pytest tests/unit/
# Integration tests
python -m pytest tests/integration/
# End-to-end tests
python -m pytest tests/e2e/
# All tests with coverage
python -m pytest --cov=. tests/-
Basic Functionality
# Start system and verify all components load python main_complete_integration.py # Navigate to http://localhost:5000 # Verify map loads and controls respond
-
Vehicle Simulation
# Start SUMO simulation # Spawn 20 vehicles with 80% EVs # Verify vehicles appear on map and charge at stations
-
Grid Failure Response
# Fail Times Square substation # Verify traffic lights turn yellow # Verify EV stations go offline # Enable V2G and verify emergency response
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run the test suite:
pytest - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow PEP 8 for Python code
- Use type hints where appropriate
- Add docstrings for all functions and classes
- Include unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
- Eclipse SUMO - Traffic simulation framework
- PyPSA - Power system analysis library
- Mapbox - Interactive mapping platform
- Flask - Web framework
- OpenAI - AI integration capabilities
- ✅ Complete power grid simulation
- ✅ SUMO vehicle integration with time-based dynamics
- ✅ V2G energy trading
- ✅ LLM-to-Map command interface ⭐
- ✅ Rush hour scenario system ⭐
- ✅ Temperature/weather integration ⭐
- ✅ Time-of-day vehicle scaling ⭐
- ✅ AI scenario orchestration ⭐
- ✅ Advanced AI analytics and chatbot
- ✅ Professional web interface
- 🔄 Multi-day simulation with persistent state
- 🔄 Historical data playback
- 🔄 Custom scenario builder UI
- 🔄 Voice command integration
- 🔄 Mobile app companion
- 🚀 Multi-city support
- 🚀 Distributed grid simulation
- 🚀 Blockchain energy trading
- 🚀 IoT device integration
- 🚀 Digital twin capabilities
- 🚀 Real-world grid data integration
Built with ❤️ for sustainable energy and smart city infrastructure
