Economic dispatch¶
A power system must meet the electricity demand at every hour. Each generating unit burns fuel at a cost that rises with its output, and the units differ in cost and limits. Economic dispatch decides how much each running unit produces, so that the total output meets the demand at the lowest total fuel cost.
This example solves two classic test systems:
| System | Units | Demand | Features | Best known cost |
|---|---|---|---|---|
| Gaing (2003) | 6 | 1263 MW | transmission losses, ramp rate limits, prohibited operating zones | 15449.90 $/h |
| Sinha et al. (2003) | 13 | 1800 MW | valve-point effects | 17963.83 $/h |
The 6-unit data were checked against Gaing's paper, with the loss constant B00 = 0.0056 of his 2004 correction. The 13-unit data are from the paper as reprinted in open sources. Both were checked against the published solutions: both models give the published cost of the best known solution. Some papers report lower costs for the 6-unit system, but their solutions fall short of the demand plus losses.
6 units with losses and prohibited zones¶
The variable is the output of each unit, a Real vector between its limits. The ramp rates limit how far a unit can move from its output in the previous hour, so they narrow the limits for this hour. The objective returns three things (see Objectives and constraints):
- the fuel cost,
- inequality constraints
g <= 0: for each prohibited zone, how far the unit runs inside it (negative when outside), - an equality constraint
h = 0: total output minus demand minus losses. The losses depend on the outputs through Kron's formula.
import numpy as np
import ypea
demand = 1263.0 # MW
# fuel cost of each unit: a + b P + c P^2 in $/h, with its output P in MW
a = np.array([240, 200, 220, 200, 220, 190.0])
b = np.array([7.0, 10.0, 8.5, 11.0, 10.5, 12.0])
c = np.array([0.0070, 0.0095, 0.0090, 0.0090, 0.0080, 0.0075])
# output limits for this hour, after the ramp rate limits
lower = np.array([320, 80, 100, 60, 100, 50.0])
upper = np.array([500, 200, 265, 150, 200, 120.0])
# prohibited operating zones: two ranges per unit where it must not run
zones = [
[(210, 240), (350, 380)],
[(90, 110), (140, 160)],
[(150, 170), (210, 240)],
[(80, 90), (110, 120)],
[(90, 110), (140, 150)],
[(75, 85), (100, 105)],
]
# transmission loss coefficients (Kron's formula), per unit on a 100 MVA base
B = np.array([
[0.0017, 0.0012, 0.0007, -0.0001, -0.0005, -0.0002],
[0.0012, 0.0014, 0.0009, 0.0001, -0.0006, -0.0001],
[0.0007, 0.0009, 0.0031, 0.0000, -0.0010, -0.0006],
[-0.0001, 0.0001, 0.0000, 0.0024, -0.0006, -0.0008],
[-0.0005, -0.0006, -0.0010, -0.0006, 0.0129, -0.0002],
[-0.0002, -0.0001, -0.0006, -0.0008, -0.0002, 0.0150],
])
B0 = 1e-3 * np.array([-0.3908, -0.1297, 0.7047, 0.0591, 0.2161, -0.6635])
B00 = 0.0056
def dispatch(sol):
power = sol.power
cost = np.sum(a + b * power + c * power**2)
# inequalities (<= 0): how far a unit runs inside a prohibited zone
inside = []
for unit in range(6):
for low, high in zones[unit]:
inside.append(min(power[unit] - low, high - power[unit]))
# equality (= 0): generation covers the demand and the losses
p = power / 100 # per unit
losses = 100 * (p @ B @ p + B0 @ p + B00)
balance = np.sum(power) - demand - losses
return cost, inside, [balance]
problem = ypea.Problem(ypea.Real("power", lb=lower, ub=upper), dispatch, name="6 units")
result = ypea.LSHADE(max_nfe=30_000).solve(problem, seed=1)
print(result.summary())
print(result.best.solution.power.round(2))
L-SHADE on 6 units
best objective value: 15452.1
feasible: True (violation 0)
evaluations: 30000, iterations: 950, time: 0.844 s, stopped by: max_nfe
[448.4 182.87 252.21 137.29 168.64 86.57]
Differs from Python: MATLAB draws its own random numbers, so the results differ from Python's. The objective returns cost, inequalities and equalities as three outputs (outputs=3).
demand = 1263; % MW
% fuel cost of each unit: a + b P + c P^2 in $/h, with its output P in MW
a = [240 200 220 200 220 190];
b = [7.0 10.0 8.5 11.0 10.5 12.0];
c = [0.0070 0.0095 0.0090 0.0090 0.0080 0.0075];
% output limits for this hour, after the ramp rate limits
lower = [320 80 100 60 100 50];
upper = [500 200 265 150 200 120];
% prohibited operating zones: two ranges per unit where it must not run
zones = {
[210 240; 350 380]
[90 110; 140 160]
[150 170; 210 240]
[80 90; 110 120]
[90 110; 140 150]
[75 85; 100 105]
};
% transmission loss coefficients (Kron's formula), per unit on a 100 MVA base
B = [
0.0017 0.0012 0.0007 -0.0001 -0.0005 -0.0002
0.0012 0.0014 0.0009 0.0001 -0.0006 -0.0001
0.0007 0.0009 0.0031 0.0000 -0.0010 -0.0006
-0.0001 0.0001 0.0000 0.0024 -0.0006 -0.0008
-0.0005 -0.0006 -0.0010 -0.0006 0.0129 -0.0002
-0.0002 -0.0001 -0.0006 -0.0008 -0.0002 0.0150
];
B0 = 1e-3 * [-0.3908 -0.1297 0.7047 0.0591 0.2161 -0.6635];
B00 = 0.0056;
objective = @(sol) dispatch(sol.power, a, b, c, zones, B, B0, B00, demand);
problem = ypea.Problem( ...
vars=ypea.Real("power", lb=lower, ub=upper), ...
objective=objective, ...
outputs=3, ...
name="6 units");
result = ypea.LSHADE(max_nfe=30000).solve(problem, seed=1);
disp(result.summary())
disp(round(result.best.solution.power, 2))
function [cost, inside, balance] = dispatch(power, a, b, c, zones, B, B0, B00, demand)
cost = sum(a + b .* power + c .* power.^2);
% inequalities (<= 0): how far a unit runs inside a prohibited zone
inside = zeros(1, 12);
for unit = 1:6
for k = 1:2
low = zones{unit}(k, 1);
high = zones{unit}(k, 2);
inside(2 * (unit - 1) + k) = min(power(unit) - low, high - power(unit));
end
end
% equality (= 0): generation covers the demand and the losses
p = power / 100; % per unit
losses = 100 * (p * B * p' + B0 * p' + B00);
balance = sum(power) - demand - losses;
end
L-SHADE on 6 units
best objective value: 15454.9
feasible: true (violation 0)
evaluations: 30000, iterations: 950, time: 4.23 s, stopped by: max_nfe
458.9200 183.1900 262.2100 120.9800 165.9900 85.0000
The run meets every constraint, with the balance within 0.0001 MW, and its cost is 0.014 percent above the best known value.
13 units with valve-point effects¶
When a turbine opens a steam valve, its fuel use jumps, which adds a rippled term to the cost curve. The cost of the whole system then has many local minima.
Here the model removes the equality constraint with a simple trick: the optimizer sets units 1 to 12, and unit 13 takes whatever the demand still needs. The balance then holds exactly, and the only constraint left is that unit 13 stays within its limits. An equality constraint is hard for any search method, because almost every point misses it. Removing it this way makes the search much easier. In a quick check with 5 runs each, the average gap to the best known cost fell from 0.8 to 0.25 percent for L-SHADE and from 3.3 to 0.24 percent for DE.
import numpy as np
import ypea
demand = 1800.0 # MW
# fuel cost of each unit: a + b P + c P^2 + |e sin(f (P_min - P))| in $/h
a = np.array([550, 309, 307, 240, 240, 240, 240, 240, 240, 126, 126, 126, 126.0])
b = np.array([8.10, 8.10, 8.10, 7.74, 7.74, 7.74, 7.74, 7.74, 7.74, 8.60, 8.60, 8.60, 8.60])
c = np.array([0.00028, 0.00056, 0.00056, 0.00324, 0.00324, 0.00324, 0.00324, 0.00324, 0.00324,
0.00284, 0.00284, 0.00284, 0.00284])
e = np.array([300, 200, 200, 150, 150, 150, 150, 150, 150, 100, 100, 100, 100.0])
f = np.array([0.035, 0.042, 0.042, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.084, 0.084, 0.084, 0.084])
p_min = np.array([0, 0, 0, 60, 60, 60, 60, 60, 60, 40, 40, 55, 55.0])
p_max = np.array([680, 360, 360, 180, 180, 180, 180, 180, 180, 120, 120, 120, 120.0])
def dispatch(sol):
# the optimizer sets units 1 to 12, and unit 13 takes the rest of the demand
last = demand - np.sum(sol.power)
power = np.append(sol.power, last)
cost = np.sum(a + b * power + c * power**2 + np.abs(e * np.sin(f * (p_min - power))))
out_of_range = max(p_min[-1] - last, last - p_max[-1]) # <= 0 when unit 13 is within its limits
return cost, [out_of_range]
problem = ypea.Problem(ypea.Real("power", lb=p_min[:-1], ub=p_max[:-1]), dispatch, name="13 units")
result = ypea.DE(max_nfe=100_000).solve(problem, seed=1)
print(result.summary())
DE on 13 units
best objective value: 17972.8
feasible: True (violation 0)
evaluations: 100000, iterations: 999, time: 1.27 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own random numbers, so the results differ from Python's. The objective returns cost and inequalities as two outputs (outputs=2).
demand = 1800; % MW
% fuel cost of each unit: a + b P + c P^2 + |e sin(f (P_min - P))| in $/h
a = [550 309 307 240 240 240 240 240 240 126 126 126 126];
b = [8.10 8.10 8.10 7.74 7.74 7.74 7.74 7.74 7.74 8.60 8.60 8.60 8.60];
c = [0.00028 0.00056 0.00056 0.00324 0.00324 0.00324 0.00324 0.00324 0.00324 ...
0.00284 0.00284 0.00284 0.00284];
e = [300 200 200 150 150 150 150 150 150 100 100 100 100];
f = [0.035 0.042 0.042 0.063 0.063 0.063 0.063 0.063 0.063 0.084 0.084 0.084 0.084];
p_min = [0 0 0 60 60 60 60 60 60 40 40 55 55];
p_max = [680 360 360 180 180 180 180 180 180 120 120 120 120];
objective = @(sol) dispatch(sol.power, a, b, c, e, f, p_min, p_max, demand);
problem = ypea.Problem( ...
vars=ypea.Real("power", lb=p_min(1:12), ub=p_max(1:12)), ...
objective=objective, ...
outputs=2, ...
name="13 units");
result = ypea.DE(max_nfe=100000).solve(problem, seed=1);
disp(result.summary())
function [cost, out_of_range] = dispatch(power, a, b, c, e, f, p_min, p_max, demand)
% the optimizer sets units 1 to 12, and unit 13 takes the rest of the demand
last = demand - sum(power);
power = [power, last];
cost = sum(a + b .* power + c .* power.^2 + abs(e .* sin(f .* (p_min - power))));
out_of_range = max(p_min(13) - last, last - p_max(13)); % <= 0 when unit 13 is within its limits
end
DE on 13 units
best objective value: 17972.8
feasible: true (violation 0)
evaluations: 100000, iterations: 999, time: 8.09 s, stopped by: max_nfe
DE ends 0.05 percent above the best known cost. The full script, examples/applications/economic_dispatch.py, solves both systems and draws the dispatch.
Results¶
Five algorithms for continuous problems, each with 10 seeded runs. The gap is the distance of the best run from the best known cost.
6 units, 30 000 evaluations:
| Algorithm | Best | Mean | Worst | Feasible runs | Gap of best |
|---|---|---|---|---|---|
| DE | 15453.82 | 15470.34 | 15492.82 | 10 of 10 | 0.025% |
| PSO | 15457.93 | 15488.10 | 15547.36 | 10 of 10 | 0.052% |
| CMA-ES | 15474.31 | 15489.86 | 15525.81 | 10 of 10 | 0.158% |
| JADE | 15453.39 | 15466.63 | 15484.87 | 7 of 10 | 0.023% |
| L-SHADE | 15450.93 | 15458.51 | 15484.38 | 10 of 10 | 0.007% |
13 units, 100 000 evaluations:
| Algorithm | Best | Mean | Worst | Feasible runs | Gap of best |
|---|---|---|---|---|---|
| DE | 17972.81 | 18030.87 | 18075.59 | 10 of 10 | 0.050% |
| PSO | 18081.23 | 18123.16 | 18198.00 | 10 of 10 | 0.654% |
| GA | 18028.50 | 18116.76 | 18191.58 | 10 of 10 | 0.360% |
| JADE | 17999.15 | 18015.33 | 18039.65 | 10 of 10 | 0.197% |
| L-SHADE | 17983.09 | 18014.17 | 18035.53 | 10 of 10 | 0.107% |
L-SHADE is the most reliable on the 6-unit system. On the 13-unit system DE finds the best single dispatch, while L-SHADE and JADE have the best averages. Every algorithm ends within 1 percent of the best known cost.
Try it on your own system¶
Replace the coefficients and limits with those of your units. Without losses, drop the loss terms and the balance becomes np.sum(power) - demand. With valve points or prohibited zones, keep the slack unit idea: let one unit, preferably a large one, take the rest of the demand.