---
title: Optimal power flow and locational prices
heading: Adding the network to economic dispatch, congestion when a line reaches its limit, locational marginal prices and congestion rent, a three-bus case where the price exceeds every generator's cost, and unit commitment
eyebrow: S10 · Lesson 29 · Optimal power flow and locational prices
xp: 50
---

::: hook
Economic dispatch (lesson 27) ignores the wires: it would happily send all the power from the cheapest plant even if the line from it can't carry that much. Optimal power flow adds the network's limits, and when a line congests, power at different buses stops having the same value. Markets such as PJM, ERCOT and MISO publish a separate price at every node, every five minutes, computed exactly this way. Those prices can behave in ways that surprise everyone the first time.
:::

::: play
- Two buses: a cheap generator at A (10 dollars per MWh) and an expensive one at B (30 dollars per MWh), with all the load at B and a line of limited rating between them.
- The plot shows the price at bus B against the load. Below the line's rating, all the power comes from A and both prices are 10.
- Above it, the line is full, the extra must come from B's generator, and B's price jumps to 30. The difference times the flow is the congestion rent the line earns.
:::

```sim plot
view: graph
x: D = 0..600 MW
y: price = 0..40
slider: L = 100..500 = 250 MW
plot: 10 + 20*(1 - step(L - D)) | samples: 600 | label: price at B, dollars per MWh
plot: 10 + 0*D | dashed | color: ch3 | label: price at A
readout: B's generator output at 400 MW, MW = (400 - L + abs(400 - L))/2 | digits: 4
readout: total cost at 400 MW, dollars per hour = 10*(400 - (400 - L + abs(400 - L))/2) + 30*(400 - L + abs(400 - L))/2 | digits: 5
```

::: predict
## Three buses joined by identical lines. Generators at bus 1 (20 dollars per MWh) and bus 2 (40 dollars per MWh) serve 300 MW at bus 3, and line 1–3 is limited to 150 MW. What's the price at bus 3?

- [ ] 20 dollars per MWh
- [ ] 40 dollars per MWh
- [ ] 30, the average
- [x] 60 dollars per MWh

::: reveal
To serve one more MW at bus 3 without overloading line 1–3, which carries two thirds of bus 1's output and one third of bus 2's, the dispatch must add 2 MW at bus 2 and back off 1 MW at bus 1: 2 × 40 − 20 = 60. The price at the congested end can exceed every generator's cost.
:::
:::

::: nameit
## Optimal power flow

Minimize total generation cost subject to the power-flow equations, generator limits, line flow limits and voltage limits. The full AC problem is a nonlinear program; markets usually solve a **DC-OPF**, a linear or quadratic program using the DC power flow and PTDFs (lesson 20).

## Locational marginal prices

The **LMP** at a bus is the cost of serving one more MW there, with the network's constraints respected. It splits into an energy part (the reference λ), a congestion part (each binding line's shadow price times the bus's PTDF on it) and a loss part. Without congestion and losses, every LMP equals λ.

## Congestion

When a line is at its limit, cheaper generation behind it can't reach the load, and more expensive generation on the far side must run: **out-of-merit dispatch**. The difference in LMPs across the line times its flow is the **congestion rent**, which in markets goes to holders of transmission rights.

## Unit commitment

Dispatch assumes units are already running. Deciding which units to start, hours to days ahead, is **unit commitment**: a mixed-integer problem with start-up costs, minimum up and down times, ramp limits and reserves. A unit with start-up cost S and a no-load cost h per hour should be shut down for an idle gap longer than S/h hours.
:::

::: example
## In the two-bus case with a 250 MW line, what happens at 400 MW of load?

::: solution
1. **Dispatch.** A sends 250 MW, filling the line, and B's generator supplies the other 150.
2. **Cost.**
   $$\begin{aligned} C &= 250 \times 10 + 150 \times 30 \\ &= 7000 \end{aligned}$$
   dollars per hour, against 4000 without the limit.
