Economic Dispatching using PSO and Nested PSO
Study economic dispatch in MATLAB with PSO and nested PSO, generator limits, prohibited zones, transmission losses, and plant-selection costs.

On this page
This post shares an open-source MATLAB implementation of Particle Swarm Optimization (PSO) and Nested PSO for the economic power dispatching problem.
Economic dispatch is a classic problem in power system operation. A set of generating plants must together supply the demand of the network, plus the power lost in the transmission lines. Each plant has its own fuel cost and operating limits. The task is to choose the output of every plant so that the demand is met at the lowest total cost.
Problem definition
Let be the output of plant , for . The cost of each plant is a quadratic function of its output, and the problem is:
subject to
- Power balance: the total output equals the demand plus the losses, .
- Output limits: .
- Prohibited operating zones: each plant has ranges of output where it should not run, for example because of vibration in the shaft or valve problems. must lie outside these ranges.
The transmission loss is computed with the B coefficient loss formula:
where is the vector of plant outputs, is a square matrix, is a vector and is a constant.
Because of the prohibited zones, the feasible range of each plant is split into several separate parts. This makes the problem nonconvex, so classic methods based on gradients have trouble with it. A population based method such as PSO only needs the cost of each candidate, but the constraints still need explicit encoding and validation.
The example model
CreateModel.m defines an example with six power plants and a total demand of 1263. Each plant has minimum and maximum output limits, cost coefficients, and prohibited operating zones. The model also includes loss coefficients. ParseSolution.m maps each decision variable from the range 0 to 1 to the output range of its plant. It then moves any output that falls inside a prohibited zone to the nearest edge of that zone.
In the first project, the model also has ramp rate limits. Each plant has a previous output P0, an up ramp limit UR and a down ramp limit DR. Its usable range is then
and ParseSolution.m maps the decision variables to this range (PminActual and PmaxActual). The second project does not use ramp limits.
ModelCalculations.m computes the costs, the loss and a power balance violation, . This measures how far the net output falls short of the demand. The first project uses the cost . The second project uses .
What is in the download
The download has two projects.
01 Economic Dispatching using PSO
PSO solves the problem directly. The files are:
CreateModel.m: defines the power system model.ParseSolution.m: converts a particle position into plant outputs.ModelCalculations.mandMyCost.m: compute the cost of a solution.pso.m: the PSO algorithm.
Each particle has six variables, one for each plant. The main script pso.m uses 200 iterations and a swarm of 100 particles, with the constriction coefficients of Clerc and Kennedy ().
02 Economic Dispatching using Nested PSO
This project adds an internal PSO. It has the same files as the first project, plus CreateInternalModel.m, RunInternalPSO.m, MyCostExt.m, and ParseSolutionExt.m.
Here the problem has two levels. The model has six slots for plants and six plant types. Each type has the same data as above, plus a fixed cost F. The question is which plants to use, and then how much each one should produce.
- The outer PSO (
pso.m) decides the plant set. Each particle has six variables.ParseSolutionExt.mturns each one into an integer from 0 to 6. The value 0 leaves the slot empty, and a value puts a plant of type in that slot. The same type may appear in more than one slot. - The inner PSO (
RunInternalPSO.m) solves the economic dispatch for that plant set.CreateInternalModel.mbuilds a model with the chosen plants, and an empty slot gets zero limits and zero costs.
MyCostExt.m joins the two levels. The cost of an outer particle is the sum of the fixed costs of the chosen plants plus the best dispatch cost found by the inner PSO:
Every evaluation of the outer PSO runs an inner PSO. The outer search uses 10 iterations and 10 particles, while the inner search uses 100 iterations and 50 particles. This nested structure requires many more objective evaluations than the direct formulation.
How to run the code
Neither project has a main.m. Open a project folder in MATLAB and run pso.m.
- In the first project, the program prints the best cost in each iteration and plots the best cost against the iteration at the end.
- In the second project, the outer PSO prints its best cost in each iteration, and each inner run prints a start and an end message. The best cost of the outer PSO is plotted at the end.
The final solution is stored in the variable BestSol. To use your own system, change the plant data, the loss coefficients and the demand PD in CreateModel.m.
Check the result
Check generator limits, prohibited zones, ramp limits where present, and the full power-balance residual . The implemented violation penalizes a supply shortfall but does not symmetrically enforce the stated balance equality, so surplus generation can remain. A low penalized cost is therefore not enough to establish feasibility. In the nested version, the outer cost uses the best inner result found, not a certified inner optimum, and random variation in that inner search can affect comparisons.
Applications
Economic dispatch is solved many times a day by power system operators, to share the load between generating units at the lowest cost. Related problems include unit commitment (which units to switch on) and generation expansion planning (which plants to build). The nested approach of the second project shows one way to combine a selection problem with a dispatch problem.
Related posts
Downloads
How to cite
If you use this code or tutorial in your work, articles or publications, please cite it.
Mostapha Kalami Heris, Economic Dispatching using PSO and Nested PSO (YPAP113), Yarpiz, 2015. https://yarpiz.com/economic-dispatching-ypap113@misc{yarpiz-ypap113,
author = {{Mostapha Kalami Heris}},
title = {{Economic Dispatching using PSO and Nested PSO}},
howpublished = {Yarpiz},
year = {2015},
note = {Code YPAP113},
url = {https://yarpiz.com/economic-dispatching-ypap113}
}Published Updated
Comments