Distributed AC Optimal Power Flow using Alternating Direction Method of Multipliers (ADMM)
This repository implements a fully distributed optimization framework for coordinating 37 prosumers (households with solar PV, battery storage, and reactive power control) in a distribution network using the ADMM algorithm.
- Overview
- Key Features
- Network Description
- Methodology
- Installation
- Usage
- Results
- Project Structure
- References
- Citation
- License
Modern distribution networks face increasing challenges with high penetration of Distributed Energy Resources (DERs) such as:
- βοΈ Rooftop solar PV
- π Battery energy storage systems
- π Electric vehicles
- π Controllable loads
This project demonstrates a privacy-preserving, distributed optimization approach using ADMM to coordinate these resources while:
- β Maintaining voltage regulation (0.95-1.05 p.u.)
- β Minimizing energy costs through Time-of-Use (ToU) pricing
- β Optimizing battery charging/discharging schedules
- β Reducing PV curtailment
- β Providing reactive power support (Volt-VAR Control)
- Network-level coordinator (utility/DSO) manages voltage and grid constraints
- 37 prosumer-level optimizers make independent decisions
- Consensus achieved through ADMM dual variable updates
- Privacy-preserving: prosumers don't share detailed consumption data
- 24 time periods (12-hour horizon, half-hour intervals)
- Battery scheduling for peak shaving and energy arbitrage
- PV curtailment optimization to avoid overvoltage
- Reactive power dispatch for voltage support
- AC Power Flow accuracy (nonlinear, not DC approximation)
- Voltage regulation: 100% compliance with ANSI C84.1 (0.95-1.05 p.u.)
- Scalability: Linear computation time scaling with network size
- Solver: IPOPT (Interior Point Optimizer) for nonlinear programming
- Time-of-Use pricing integration
- Demand response capability
- Cost savings: 25-35% reduction vs. uncoordinated operation
- Grid export compensation (feed-in tariff)
- Voltage Level: 12.47 kV (primary), 0.48 kV (secondary)
- Topology: Radial distribution network
- Total Buses: 72 (in OpenDSS physical model)
- Load Buses: 37 (active residential loads)
- Total Loads: 46 (37 active + 9 EV chargers commented out)
- Number: 37 households
- PV Capacity: 5-60 kW per household
- Battery: 7.5 kWh capacity, Β±1.75 kW power
- Inverter: Sized at 1.1Γ max(PV), 10% reactive capability
- All prosumers have PV + Battery + VVC capability
The distributed optimization problem is formulated as:
minimize f(x) + Ξ£α΅’ gα΅’(zα΅’)
subject to x = zα΅’, βi
Where:
- x: Network variables (voltages, grid power)
- zα΅’: Prosumer i variables (battery, PV, reactive power)
- f(x): Network cost function (grid energy cost + voltage deviation)
- gα΅’(zα΅’): Prosumer i cost function (energy cost + ADMM penalties)
for iteration k = 1, 2, ..., max_iterations:
# 1. X-update (Network Aggregator)
x^(k+1) = argmin_x { f(x) + (Ο/2)Ξ£α΅’ ||x - zα΅’^k + Ξ»α΅’^k||Β² }
# 2. Z-update (Prosumer Optimizations - Parallel)
for each prosumer i:
zα΅’^(k+1) = argmin_zα΅’ { gα΅’(zα΅’) + (Ο/2)||x^(k+1) - zα΅’ + Ξ»α΅’^k||Β² }
# 3. Ξ»-update (Dual Variables)
Ξ»α΅’^(k+1) = Ξ»α΅’^k + Ο(x^(k+1) - zα΅’^(k+1))
# 4. Check Convergence
if ||x^(k+1) - zα΅’^(k+1)||Β² < Ξ΅:
break- Bus voltages: Vα΅’, ΞΈα΅’
- Grid power: Pβα΅£α΅’πΉ, Qβα΅£α΅’πΉ
- Prosumer injections: Pα΅’, Qα΅’
- Battery: P_bat_charge, P_bat_discharge, SoC
- PV: P_pv, P_curtail
- Reactive: Q_reactive
- Grid: P_import, P_export
# Python 3.8 or higher
python --version
# Required packages
pip install numpy pandas matplotlib seaborn
pip install pyomo
pip install dss-python
# Install IPOPT solver (one of the following):
# Option 1: Using conda (recommended)
conda install -c conda-forge ipopt
# Option 2: Using pip
pip install cyipopt
# Option 3: System package manager
# Ubuntu/Debian:
sudo apt-get install coinor-libipopt-dev
# macOS:
brew install ipoptgit clone https://github.com/yourusername/Custom_Feeder_ADMM.git
cd Custom_Feeder_ADMMimport pyomo.environ as pyo
from pyomo.opt import SolverFactory
solver = SolverFactory('ipopt')
assert solver.available(), "IPOPT solver not available"
print("β
All dependencies installed successfully!")-
Open Jupyter Notebook:
jupyter notebook Custom_Design.ipynb
-
Run All Cells:
- Click
KernelβRestart & Run All - Or run cells sequentially (Shift+Enter)
- Click
-
Expected Runtime:
- OpenDSS baseline: ~5 seconds
- Centralized AC-OPF: ~10 seconds
- ADMM (100 iterations): ~70 seconds
# In Cell 13
n_prosumers = 25 # Change from 37 to any value β€ 37
prosumer_ids = list(range(1, n_prosumers + 1))# In Cell 13
T_periods = list(price_data.index[:48]) # Full 24 hours (48 half-hour periods)# In Cell 15 (Network Model)
rho_P_network = 100.0 # Increase for faster convergence (default: 50.0)
rho_Q_network = 20.0 # Increase for better reactive power consensus (default: 10.0)# In Cell 14 (Prosumer Models)
battery_params = {
'P_max': 3.5, # kW (default: 1.75)
'E_capacity': 15.0, # kWh (default: 7.5)
'eta_charge': 0.95, # efficiency (default: 0.92)
'eta_discharge': 0.95,
'SoC_min': 0.20, # 20% (default: 0.10)
'SoC_max': 0.90, # 90% (default: 0.90)
}| Category | Metric | Value |
|---|---|---|
| Network Scale | Total Prosumers | 37 |
| Network Buses | 38 (37 prosumer + 1 slack) | |
| Time Periods | 24 (0-11.5 hours) | |
| Decision Variables | ~3,360 | |
| Energy Flows | Total Demand | ~450-500 kWh |
| Total PV Available | ~550-600 kWh | |
| PV Curtailment | 20-25% | |
| Grid Dependency | 55-65% | |
| Battery | Total Charged | ~40-45 kWh |
| Total Discharged | ~40-45 kWh | |
| Round-trip Efficiency | ~90-95% | |
| Voltage | Compliance Rate | 100% |
| Min Voltage | 0.95-0.98 p.u. | |
| Max Voltage | 1.02-1.05 p.u. | |
| Economics | Grid Cost (12h) | $20-25 |
| Avg Energy Price | $0.07-0.09/kWh | |
| Cost Savings | 25-35% | |
| Computation | Total Time (100 iter) | ~70 seconds |
| Time per Iteration | ~0.7 seconds | |
| Solver Success Rate | 100% |
β Scalability: Linear scaling - 37 prosumers solved in ~0.7 sec/iteration (vs. 0.47 sec for 5 prosumers)
β Voltage Regulation: Perfect compliance (0/888 violations) across all buses and time periods
β Battery Utilization: Optimal charging during low ToU prices, discharging during peak
β PV Integration: High PV penetration (>100% of demand) managed through coordinated curtailment
β Convergence: ADMM typically converges or stabilizes within 50-100 iterations
Custom_Feeder_ADMM/
βββ Custom_Design.ipynb # Main notebook with full implementation
βββ README.md # This file
βββ Montreal_Custom.dss # OpenDSS network definition
βββ Custom_2xy.csv # Bus coordinates for plotting
βββ LineCodes.DSS # Line impedance parameters
βββ Montreal_BusXY.csv # Bus location data
β
βββ Networks/
β βββ NetworkMontreal.csv # 25 households Γ 48 time periods
β
βββ Households/
β βββ NetworkMontreal/
β βββ 1.csv # Household 1 load/PV profile
β βββ 2.csv # Household 2 load/PV profile
β βββ ... # Up to 36.csv
β
βββ Prices/
β βββ PriceSignal_Montreal.csv # Time-of-Use tariff (48 periods)
β
βββ Results/
β βββ ADMM_Performance_Summary.csv
β βββ ADMM_Convergence_History.csv
β βββ ADMM_Voltage_Results.csv
β
βββ plots/
βββ OpenDSS_Voltage_Analysis.png
βββ ADMM_Convergence_Results.png
βββ Voltage_Comparison_OpenDSS_vs_Pyomo.csv
- Boyd, S., Parikh, N., Chu, E., Peleato, B., & Eckstein, J. (2011). Distributed optimization and statistical learning via the alternating direction method of multipliers. Foundations and Trends in Machine Learning, 3(1), 1-122.
- Erseghe, T. (2014). Distributed optimal power flow using ADMM. IEEE Transactions on Power Systems, 29(5), 2370-2380.
- IEEE Std 1547-2018: Standard for Interconnection and Interoperability of Distributed Energy Resources with Associated Electric Power Systems Interfaces
- ANSI C84.1-2020: Electric Power Systems and EquipmentβVoltage Ratings (60 Hertz)
- OpenDSS: Dugan, R. C., & Montenegro, D. (2020). OpenDSS PVSystem and InvControl Element Models. EPRI.
- Pyomo: Hart, W. E., Laird, C. D., Watson, J. P., Woodruff, D. L., et al. (2017). Pyomoβoptimization modeling in Python (Vol. 67, p. 277). Berlin: Springer.
- IPOPT: WΓ€chter, A., & Biegler, L. T. (2006). On the implementation of an interior-point filter line-search algorithm for large-scale nonlinear programming. Mathematical Programming, 106(1), 25-57.
If you use this code in your research, please cite:
@software{admm_acopf_montreal_2025,
author = {Khan, B.},
title = {{ADMM-based Distributed AC Optimal Power Flow
for Distribution Networks}},
year = 2025,
publisher = {GitHub},
url = {https://github.com/yourusername/Custom_Feeder_ADMM},
note = {Montreal Custom Feeder Case Study with 37 Prosumers}
}This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 B. Khan
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.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Extend to full 48-period day-ahead optimization
- Implement complete IEEE 1547 Q(V) curves
- Add Volt-Watt control (VWC)
- Incorporate uncertainty quantification for PV
- Add electric vehicle (EV) charging optimization
- Implement multi-day rolling horizon optimization
- Create real-time ADMM variant
- Add network reconfiguration capability
Author: B. Khan
Email: [your.email@domain.com]
GitHub: @yourusername
For questions, issues, or collaboration opportunities:
- π« Open an Issue
- π¬ Start a Discussion
- OpenDSS Team at EPRI for the powerful distribution system simulator
- Pyomo Development Team for the flexible optimization modeling framework
- IPOPT Team for the robust nonlinear solver
- Montreal Utility for providing the network topology and load data
β If you find this project helpful, please consider giving it a star! β
Made with β€οΈ and β by B. Khan