3. **Prices.** The prices are 10 at A and 30 at B.
4. **Congestion rent.**
   $$\begin{aligned} R &= (30 - 10) \times 250 \\ &= 5000 \end{aligned}$$
   dollars per hour, a measure of what expanding the line would be worth.

**Answer:** B's generator makes up the last 150 MW, the cost rises to 7000 dollars per hour, and prices split to 10 at A and 30 at B.
:::
:::

::: example
## Solve the three-bus case with the 150 MW limit on line 1–3.

::: solution
1. **Flow on line 1–3.** With identical lines, line 1–3 carries
   $$\tfrac{2}{3}g_1 + \tfrac{1}{3}g_2$$
2. **Apply the limit.** With $g_1 + g_2$ = 300:
   $$100 + g_1/3 \le 150$$
   so $g_1 \le 150$.
3. **Dispatch.** The cheap unit runs at 150, the expensive one at 150, for 9000 dollars per hour. Line 1–2 carries nothing and line 2–3 carries 150.
4. **Prices.** The LMPs are 20 at bus 1, 40 at bus 2 and 60 at bus 3.

**Answer:** each unit runs at 150 MW for 9000 dollars per hour, with LMPs of 20, 40 and 60 at buses 1, 2 and 3.
:::
:::

::: example
## An uncongested line carries 300 MW from a generator at A, priced at 20 dollars per MWh, to bus B. Its losses are $BP^2$ with B = 10⁻⁴ per MW. What's the LMP at B?

::: solution
1. **Marginal losses.**
   $$\begin{aligned} \partial P_L/\partial P &= 2BP \\ &= 0.06 \end{aligned}$$
2. **Power needed at A.** Each extra MW delivered at B needs $1/(1 - \partial P_L/\partial P)$ MW at A.
3. **LMP at B.**
   $$\begin{aligned} \text{LMP}_B &= 20/0.94 \\ &= 21.28 \end{aligned}$$
   dollars per MWh.
4. **What it means.** The marginal-loss component adds 1.28 even with no congestion. Prices at buses far from cheap generation are higher for this reason alone.

**Answer:** 21.28 dollars per MWh.
:::
:::

::: check
given: D = 300 | 450 | 600; L = 150 | 250
answer: D - L
unit: MW
tolerance: 0.5%

## A cheap generator at A sends power over a line rated {L} MW to a {D} MW load at B, where a costlier generator also sits. How much must B's generator produce?

::: right
Right. Whatever the line can't deliver: {answer} MW.
:::

::: misses
- [D] The line still carries its full rating.
- [any] Not yet. Load minus line rating.
:::
:::

::: check
given: a = 12 | 18; b = 30 | 45; L = 150 | 300
answer: (b - a)*L
tolerance: 0.5%

## A congested line carries {L} MW from a bus priced at {a} to one priced at {b} dollars per MWh. What's its congestion rent, in dollars per hour?

::: right
Right. $(\text{LMP}_B - \text{LMP}_A) \times$ flow = {answer}.
:::

::: misses
- [b*L] Only the price difference counts.
- [any] Not yet. Price difference times flow.
:::
:::

::: check
given: a = 10 | 15; b = 30 | 40; D = 400 | 550; L = 200 | 300
answer: a*L + b*(D - L)
tolerance: 0.5%

## A {D} MW load at B is served by a {a} dollars per MWh generator at A through a {L} MW line and by a {b} dollars per MWh generator at B. What's the total cost per hour?

::: right
Right. {L} MW at {a} plus the rest at {b}: {answer} dollars per hour.
:::

::: misses
- [a*D] The line can't carry the whole load.
- [any] Not yet. Fill the line from A, the rest from B.
:::
:::

::: check
given: D = 240 | 300 | 360; L = 110 | 130 | 150
answer: 3*L - D
unit: MW
tolerance: 0.5%

## A triangle of identical lines has generators at buses 1 and 2 and a {D} MW load at bus 3, with line 1–3 limited to {L} MW. What's the most bus 1's generator can produce?

::: right
Right. $\frac{2}{3}g_1 + \frac{1}{3}(D - g_1) \le L$ gives $g_1 \le 3L - D$ = {answer} MW.
:::

