A comprehensive mixed-integer linear programming (MILP) optimization model for strategic enhancement of the Kitchener-Waterloo Census Metropolitan Area (KWC-CMA) electric vehicle charging network. This project combines real-world data sources, advanced spatial analysis, and multi-objective optimization to recommend optimal charging infrastructure placement and upgrades.
- Optimization of EV Charging Station Network in the Kitchener-Waterloo-Cambridge Region
- Table of Contents
- 1. Project Overview
- 2. Methodology and Data Pipeline
- 3. Technical Implementation
- 4. Getting Started
- 5. Project Structure & Standards
- 6. Contributing
- 7. License
- 8. Sources and Citations
- 9. Appendix: Mathematical Model Formulation
This project develops an optimization model for enhancing the Kitchener-Waterloo-Cambridge Census Metropolitan Area's (KWC-CMA) EV charging infrastructure through comprehensive data analysis and mathematical optimization. The model addresses current infrastructure gaps while planning for future EV adoption trends.
The project covers the entire KWC-CMA region including:
- Major Cities: Kitchener, Waterloo, Cambridge
- Townships: Woolwich, Wilmot, North Dumfries, Wellesley
- Total Area: 1,092.33 km²
- Population: 637,730 (Region of Waterloo Data)
- Key Features: Dense urban cores, suburban areas, rural communities
-
L2 to L3 Conversion
- Identification of high-impact L2 stations for L3 upgrades based on:
- Current utilization patterns
- Grid infrastructure capacity
- Population density and EV ownership
- Implementation feasibility
- Cost-benefit analysis incorporating:
- Installation costs
- Grid upgrade requirements
- Expected usage patterns
- Revenue potential
- L2 port retention costs
- Identification of high-impact L2 stations for L3 upgrades based on:
-
Port retention
- Retains minimum L2 ports for non-L3 compatible vehicles
- Sell excess L2 ports based on L3 space requirements
- Optimize total port capacity
- Balances upgrade costs with equipment resale value
- Preserves charging accessibility for all vehicle types
-
Network Coverage Enhancement
- Population coverage maximization through:
- Demographic-weighted demand analysis
- EV ownership pattern integration
- Multi-modal transit accessibility
- Future growth consideration
- Service area optimization considering:
- Walking distance for urban areas
- Driving distance for L3 chargers
- Transit hub integration
- Grid capacity constraints
- Population coverage maximization through:
-
Infrastructure Optimization
- Data-driven port allocation:
- Usage pattern analysis
- Peak demand consideration
- Grid capacity limits
- Expansion potential
- Location selection based on:
- Population density
- EV ownership patterns
- Transit accessibility
- Grid infrastructure
- Data-driven port allocation:
-
Comprehensive Network Planning Multi-objective optimization balancing:
- Coverage maximization
- Cost minimization
- Grid capacity constraints
- Implementation feasibility
- Phased implementation strategy:
- Priority upgrades
- Coverage gap filling
- Future expansion preparation
-
Implementation Planning
- Phased approach with carefully managed transitions
- Maintains service continuity during upgrades
- Strategic port allocation across network
- Infrastructure readiness assessment
graph TD
A[Data Collection] --> |data_manager.py| B[Raw Data Storage]
B --> C[Data Processing]
subgraph "Primary Data Sources"
D1[OpenChargeMap API]
D2[Region of Waterloo OpenData]
D3[Statistics Canada Census 2021]
D4[Ontario EV Database]
D5[OpenStreetMap]
end
D1 --> A
D2 --> A
D3 --> A
D4 --> A
D5 --> A
subgraph "Processing Pipeline"
C --> E[Population Analysis]
C --> F[Transit Analysis]
C --> G[EV Ownership Pattern Analysis]
C --> H[Infrastructure Assessment]
E --> I[Demand Point Generation]
F --> I
G --> I
H --> I
end
I --> J[Optimization Model]
J --> K[Sensitivity Analysis]
J --> L[Implementation Plan]
The project follows a systematic data collection approach implemented in data_manager.py
:
-
Boundary Data:
- Source: Region of Waterloo Open Data
- Process: UTM Zone 17N projection for accurate measurements
- Validation: Geometric integrity checks, coordinate system verification
-
Charging Infrastructure:
- Source: OpenChargeMap API
- Current Network: 183 stations (169 Level 2, 18 Level 2)
- Details: Port configurations, operator data, power specifications
- Processing: Grid capacity analysis, geocoding validation
-
Potential Locations:
- Source: OpenStreetMap via OSMnx
- Categories: Commercial centers, parking facilities, public venues
- Analysis: Land use compatibility, grid proximity, site suitability
- Scoring: Multi-factor location scoring implemented in
02_location_analysis.ipynb
-
Census Data (2021):
- Sources: Statistics Canada, Region of Waterloo Open Data
- Level: Census tract granularity
- Metrics: Population density, housing characteristics, demographic factors
- Integration: UTM projection alignment, spatial joins
-
EV Ownership Patterns:
- Source: Ontario FSA-level EV database
- Coverage: All KWC-CMA FSA codes
- Processing:
- Density calculations per FSA
- BEV/PHEV ratio analysis
- Spatial distribution mapping
- Growth trend projections
- Source: Grand River Transit Open Data
- Components:
- GRT Bus routes and stops
- ION LRT infrastructure
- Service frequency data
- Coverage area analysis
- Integration: Multi-modal accessibility scoring
Our analysis workflow, implemented across multiple notebooks, processes raw data into optimization inputs:
- Population distribution analysis
- Transit accessibility scoring
- Demographic pattern identification
- Service area calculations
- Identification of upgrade candidates
- Port retention calculations
- Cost-benefit analysis with retained ports
- Grid capacity verification
- Implementation feasibility assessment
- Demand point generation
- Constraint parameter calculation
- Distance matrix computation
- Site suitability scoring
The project creates sophisticated demand points to represent charging needs through a multi-factor analysis.
graph LR
A[Census Tracts] --> |Population Weighting| B[Base Points]
C[Transit Data] --> |Accessibility Score| D[Transit Factor]
E[EV Ownership] --> |Density Analysis| F[EV Factor]
G[Infrastructure] --> |Quality Assessment| H[Infrastructure Factor]
B --> I[Demand Points]
D --> I
F --> I
H --> I
I --> |Score Calculation| J[Final Weighted Points]
- Census tract centroids as initial points
- Population-weighted adjustments
- Density-based clustering
- Service area calculations
- Data from 14 FSA regions in KWC-CMA
- Downscaling to census tract level
- BEV/PHEV ratio consideration
- Growth trend incorporation
- EV Ownership Data (35%)
- Infrastructure quality (25%)
- Base population density (20%)
- Transit accessibility (15%)
- Infrastructure Age (5%)
- Model Type: Multi-Objective Mixed-Integer Linear Programming (MILP)
- Solver: Gurobi Optimizer (Academic WLS License)
- Implementation:
network_optimizer.py
- Key Features:
- Port retention constraints
- Budget-aware planning with resale consideration
- Grid capacity constraints
- Coverage requirements with dual charging types
-
Station Decisions:
- New L2/L3 station placement
- L2 to L3 conversions with port retention
- Station type selection
- Coverage optimization
-
Coverage Analysis:
- Population coverage tracking
- EV owner accessibility
- Service level guarantees
- Future growth accommodation
-
Infrastructure Limits:
- Grid capacity per location
- Maximum stations per area
- Minimum distance requirements
- Port allocation rules
-
Coverage Requirements:
- Minimum population coverage
- EV owner accessibility
- Transit integration targets
- Service redundancy
-
Data Manager (
data_manager.py
):- API integrations (OpenChargeMap, Census)
- Spatial data processing
- Caching mechanisms
- Error handling
-
Preprocessing Steps:
- Coordinate validation
- Missing data handling
- Projection standardization
- Spatial indexing
-
Location Analysis:
- Population density mapping
- Transit accessibility scoring
- Land use compatibility
- Grid capacity assessment
-
Enhancement Analysis:
- Current coverage evaluation
- Upgrade opportunity identification
- Cost-benefit calculations
- Implementation feasibility
-
Input Generation:
- Demand point creation
- Distance matrix computation
- Constraint parameter calculation
- Cost modeling
-
Solution Analysis:
- Coverage metrics
- Financial impact
- Implementation phasing
- Sensitivity testing
graph TD
A[Input Data] --> B[Problem Setup]
B --> C[Initial Solution]
subgraph "Optimization Loop"
C --> D[Coverage Check]
D --> E[Cost Analysis]
E --> F[Grid Constraints]
F --> G[Solution Update]
G --> D
end
G --> |Convergence| H[Final Solution]
H --> I[Implementation Planning]
H --> J[Sensitivity Analysis]
-
Decision Variables:
- Binary variables for station decisions
- Integer variables for port allocation
- Coverage tracking variables
- Cost accounting variables
-
Model Parameters:
- Grid capacity thresholds
- Coverage radius requirements
- Budget constraints
- Minimum port requirements
-
Setup Phase:
- Data structure preparation
- Variable initialization
- Constraint generation
- Objective function formulation
-
Solution Strategy:
- Multi-phase optimization
- Iterative refinement
- Feasibility checking
- Solution validation
-
Geographic Coverage:
- Population accessibility metrics
- EV owner coverage calculations
- Transit integration assessment
- Service gap identification
-
Infrastructure Distribution:
- Charger type analysis
- Port allocation efficiency
- Grid capacity utilization
- Service redundancy evaluation
-
Cost Breakdown:
- Installation expenses
- Infrastructure upgrades
- Grid capacity enhancements
- Operating cost projections
-
ROI Calculations:
- Coverage improvement metrics
- Cost per capita served
- Efficiency improvements
- Long-term value assessment
graph LR
A[Phase 1: L2 to L3 Upgrades] --> B[Phase 2: New L3 Stations]
B --> C[Phase 3: L2 Network]
subgraph "Phase 1"
D[Grid Assessment]
E[Equipment Upgrades]
F[Site Modification]
end
subgraph "Phase 2"
G[Site Selection]
H[Infrastructure Setup]
I[Grid Connection]
end
subgraph "Phase 3"
J[Gap Analysis]
K[New Installations]
L[Network Integration]
end
-
Phase 1: Strategic Upgrades
- Timeframe: Months 1-4
- Focus: L2 to L3 conversions
- Activities:
- Grid capacity upgrades
- Equipment installation
- Site preparation
-
Phase 2: Network Expansion
- Timeframe: Months 5-8
- Focus: New L3 installations
- Activities:
- Site development
- Infrastructure setup
- Grid connections
-
Phase 3: Coverage Enhancement
- Timeframe: Months 9-12
- Focus: L2 network completion
- Activities:
- Gap filling
- Accessibility improvements
- Network optimization
-
Grid Infrastructure:
- Power capacity analysis
- Transformer requirements
- Protection systems
- Monitoring equipment
-
Site Preparation:
- Surface modifications
- Accessibility improvements
- Signage and markings
- Safety features
-
Coverage Visualization:
- Population density heatmaps
- Service area overlays
- Station status indicators
- Implementation phase mapping
-
Analysis Layers:
- EV ownership density
- Transit accessibility
- Grid capacity zones
- Upgrade priorities
-
Performance Metrics:
- Coverage improvements
- Cost efficiency
- Implementation progress
- Service level achievements
-
Analysis Views:
- Geographic distribution
- Financial analysis
- Timeline tracking
- Impact assessment
The model employs a sophisticated port retention strategy during L2 to L3 upgrades:
-
Retention Logic
- Maintains minimum required L2 ports (
min_ports_per_l2
) at upgraded stations, which is reasonably set as1
. - Ensures charging accessibility for non-L3 compatible vehicles
- Balances retention with L3 space requirements
- Maintains minimum required L2 ports (
-
Cost Considerations
- Selective resale of excess L2 ports
- Optimizes between retention benefits and upgrade costs
- Factors in resale value of removed ports
- Considers installation costs for new L3 infrastructure
-
Implementation Impact
- Phased transition that maintains service continuity
- Balanced distribution of charging options
- Future-proof infrastructure development
- Grid capacity optimization
-
Design Rationale
- No assumption of total space availability
- Flexible adaptation to site conditions
- Priority on maintaining service accessibility
- Cost-effective infrastructure evolution
- Python 3.12.7 or higher
- Gurobi Optimizer License
- OpenChargeMap API key
-
Core Data Processing
numpy
pandas
scipy
lxml
scikit-learn
-
Geospatial Analysis
geopandas
pyproj
shapely
osmnx
haversine
-
Optimization
gurobipy
-
Visualization
matplotlib
folium
branca
seaborn
-
API & Network
requests
ratelimit
python-dotenv
fastparquet
-
Progress & Formatting
tqdm
tabulate
-
Jupyter Environment
jupyter
-
Clone repository
git clone https://github.com/username/kw-ev-charging-optimization.git cd kw-ev-charging-optimization
-
Configure API Access
- Obtain an OpenChargeMap API key here
- Acquire Ontario Data Portal access (if necessary)
- Create a file named
.env
in your project root - Set up your API keys as environment variables by placing the following in the
.env
file:OCMAP_API_KEY=<your_api_key_here> # Any other necessary keys in format: <KEY_NAME>=<key>
-
Run setup verification
python src/verify_setup.py
The
verify_setup.py
script automates the setup process by:- Checking and enforcing project-specific virtual environment setup at
PROJECT_ROOT/venv
- Verifying Python version compatibility (requires Python 3.12.7+)
- Installing the project package in editable mode (
pip install -e .
) - Installing all dependencies from
requirements.txt
with proper categorization - Verifying Gurobi license status
- Checking API key configurations
- Testing API connectivity (OpenStreetMap, OpenChargeMap, ROW OpenData)
- Validating source code file structure
- Creating all necessary project directories
The script provides interactive prompts and clear instructions if any setup steps fail or require user action. Follow the on-screen instructions to complete any missing setup requirements.
- Checking and enforcing project-specific virtual environment setup at
- Located in
configs/base.json
- Key parameters:
- Cost factors
- Coverage requirements
- Grid constraints
- Implementation phases
- Located in
configs/scenarios/
- Available scenarios:
aggressive.json
balanced.json
conservative.json
Note
This section is to run the optimization directly on the command line interface. If you would like to visualize and observe the data pipeline working its way through, you can skip to section 4.5.. The following content is just for a quick run.
For a quick run of the optimization model after setting up your cconfigurations in the config\
directory, run the following script.
# Basic run with default configuration
python src/run_optimization.py
# Run with specific scenario
python src/run_optimization.py --scenario balanced
# Run with custom output directory
python src/run_optimization.py --output custom_results
If run successfully, you would get a results package with the following components.
results/
└── results_YYYYMMDD_HHMMSS/
├── config.json
│
├── implementation_plan.json
├── implementation_plan.png
├── implementation_plan.txt
│
├── optimization.log
│
├── program.json
├── program.txt
│
├── sensitivity_analysis.json
├── sensitivity_analysis.png
├── sensitivity_analysis.txt
│
├── solution.json
├── solution.png
├── solution.txt
└── solution_map.html
If the run fails, the error message would be logged in the optimization.log
file. If the file is empty, you have run the script successfully.
Tip
If you want to run the optimization directly, you can check out section 4.4.. The following content is just for visualizing the optimization steps and is not necessary to run the optimization script.
jupyter notebook notebooks/01_data_collection.ipynb
# Execute notebooks in order:
jupyter notebook notebooks/02_location_analysis.ipynb
jupyter notebook notebooks/03_enhancement_analysis.ipynb
jupyter notebook notebooks/04_data_preparation.ipynb
The optimization can also be executed using a Jupyter Notebook. This method emphasizes immediate visualization of results.
Note
This notebook does not include predefined cells or code for saving outputs. However, you can add cells to save your results as needed. Currently, only the optimization script in section 4.4. saves a results pacakge as outlined.
jupyter notebook notebooks/05_optimization_model.ipynb
- Interactive maps showing:
- Current coverage
- Proposed changes
- Implementation phases
- Service areas
- Coverage improvement
- Cost efficiency
- Implementation timeline
- Technical feasibility
ROOT/
├── data/ # Data storage
│ ├── raw/ # Raw data files
│ │ ├── boundaries/ # Geographic boundaries
│ │ ├── charging_stations/ # Station data
│ │ ├── ev_fsa/ # EV ownership data
│ │ ├── population/ # Census data
│ │ └── potential_locations/ # Candidate sites
│ │
│ └── processed/ # Processed datasets
│ ├── demand_points/ # Generated demand points
│ ├── ev_fsa_analyzed/ # Analyzed EV data
│ ├── integrated_analyzed_data/ # Combined analysis
│ └── optimization_inputs/ # Model inputs
│
├── notebooks/ # Analysis notebooks
│ ├── 01_data_collection.ipynb
│ ├── 02_location_analysis.ipynb
│ ├── 03_enhancement_analysis.ipynb
│ ├── 04_data_preparation.ipynb
│ └── 05_optimization_model.ipynb
│
├── src/ # Source code
│ ├── run_optimization.py # Run model on the terminal
│ ├── verify_setup.py # Verify environment setup
│ │
│ ├── data/ # Data processing
│ │ ├── constants.py # Project constants
│ │ ├── data_manager.py # Data handling
│ │ └── utils.py # Utility functions
│ │
│ ├── model/ # Optimization model
│ │ ├── network_optimizer.py # Core optimizer
│ │ └── utils.py # Model utilities
│ │
│ └── visualization/ # Visualization tools
│ ├── map_viz.py # Mapping functions
│ └── optimization_viz.py # Result visualization
│
├── configs/ # Configuration files
│ ├── base.json # Base configuration
│ └── scenarios/ # Scenario configs
│
├── tests/ # Unit tests
│
├── requirements.py
└── setup.py
- PEP 8 compliance
- Type hints for all functions
- Comprehensive docstrings
- Clear variable naming
- Exception handling patterns
- Function documentation:
- Purpose and description
- Parameter types
- Return values
- Example usage
- Module documentation:
- Purpose
- Dependencies
- Key classes/functions
- Usage examples
-
Data Loading Errors:
- Check API key configuration
- Verify file paths in constants.py
- Ensure proper data directory structure
- Validate input file formats
-
Optimization Issues:
- Verify Gurobi license
- Check constraint feasibility
- Monitor memory usage
- Review problem scale
-
Visualization Errors:
- Confirm coordinate systems
- Check projection transformations
- Verify data completeness
- Monitor memory constraints
-
Data Processing:
- Use spatial indexing
- Implement caching
- Optimize queries
- Batch processing
-
Model Performance:
- Problem decomposition
- Parameter tuning
- Memory management
- Solution warm-starting
- Regular data refresh schedule
- Validation procedures
- Version control
- Backup protocols
- Parameter calibration
- Constraint updates
- Objective function tuning
- Solution validation
- Code changes
- Configuration updates
- New features
- Bug fixes
Please see CONTRIBUTING.md for detailed contribution guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Region of Waterloo Open Data
- OpenChargeMap API
- OpenStreetMap via OSMnx
- Statistics Canada
- Ontario Data
- Grand River Transit Open Data
- HoneyBadger Charging Inc. (January 2024): Cost to Install an EV Charger at Home
- TCA ELectric (July 25, 2023): Level 2 vs Level 3 EV Charging
- SparkCharge (May 2023): EV Charging Station Infrastructure Costs and Breakdown
- Future Energy (August 11, 2022): What Does a Level 3 Charger Cost?
- HydroOne (December 10, 2021): Kitchener-Waterloo-Cambridge-Guelph Regional Infrastructure Plan
- HydroOne (May 2024): Kitchener-Waterloo-Cambridge-Guelph Regional Planning
- IESO (May 6, 2021): Kitchener-Waterloo-Cambridge-Guelph Region Integrated Regional Resource Plan
- IESO (May 6, 2021): Kitchener-Waterloo-Cambridge-Guelph Region Integrated Regional Resource Plan Appendices
The optimization model is formulated as a mixed-integer linear program:
We have the following data sets from our data collection .
Set | Description |
---|---|
Set of potential locations, |
|
Set of demand points, |
|
Set of existing Level 2 stations (upgrade candidates) | |
Set of existing Level 3 stations | |
Set of potential locations within the Level 2 coverage radius of demand point |
|
Set of potential locations within the Level 3 coverage radius of demand point |
Symbol | Meaning |
---|---|
Normalized population weight at demand point |
|
Coverage radius for Level 2 stations | |
Coverage radius for Level 3 stations | |
Minimum required Level 2 coverage | |
Minimum required Level 3 coverage |
Symbol | Meaning |
---|---|
Cost of new Level 2 station | |
Cost of new Level 3 station | |
Cost per Level 2 port | |
Cost per Level 3 port | |
Resale value factor | |
Total available budget |
Symbol | Meaning |
---|---|
Minimum ports per Level 2 station | |
Minimum ports per Level 3 station | |
Power requirement per Level 2 port | |
Power requirement per Level 3 port | |
Grid capacity at site |
Variable | Indices | Type | Bounds | Meaning |
---|---|---|---|---|
Binary | Install new Level 2 station at site |
|||
Binary | Install new Level 3 station at site |
|||
Binary | Upgrade existing Level 2 station |
|||
Binary | Demand point |
|||
Binary | Demand point |
We cannot place a new Level 2 station as well as a new Level 3 station at the same potential location.
Our budget needs to be able to accommodate new Level 2 stations, new Level 3 stations, as well as Level 2 stations being upgraded to Level 3. This would also account for their individual charging port installations.
All demand points being covered by stations offering Level 2 charging ports. This would include Level 2 stations upgraded to Level 3 standards, since they would retain at least one Level 2 charging port.
All demand points being covered by stations offering Level 3 charging ports. This would include Level 2 stations upgraded to Level 3 standards.
The individual coverages calculated according to the wights assigned to the deman points should meet the minimum coverage requirements outlined in our parameters.
The power needs of station placements (calculated depending on the quantity of charging ports it offers) should not exceed the grid capacity offered by the region.
We know we have the total cost function,
So, we can incorprate all of our data to formulate our multi-objective function as a
We can turn this into a weighted linear function as a