Skip to content

MATPOWER: Optimal Power Flow Solvers and Extensible OPF Framework for Power System Research

By Jeff 74 views
MATPOWER OPF Architecture Diagram
MATPOWER OPF Architecture Diagram

MATPOWER is a free, open-source package of MATLAB and GNU Octave M-files for solving power flow and optimal power flow (OPF) problems. Originally developed at Cornell University and now maintained by the Power Systems Engineering Research Center (PSERC), MATPOWER has become the de facto standard simulation environment for power systems researchers and educators worldwide. While many engineers are familiar with its basic power flow capabilities, MATPOWER's extensible OPF framework and its suite of solver interfaces represent a sophisticated platform for tackling real-world grid optimization challenges.

Why MATPOWER for OPF?

Optimal power flow is the backbone of economic dispatch, locational marginal pricing (LMP) calculation, security-constrained unit commitment, and transmission expansion planning. MATPOWER's OPF engine supports both AC and DC formulations, and its architecture is deliberately designed to be extended — allowing users to inject custom cost functions, add user-defined constraints, and interface with state-of-the-art nonlinear programming solvers without modifying the core codebase.

The standard AC OPF minimizes a generation cost objective subject to:

  • Power balance equations (Kirchhoff's laws in polar or rectangular form)
  • Generator real and reactive power limits
  • Bus voltage magnitude bounds
  • Branch thermal (MVA) flow limits

The DC OPF linearizes the AC equations, trading accuracy for speed and convexity — making it suitable for large-scale market clearing and planning studies where thousands of scenarios must be evaluated.

Solver Interfaces: Choosing the Right Backend

MATPOWER Solver Performance Benchmarks

MATPOWER ships with its own interior-point solver, MIPS (MATPOWER Interior Point Solver), which handles medium-scale AC OPF problems reliably out of the box. For larger or more demanding problems, MATPOWER provides clean interfaces to several external solvers:

Solver Type Best Use Case
MIPS (built-in) Primal-dual interior point General AC OPF, up to ~5,000 buses
IPOPT Interior point (open-source) Large-scale AC OPF, sparse Hessians
KNITRO Interior point (commercial) High-accuracy, large-scale NLP
CPLEX / Gurobi LP/QP/MILP DC OPF, unit commitment, MILP extensions
GLPK / linprog LP DC OPF, lightweight deployments

Switching solvers requires only a single option flag:

mpopt = mpoption('opf.ac.solver', 'IPOPT');
results = runopf(mpc, mpopt);

This abstraction allows researchers to benchmark solver performance across test cases without restructuring their models.

The Extensible OPF Framework

MATPOWER's most powerful — and often underutilized — feature is its OPF extension mechanism. Through a set of callback functions, users can augment the standard OPF with:

  1. Custom cost terms — add penalty functions for voltage deviation, reactive power procurement, or network losses directly to the objective.
  2. User-defined constraints — inject linear or nonlinear equality/inequality constraints (e.g., interface flow limits, zonal reserve requirements, carbon emission caps).
  3. Additional variables — introduce new decision variables (e.g., FACTS device settings, storage dispatch levels, demand response quantities) that are co-optimized with generation dispatch.

A typical extension registers callbacks via add_userfcn:

mpc = add_userfcn(mpc, 'formulation', @userfcn_reserves_formulation);
mpc = add_userfcn(mpc, 'int2ext',     @userfcn_reserves_int2ext);
mpc = add_userfcn(mpc, 'printpf',     @userfcn_reserves_printpf);

MATPOWER ships with two production-quality extensions demonstrating this pattern: runopf_w_res (spinning reserve co-optimization) and the MATPOWER OPF with DC lines extension. These serve as templates for building custom market models or security-constrained OPF formulations.

MATPOWER Case Format and Test Systems

All network data is stored in the MATPOWER case format — a MATLAB struct (mpc) with standardized matrices for buses, generators, branches, and costs. This format is widely adopted: the MATPOWER test case archive includes systems ranging from the classic 9-bus and 30-bus IEEE test cases to the 13,659-bus PEGASE European network and the 70,000+ bus synthetic Texas grid (ACTIVSg70k).

Loading and solving a case is intentionally concise:

mpc = loadcase('case118');          % IEEE 118-bus system
results = runopf(mpc);              % AC OPF with default MIPS solver
printpf(results);                   % Formatted results summary

The results struct contains solved bus voltages, generator dispatch, branch flows, Lagrange multipliers (shadow prices), and the total generation cost — all accessible for downstream analysis or export.

Locational Marginal Prices and Sensitivity Analysis

Locational Marginal Prices on IEEE 118-Bus System

For market simulation and planning studies, MATPOWER computes locational marginal prices (LMPs) directly from the OPF dual variables. The LMP at each bus decomposes into energy, congestion, and loss components:

lmp       = results.bus(:, LAM_P);   % $/MWh at each bus
lmp_loss  = results.bus(:, LAM_Q);   % reactive component

MATPOWER also provides DC power flow sensitivity matrices — the Power Transfer Distribution Factors (PTDFs) and Line Outage Distribution Factors (LODFs) — via makePTDF and makeLODF. These are essential for fast contingency screening and zonal market modeling without re-solving the full OPF for each contingency.

MATPOWER Optimal Scheduling Tool (MOST)

MATPOWER MOST 24-Hour Multi-Period Economic Dispatch

For multi-period and stochastic planning problems, the MATPOWER Optimal Scheduling Tool (MOST) extends the single-period OPF into a full unit commitment and economic dispatch framework. MOST supports:

  • Multi-period (hourly to annual) scheduling with ramping constraints
  • Stochastic scenarios for wind/solar uncertainty
  • Energy storage dispatch with state-of-charge tracking
  • Transmission switching and N-1 security constraints

MOST uses the same case format and solver interfaces as the core OPF, making the transition from single-period to multi-period studies straightforward.

Best Practices for Production Studies

Validate your case data first. Use checkpf and case_info to verify bus connectivity, generator limits, and cost function parameters before running OPF. Infeasible cases often stem from tight reactive power limits or disconnected islands.

Use the DC OPF for sensitivity and screening. For large-scale contingency analysis or scenario sweeps, the DC OPF is orders of magnitude faster than AC. Reserve AC OPF for final validation of selected operating points.

Leverage sparse matrix operations. MATPOWER's internal admittance matrix construction (makeYbus) and Jacobian/Hessian routines are fully sparse. Avoid converting these to full matrices in custom code — doing so will dramatically increase memory usage for large systems.

Profile solver performance. For systems above 2,000 buses, compare MIPS against IPOPT using mpoption('verbose', 2) to observe iteration counts and convergence behavior. IPOPT typically outperforms MIPS on ill-conditioned or heavily-loaded systems.

Further Resources

MATPOWER's combination of a clean, well-documented API, a rich test case library, and a genuinely extensible OPF architecture makes it an indispensable tool for power systems researchers and engineers who need a transparent, scriptable platform for grid optimization studies. Whether you are computing LMPs for a market model, benchmarking new OPF algorithms, or building a stochastic planning tool, MATPOWER provides a solid and battle-tested foundation.

Tags: MATPOWER optimal power flow LMP power systems MOST