A world-class, real-time 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 advanced AI analytics and machine learning optimization.
Watch the full system demonstration on YouTube:
🔗 Watch Demo: Manhattan Power Grid Simulation - Electric Vehicles, V2G & AI Analytics
See the system in action with live power flow analysis, EV simulation, V2G emergency response, and AI-powered grid management.
- PyPSA Integration: Real-time DC power flow analysis
- 8 Substations: Realistic Manhattan power infrastructure
- Distribution Network: 13.8kV primary and 480V secondary systems
- Load Management: Dynamic load balancing and optimization
- SUMO Integration: Eclipse SUMO traffic simulation
- Electric Vehicle Fleet: Configurable EV percentage (0-100%)
- Battery Management: SOC-based routing and charging behavior
- Real-time Tracking: Live vehicle positions and battery states
- 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
- Machine Learning: Demand prediction and optimization
- Real-time Insights: Grid performance analytics
- Predictive Maintenance: Failure prediction and prevention
- Interactive Chatbot: AI assistant for grid operations
- Glassmorphic Design: Modern, premium UI/UX
- Real-time Visualization: Live map with Mapbox integration
- Interactive Controls: Comprehensive system management
- Responsive Design: Works on desktop and mobile
- Python: 3.8 or higher
- RAM: 8GB minimum (16GB recommended)
- Storage: 2GB free disk space
- OS: Windows 10+, macOS 10.14+, or Linux (Ubuntu 20.04+)
- Browser: Chrome, Firefox, Safari, or Edge (latest versions)
# Python 3.8+ required
python --version # Should be 3.8+
# SUMO Traffic Simulator (1.15.0+)
# See installation instructions below for your OS
Windows:
- Download the installer from Eclipse SUMO Downloads
- Run the installer and follow the setup wizard
- Add SUMO to your system PATH during installation
macOS:
# Using Homebrew
brew install sumo
Linux (Ubuntu/Debian):
sudo add-apt-repository ppa:sumo/stable
sudo apt-get update
sudo apt-get install sumo sumo-tools sumo-doc
-
Clone the repository
git clone https://github.com/XGraph-Team/SumoXPypsa.git cd SumoXPypsa
-
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
# Create .env file cat > .env << EOF # Server Configuration FLASK_PORT=5000 FLASK_ENV=development FLASK_DEBUG=True # SUMO Configuration SUMO_HOME=/usr/share/sumo # Update with your SUMO installation path # Mapbox Configuration (optional - for enhanced map features) # Get your free token at https://www.mapbox.com/ MAPBOX_API_TOKEN=your_mapbox_token_here # Grid Configuration DEFAULT_EV_PERCENTAGE=0.7 DEFAULT_VEHICLE_COUNT=10 BATTERY_MIN_SOC=0.2 BATTERY_MAX_SOC=0.9 # V2G Configuration V2G_MARKET_PRICE=0.15 V2G_POWER_RATE=250 EMERGENCY_THRESHOLD=0.9 EOF
-
Configure SUMO_HOME (if not automatically set)
# Linux/Mac export SUMO_HOME=/usr/share/sumo # Windows (PowerShell) $env:SUMO_HOME = "C:\Program Files (x86)\Eclipse\Sumo"
-
Run the application
python main_complete_integration.py
-
Open your browser
http://localhost:5000
For enhanced map features with satellite imagery and advanced styling:
- Sign up for a free account at Mapbox
- Navigate to your account dashboard
- Copy your default public token
- Add it to your
.env
file asMAPBOX_API_TOKEN
Note: The application works without Mapbox using OpenStreetMap, but Mapbox provides better visuals and performance.
-
Start Vehicle Simulation
- Click "Start Vehicles" in the control panel
- Configure EV percentage and battery ranges
- Watch real-time vehicle movement and charging
-
Test Power Grid Scenarios
- Click on substations to trigger failures
- Observe traffic light responses (yellow = caution mode)
- Monitor EV station impacts
-
Enable V2G Emergency Response
- Fail a substation to create power deficit
- Enable V2G for that substation
- Watch high-SOC EVs provide backup power
-
Use AI Analytics
- Access ML dashboard for insights
- Chat with AI assistant for recommendations
- Generate comprehensive system reports
# 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 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
SumoXPypsa/
├── 📁 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
├── dashboard-preview.png # Dashboard screenshot
├── requirements.txt # Dependencies
├── .env.example # Environment variables template
└── README.md # This file
GET /api/status
Returns complete system status including vehicles, grid state, and performance metrics.
GET /api/network_state
Returns 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%20Square
Triggers substation failure simulation.
POST /api/restore/Times%20Square
Restores failed substation.
POST /api/v2g/enable/Times%20Square
Enables V2G for specified substation.
GET /api/v2g/status
Returns V2G system status and active sessions.
POST /api/ai/chat
Content-Type: application/json
{
"message": "Analyze grid performance",
"user_id": "operator_1"
}
# 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 follow these 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
type: subject
body (optional)
footer (optional)
Types: feat
, fix
, docs
, style
, refactor
, test
, chore
Example:
feat: add renewable energy integration
- Implemented solar panel simulation
- Added wind turbine models
- Updated power flow calculations
Closes #123
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 XGraph-Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- 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
- ✅ V2G energy trading
- ✅ AI analytics and chatbot
- ✅ Professional web interface
- 🔄 Real-time weather integration
- 🔄 Advanced ML demand forecasting
- 🔄 Multi-city support
- 🔄 Mobile app companion
- 🔄 Renewable energy sources (solar/wind)
- 🚀 Distributed grid simulation
- 🚀 Blockchain energy trading
- 🚀 IoT device integration
- 🚀 Digital twin capabilities
- 🚀 Predictive maintenance AI
- Simulation Capacity: Up to 1000 concurrent vehicles
- Grid Resolution: Real-time updates every 100ms
- V2G Response Time: < 2 seconds for emergency activation
- API Latency: Average < 50ms response time
- Scalability: Horizontally scalable with Docker/Kubernetes
- 📹 Watch Demo Video - Full system demonstration
Built with ❤️ for sustainable energy and smart city infrastructure