0% found this document useful (0 votes)
3 views

Assignment 01

dhbdfbfxsb

Uploaded by

jawadamin1133
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 01

dhbdfbfxsb

Uploaded by

jawadamin1133
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

ASSIGNMENT # 01

POWER SYSTEM OPERATION & CONTROL

Submitted TO:____Dr.Salman Fakhar

Submitted BY:__Musa Ishaq (2021-EE-77)


Jawad Amin (2021-EE-80)
Khizer Hayat(2021-EE-84)
Zubair Ahmad (2021-EE-93)
Talal Khalid (2021-EE-97)

UNIVERSITY OF ENGINEERING & TECHNOLOGY LAHORE


Department Of Electrical Engineering
Adaptive Particle Swarm Optimization.

Here Is Matlab Code For Base Case:


% Particle Swarm Optimization (by X-S Yang, Cambridge University)
% Usage: pso_demo(number_of_particles, Num_iterations)
% Example: best = pso_demo(20, 15);
% Output: best = [xbest ybest zbest] (an n-by-3 matrix)

function [best] = pso_demo(n, Num_iterations)


if nargin < 2, Num_iterations = 15; end
if nargin < 1, n = 20; end

% Michaelwicz Function f* = -1.801 at [2.20319, 1.57049]


fstr = '-sin(x) * (sin(x^2/pi))^20 - sin(y) * (sin(2 * y^2/pi))^20';
% Converting to an inline function and vectorization
f = vectorize(inline(fstr));

% range = [xmin xmax ymin ymax];


range = [0 4 0 4];

% Setting the parameters: alpha, beta


alpha = 0.2;
beta = 0.5;

% Grid values of the objective for visualization only


Ndiv = 100;
dx = (range(2) - range(1)) / Ndiv;
dy = (range(4) - range(3)) / Ndiv;
xgrid = range(1):dx:range(2);
ygrid = range(3):dy:range(4);
[x, y] = meshgrid(xgrid, ygrid);
z = f(x, y);

% Display the shape of the function to be optimized


figure(1);
surfc(x, y, z);

% Initialize history to store best positions


best = zeros(Num_iterations, 3);

% Start Particle Swarm Optimization


% Generating the initial locations of n particles
[xn, yn] = init_pso(n, range);

% Display the particle paths and contour of the function


figure(2);

% Start iterations
for i = 1:Num_iterations
% Show the contour of the function
contour(x, y, z, 15); hold on;

% Find the current best location (xo, yo)


zn = f(xn, yn);
zn_min = min(zn);
xo = min(xn(zn == zn_min));
yo = min(yn(zn == zn_min));
zo = min(zn(zn == zn_min));

% Trace the paths of all roaming particles


plot(xn, yn, '.', xo, yo, '*'); axis(range);

% Move all the particles to new locations


[xn, yn] = pso_move(xn, yn, xo, yo, alpha, beta, range);
drawnow;

% Store the best history


best(i, 1) = xo; best(i, 2) = yo; best(i, 3) = zo;
hold off;
end
end

% Initialize locations of n particles


function [xn, yn] = init_pso(n, range)
xrange = range(2) - range(1);
yrange = range(4) - range(3);
xn = rand(1, n) * xrange + range(1);
yn = rand(1, n) * yrange + range(3);
end
% Move all the particles toward (xo, yo)
function [xn, yn] = pso_move(xn, yn, xo, yo, alpha, beta, range)
nn = size(yn, 2);
xn = xn * (1 - beta) + xo * beta + alpha * (rand(1, nn) - 0.5);
yn = yn * (1 - beta) + yo * beta + alpha * (rand(1, nn) - 0.5);
[xn, yn] = findrange(xn, yn, range);
end

% Ensure the particles stay within the bounds


function [xn, yn] = findrange(xn, yn, range)
nn = length(yn);
for i = 1:nn
if xn(i) <= range(1), xn(i) = range(1); end
if xn(i) >= range(2), xn(i) = range(2); end
if yn(i) <= range(3), yn(i) = range(3); end
if yn(i) >= range(4), yn(i) = range(4); end
end
end
Results:
TASK-1
For maximum Adaptive Particle Swarm Optimization.
Alpha decides how much randomness is added to the particle's movement, and Beta controls
how much the particles follow the best position found so far. If Alpha is increased, the particles
move more randomly and explore a bigger area. If Beta is increased, the particles are more
strongly pulled towards the best position.
Results:
Task-2
For minimum Adaptive Particle Swarm Optimization.

With α = 0.1 and β = 0.2, the APSO algorithm will likely be slow and explore a lot of different
areas. The particles will only make small moves and won't be strongly drawn to the best
solution they find. This might make them get stuck and not change much. However, this slower
way of searching could help them look at many different parts of the space, which might lead
them to find the best solution instead of getting stuck in a less good one.
Results:

You might also like