Optimal Power Flow
OPF · DC-OPF · AC-OPF
Kirchhoff's Laws · Line Limits · LMP Formation
When a generator a thousand kilometres from the load is cheaper than one right next door, should we dispatch it? Only if the transmission network can carry the flow without overheating any line and without violating the physics of alternating current. The optimal power flow (OPF) problem adds grid physics to economic dispatch: Kirchhoff's current law, the nonlinear power-flow equations, line thermal limits, voltage bounds. It is the foundational power-systems optimization problem — formulated by Carpentier in 1962 and still an active research frontier sixty years later.
The problem
Grid physics meets least-cost dispatch
Economic dispatch alone tells us how much each generator should produce to meet load at minimum cost. OPF answers the harder question: given that electricity flows according to Kirchhoff's laws through a network of transmission lines with thermal limits, is the ED solution actually deliverable? If not, the operator must redispatch: force cheap generation down and expensive generation up until the flow pattern respects every line's rating.
There are two main OPF formulations. DC-OPF linearizes the full AC power-flow equations around three standard assumptions: voltage magnitudes equal 1 per-unit everywhere, line resistance is negligible relative to reactance, and voltage-angle differences are small enough that $\sin(\theta_i - \theta_j) \approx \theta_i - \theta_j$. Under these approximations, power flow is a linear function of bus injections, and OPF becomes a linear program (or QP if costs are quadratic). DC-OPF is fast, reliable, and used for day-ahead markets and unit commitment across almost every ISO in the world.
AC-OPF keeps the full nonlinear power-flow equations and tracks both voltage magnitudes and angles on every bus. Active and reactive power are both modeled; voltage bounds and reactive-power limits become binding constraints. The problem becomes a nonconvex nonlinear program (NLP). Solvers use interior-point (Newton-like) or sequential quadratic programming; convergence is not guaranteed and finding a global optimum on meshed networks is provably NP-hard.
In liberalized markets, OPF determines Locational Marginal Prices (LMPs). When the network is unconstrained and every line has slack, all buses have the same LMP and it equals the system marginal cost $\lambda$ — the same $\lambda$ that comes out of economic dispatch. When a line congests, LMPs diverge: buses on the import side of the congestion see high LMPs; buses on the export side see low LMPs. The LMP spread is the dual of the congested-line constraint and measures the economic value of adding transmission capacity — a direct input into expansion-planning models (TEP).
Mathematical formulation
DC-OPF (linear) and AC-OPF (nonconvex)
Notation
| Symbol | Meaning | Units |
|---|---|---|
| $\mathcal{N}$ | Set of buses (nodes) | — |
| $\mathcal{L}$ | Set of transmission lines | — |
| $\mathcal{G}$ | Set of generators | — |
| $b_\ell$ | Susceptance of line $\ell = (i,j)$, equal to $1/x_\ell$ | pu |
| $F_\ell^{\max}$ | Thermal limit of line $\ell$ | MW |
| $D_i$ | Load at bus $i$ | MW |
| $P_g^{\min}, P_g^{\max}$ | Limits of generator $g$ | MW |
| $c_g(p)$ | Cost curve of generator $g$ | $/h |
| $p_g$ | Generator output | MW |
| $\theta_i$ | Bus voltage angle | rad |
| $f_\ell$ | Line flow (DC-OPF) | MW |
| $V_i, \delta_i$ | Bus voltage magnitude and angle (AC-OPF) | pu, rad |
| $p_i^{\mathrm{net}}$ | Net injection at bus $i$, $p_i^{\mathrm{net}} = \sum_{g \in i} p_g - D_i$ | MW |
DC-OPF linearized, LP
Minimize total generation cost subject to the linearized power-flow equations:
subject to:
Line flow — the DC approximation:
Bus balance (Kirchhoff's current law at each bus):
Thermal limits on lines:
Generator limits:
Reference bus (fix one angle to break degeneracy):
With linear or piecewise-linear cost curves, this is a pure LP; with quadratic costs, a convex QP. Either way, polynomial-time and solved by every commercial solver (Gurobi, CPLEX, MOSEK, HiGHS) in seconds for ISO-scale networks (10,000–30,000 buses).
PTDF formulation angle-free DC-OPF
An equivalent DC-OPF representation eliminates the angle variables $\theta$ using the Power Transfer Distribution Factors (PTDFs). Let $H \in \mathbb{R}^{|\mathcal{L}| \times |\mathcal{N}|}$ be the PTDF matrix; each entry $H_{\ell i}$ is the fraction of an MW injected at bus $i$ and withdrawn at the slack that flows through line $\ell$. Then:
PTDFs are computed once from the network susceptance matrix; the resulting LP has only generator outputs as variables (plus slack for line limits) and is usually smaller than the angle-based formulation. Most ISO production solvers use a PTDF-based LP.
AC-OPF nonconvex NLP · Carpentier (1962)
The full AC formulation tracks voltage magnitude $V_i$ and angle $\delta_i$ at every bus. Active and reactive power balance at each bus involve the complex admittance matrix $Y = G + jB$:
Constraints (8)–(9) are nonlinear and nonconvex. Voltage magnitudes are bounded ($V_i^{\min} \le V_i \le V_i^{\max}$), reactive-power limits apply to generators, and line limits now involve apparent power $|S_\ell| \le S_\ell^{\max}$. AC-OPF is NP-hard in general (Lehmann, Grastien, Van Hentenryck, 2016); interior-point codes (IPOPT, KNITRO) find local optima reliably on most real systems but cannot guarantee global optimality.
Convex relaxations Low (2014), Molzahn & Hiskens (2019)
The AC-OPF nonconvexity can often be relaxed to a convex cone program:
- SOCP relaxation (Jabr, 2006): uses variables $c_{ij} = V_i V_j \cos(\delta_i - \delta_j)$, $s_{ij} = V_i V_j \sin(\delta_i - \delta_j)$, and the quadratic equality $c_{ij}^2 + s_{ij}^2 = (V_i V_j)^2$. Relaxed to a second-order cone, this gives a convex program whose optimum is a lower bound on AC-OPF. Low (2014) proved exactness on radial (tree) networks: the relaxation gap is zero.
- SDP relaxation (Bai & Wei, 2008): drops the rank-one constraint on a positive-semidefinite voltage matrix, yielding a tighter but larger convex program.
- QC / moment relaxations: progressively tighter hierarchies that converge to the AC-OPF optimum.
The survey Molzahn & Hiskens (2019) gives a comprehensive comparison: on meshed networks SOCP is loose, SDP is tighter but expensive, and QC is a practical middle ground for research problems up to a few thousand buses.
Complexity
DC-OPF is a convex LP/QP, polynomial-time solvable. AC-OPF is NP-hard in general. Security-constrained OPF (SC-OPF) adds N−1 contingency constraints (one set of flow limits per potential line or generator outage) and is also polynomial if DC, exponentially larger but still tractable via Benders decomposition.
Real-world data
Benchmark networks · test systems
MATPOWER cases
MATPOWER is the standard open-source OPF research platform. Its bundled cases — case9, case14, case30, case57, case118, case300, case2383wp, case13659pegase — range from 9 buses (didactic) to 13,659 buses (European continental grid). Each case has full AC data, generator cost curves, line limits, and voltage bounds. MATPOWER is the source of almost every academic OPF benchmark result published.
PGLIB-OPF benchmark library
The PGLIB-OPF library packages 350+ systems in three operating scenarios (typical operations, congested operations, N−1 secure). Maintained by the IEEE PES Task Force, it is the benchmark standard for AC-OPF research post-2015.
3-bus triangle (this page)
The interactive solver below uses a canonical pedagogical example: a three-bus ring with two generators at buses 1 and 2 and load at bus 3, connected by three equal-reactance transmission lines. The analytical PTDFs are $H_{(1,2) \gets 1} = \tfrac{1}{3}$, $H_{(1,3) \gets 1} = \tfrac{2}{3}$ etc., and the LP has three variables (line flows) plus two generator outputs. Simple enough to solve by hand, rich enough to show LMP formation under congestion.
Interactive DC-OPF solver
3-bus triangle · LMP formation under congestion
Network parameters
Network flows & LMPs
Solution interpretation
What LMPs reveal about the network
When no line is congested, every bus sees the same LMP and it equals the cheapest marginal-cost generator that is unconstrained at max. In the 3-bus triangle, if Gen-1 is cheap and uncongested, LMP at all three buses equals Gen-1's marginal cost. ED and OPF give the same answer.
When line 1–3 binds, Gen-1 cannot supply all of bus 3's load directly; some load at bus 3 must be served by the more expensive Gen-2 via lines 1-2 and 2-3, or directly via line 2-3. The LMP at bus 3 rises to reflect the binding constraint — typically settling at Gen-2's marginal cost or somewhere between Gen-1 and Gen-2 depending on the PTDFs. Gen-1's bus stays at its marginal cost. The LMP spread between buses is the shadow price of the line limit.
Counterflow and loop flow are the subtle things. In a meshed network, injecting at one bus affects every line — a PTDF of 0.3 on line A means 30% of your injection flows there, 70% elsewhere. Sometimes relieving congestion on one line requires increasing counterflow on another. OPF handles this automatically; ED alone cannot.
Over time, persistent LMP spreads tell transmission planners where to build new lines — this is the economic signal feeding TEP. Persistent LMP spread at a generator's bus tells that generator it will earn lower revenue than an unconstrained dispatch would suggest — this feeds GEP and market-participant decision-making.
Extensions & variants
From DC-OPF to contingency-secured, stochastic, distributed
AC-OPF (nonconvex NLP)
Full grid physics: voltage magnitudes, reactive power, apparent-power limits. Solved by interior-point (IPOPT, KNITRO) or sequential convex programming on each PGLIB-OPF case. Local optimality only; no global guarantees on meshed networks.
SOCP / SDP relaxations
Convex relaxations of AC-OPF. SOCP is provably exact on radial networks; SDP is tighter but expensive. A major modern research frontier with deep connections to polynomial optimization and the moment/SOS hierarchy.
Security-constrained OPF (SC-OPF)
Adds N−1 contingency constraints: the schedule must remain feasible after any single line or generator outage. Solved by Benders decomposition with a master OPF plus one subproblem per contingency. Every US ISO's day-ahead market clears an SCOPF.
Chance-constrained OPF (CC-OPF)
Under renewable forecast uncertainty, require that line flows stay below limits with probability $\ge 1-\alpha$. For Gaussian uncertainty the constraints become second-order cones; for general distributions, scenario-approximation or DRO.
Distributed OPF · ADMM
Decompose a large OPF into per-area subproblems coordinated via boundary flow / angle constraints using the Alternating Direction Method of Multipliers. Enables multi-area / multi-ISO dispatch without a centralized optimizer.
AC power flow via machine learning
Train a neural network to predict AC-OPF solutions orders of magnitude faster than interior-point. Post-hoc feasibility projection restores constraint satisfaction. Active 2020+ research frontier with safety-critical caveats.
Key references
Cited above · DOIs and permanent URLs