load flow by backward-forward sweep algorithm to make NR
13 views (last 30 days)
Show older comments
Hello every one..
please, i need matlab code to make network reconfiguration using BPSO as optimization method for ieee 33 bus system but i need load flow by BFS algorthim for this code.
I know NR by BPSO found but using mat power to make load flow.
thanks alot.
1 Comment
Omar Shaaban
on 1 Sep 2024
Hi did you happen to find the network reconfiguration code? can you please share to: omar.abdalmoneem@gmail.com
Accepted Answer
Zinea
on 2 Sep 2024
Here is the outline of the MATLAB code for NR using BPSO with a simplified BFS-based load flow analysis for the IEEE 33-bus system. The following points are to be considered:
- The voltage magnitudes are initialized to 1 p.u. (per unit) for simplicity.
- The adjacency matrix represents the connectivity of the network, where a ‘1’ indicates a connection between buses (i.e., a closed branch).
- The voltage drop across each branch is calculated using a simplified linear approximation. This is a basic method and should be replaced with a more precise calculation, such as using the power flow equations.
% Initialization
numBuses = 33; % Number of buses
numBranches = 37; % Number of branches
maxIter = 100; % Maximum number of iterations for BPSO
numParticles = 30; % Number of particles in the swarm
% Hypothetical bus data: [busNumber, type, Pd, Qd]
busData = [
1, 1, 0, 0; % Slack bus
2, 2, 0.1, 0.06;
3, 2, 0.09, 0.04;
% Add remaining buses...
];
% Hypothetical branch data: [fromBus, toBus, resistance, reactance]
branchData = [
1, 2, 0.0922, 0.0470;
2, 3, 0.4930, 0.2511;
% Add remaining branches...
];
% Initialize particles
particles = randi([0, 1], numParticles, numBranches);
velocities = zeros(numParticles, numBranches);
pBest = particles;
gBest = particles(1, :);
pBestCost = inf(numParticles, 1);
gBestCost = inf;
% BPSO parameters
w = 0.5; % Inertia weight
c1 = 1.5; % Cognitive coefficient
c2 = 1.5; % Social coefficient
% Optimization Loop
for iter = 1:maxIter
for i = 1:numParticles
% Perform BFS Load Flow Analysis
[V, loss] = bfsLoadFlow(particles(i, :), busData, branchData);
% Evaluate cost function (e.g., power loss)
cost = sum(loss);
% Update personal best
if cost < pBestCost(i)
pBest(i, :) = particles(i, :);
pBestCost(i) = cost;
end
% Update global best
if cost < gBestCost
gBest = particles(i, :);
gBestCost = cost;
end
end
% Update particle velocities and positions
for i = 1:numParticles
velocities(i, :) = w * velocities(i, :) ...
+ c1 * rand * (pBest(i, :) - particles(i, :)) ...
+ c2 * rand * (gBest - particles(i, :));
% Update particles using sigmoid function for binary conversion
sigmoid = 1 ./ (1 + exp(-velocities(i, :)));
particles(i, :) = rand(size(sigmoid)) < sigmoid;
end
% Display iteration information
fprintf('Iteration %d: Best Cost = %.4f\n', iter, gBestCost);
end
% Final Results
fprintf('Optimal Configuration: %s\n', num2str(gBest));
fprintf('Minimum Loss: %.4f\n', gBestCost);
function [V, loss] = bfsLoadFlow(particle, busData, branchData)
% Initialize variables
numBuses = size(busData, 1);
V = ones(numBuses, 1); % Initialize voltage magnitudes to 1 p.u.
loss = zeros(size(branchData, 1), 1); % Power loss for each branch
% Create adjacency matrix for BFS
adjacencyMatrix = zeros(numBuses, numBuses);
for i = 1:size(branchData, 1)
if particle(i) == 1 % If branch is closed
fromBus = branchData(i, 1);
toBus = branchData(i, 2);
adjacencyMatrix(fromBus, toBus) = 1;
adjacencyMatrix(toBus, fromBus) = 1;
end
end
% BFS algorithm
visited = false(numBuses, 1);
queue = [1]; % Start from the slack bus (assumed to be bus 1)
visited(1) = true;
while ~isempty(queue)
currentBus = queue(1);
queue(1) = [];
neighbors = find(adjacencyMatrix(currentBus, :));
for neighbor = neighbors
if ~visited(neighbor)
% Find branch index
branchIndex = find((branchData(:, 1) == currentBus & branchData(:, 2) == neighbor) | ...
(branchData(:, 1) == neighbor & branchData(:, 2) == currentBus));
% Calculate voltage drop and losses
resistance = branchData(branchIndex, 3);
reactance = branchData(branchIndex, 4);
powerDemand = busData(neighbor, 3) + 1i * busData(neighbor, 4);
% Simplified voltage drop calculation (linear approximation)
voltageDrop = (resistance + 1i * reactance) * powerDemand / V(currentBus);
V(neighbor) = V(currentBus) - abs(voltageDrop);
% Calculate power loss in the branch
currentFlow = powerDemand / V(currentBus);
loss(branchIndex) = resistance * abs(currentFlow)^2;
% Mark as visited and add to queue
visited(neighbor) = true;
queue(end + 1) = neighbor;
end
end
end
end
Hope this helps you get started!
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!