::: misses
- [any] Not yet. Line 1–3 carries two thirds of $g_1$ and one third of $g_2$.
:::
:::

::: check
given: a = 15 | 20 | 25; b = 35 | 45
answer: 2*b - a
tolerance: 0.5%

## In the same triangle, with line 1–3 binding, generator 1 costs {a} and generator 2 costs {b} dollars per MWh. What's the LMP at bus 3?

::: right
Right. One more MW at bus 3 takes +2 MW at bus 2 and −1 MW at bus 1: $2b - a$ = {answer} dollars per MWh.
:::

::: misses
- [b] That ignores the counterflow needed to keep line 1–3 within its limit.
- [(a + b)/2] Prices aren't averages; find the dispatch change that keeps the line at its limit.
- [any] Not yet. Keep the flow on 1–3 unchanged while adding 1 MW at bus 3.
:::
:::

::: check
given: S = 5000 | 20000 | 60000; h = 800 | 2500
answer: S/h
unit: h
tolerance: 0.5%

## A unit costs {S} dollars to start and {h} dollars per hour to keep running at minimum output when it isn't needed. Above what idle gap is shutting it down cheaper?

::: right
Right. {answer} hours: shorter gaps aren't worth a restart.
:::

::: misses
- [h/S] Divide the start cost by the hourly cost.
- [any] Not yet. Compare S with h times the gap.
:::
:::

::: check
kind: parts
given: l = 15 | 20 | 30; B = 0.00005 | 0.0001 | 0.0002; P = 100 | 300 | 600

## An uncongested line carries {P} MW from a generator priced at {l} dollars per MWh, with losses $BP^2$, B = {B} per MW.

::: part
answer: 2*B*P
tolerance: 0.5%

### What is the marginal loss factor?

::: misses
- [B*P] The derivative of $BP^2$ is 2BP.
- [any] $\partial P_L/\partial P = 2BP$.
:::
:::

::: part
answer: l/(1 - 2*B*P)
tolerance: 0.5%

### What is the LMP at the receiving bus?

::: misses
- [any] $\lambda/(1 - 2BP)$.
:::
:::
:::

::: check
kind: derivation
vars: L = 10..1000, a = 5..50, b = 10..100, P = 10..2000

## A line at its limit L MW joins a bus priced a to one priced b dollars per MWh, and the receiving bus's load is P MW.

::: step
answer: L*(b - a)

### What congestion rent accrues per hour?
:::

::: step
answer: b*P

### What do the receiving bus's loads pay per hour?
:::

::: right
Right. Congestion rent is the price difference times the flow, collected by the system operator.
:::
:::

::: explain
## How can the price at a bus be higher than the cost of every generator in the system?

::: model
The price at a bus is what it costs the whole system to serve one more megawatt there while keeping every line within its limit. If the line from the cheap generator is already full, the extra megawatt can't come from that generator directly, and if every path from the expensive generator also loads the congested line, the system has to rearrange flows: raise the expensive unit by more than one megawatt and lower the cheap one to create a counterflow on the full line. Paying for two megawatts of expensive power while saving one of cheap power can cost more than either generator's price, and that combined cost is the bus's marginal price.
:::
:::

::: practice

::: check
given: a = 8 | 20; b = 25 | 60; L = 100 | 400
answer: (b - a)*L
tolerance: 0.5%

## Congestion rent (dollars per hour): {L} MW from {a} to {b} dollars per MWh?

::: misses
- [any] Price difference × flow.
:::
:::

::: check
given: a = 10 | 30; b = 40 | 70
answer: 2*b - a
tolerance: 0.5%

## Bus-3 LMP in the binding triangle, costs {a} and {b}?

::: misses
- [any] $2b - a$.
:::
:::

::: check
given: S = 3000 | 40000; h = 500 | 4000
answer: S/h
unit: h
tolerance: 0.5%

## Breakeven idle time: start cost {S}, no-load cost {h} per hour?

::: misses
- [any] S/h.
:::
:::
:::
