0% found this document useful (0 votes)
27 views14 pages

Srmpsooptimization

The document describes a particle swarm optimization (PSO) algorithm used to optimize 3 variables to minimize an objective function. It initializes 15 particles across the variable bounds and runs the algorithm for 20 iterations. In each iteration, it calculates the objective value for each particle, updates each particle's personal best position and the global best position. It then updates each particle's velocity and position for the next iteration. The algorithm returns the optimized global best position that minimizes the objective function.

Uploaded by

Lalan Chaudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views14 pages

Srmpsooptimization

The document describes a particle swarm optimization (PSO) algorithm used to optimize 3 variables to minimize an objective function. It initializes 15 particles across the variable bounds and runs the algorithm for 20 iterations. In each iteration, it calculates the objective value for each particle, updates each particle's personal best position and the global best position. It then updates each particle's velocity and position for the next iteration. The algorithm returns the optimized global best position that minimizes the objective function.

Uploaded by

Lalan Chaudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PSO ALGO

clear all
close all
clc

% Define the details of the table design problem


nVar = 3; % number of variables
ub = [1000 1000 1000]; %upper Bound
lb = [0 0 0]; % lower bound
fobj = @tunning; % Objective function Name

% Define the PSO's paramters


noP = 15; % number of particles for initialization
maxIter = 20; % maximum iterations
wMax = 1;
wMin = 0.1;
c1 = 2;
c2 = 2;
vMax = (ub - lb) .* 0.2;
vMin = -vMax;

% The PSO algorithm

% Initialize the particles


for k = 1 : noP
Swarm.Particles(k).X = (ub-lb) .* rand(1,nVar) + lb;
Swarm.Particles(k).V = zeros(1, nVar);
Swarm.Particles(k).PBEST.X = zeros(1,nVar);
Swarm.Particles(k).PBEST.O = inf;

Swarm.GBEST.X = zeros(1,nVar);
Swarm.GBEST.O = inf;
end

% Main loop
for t = 1 : maxIter

% Calcualte the objective value


for k = 1 : noP
currentX = Swarm.Particles(k).X;
Swarm.Particles(k).O = fobj(currentX);

% Update the PBEST


if Swarm.Particles(k).O < Swarm.Particles(k).PBEST.O
Swarm.Particles(k).PBEST.X = currentX;
Swarm.Particles(k).PBEST.O = Swarm.Particles(k).O;
end

% Update the GBEST


if Swarm.Particles(k).O < Swarm.GBEST.O
Swarm.GBEST.X = currentX;
Swarm.GBEST.O = Swarm.Particles(k).O;
end
end

% Update the X and V vectors


w = wMax - t .* ((wMax - wMin) / maxIter);

for k = 1 : noP
Swarm.Particles(k).V = w .* Swarm.Particles(k).V + c1 .* rand(1,nVar) .*
(Swarm.Particles(k).PBEST.X - Swarm.Particles(k).X) ...

+ c2 .* rand(1,nVar) .* (Swarm.GBEST.X - Swarm.Particles(k).X);

% Check velocities
index1 = find(Swarm.Particles(k).V > vMax);
index2 = find(Swarm.Particles(k).V < vMin);

Swarm.Particles(k).V(index1) = vMax(index1);
Swarm.Particles(k).V(index2) = vMin(index2);

Swarm.Particles(k).X = Swarm.Particles(k).X + Swarm.Particles(k).V;

% Check positions
index1 = find(Swarm.Particles(k).X > ub);
index2 = find(Swarm.Particles(k).X < lb);

Swarm.Particles(k).X(index1) = ub(index1);
Swarm.Particles(k).X(index2) = lb(index2);
end

outmsg = ['Iteration# ', num2str(t) , ' Swarm.GBEST.O = ' ,


num2str(Swarm.GBEST.O)];
disp(outmsg);

cgCurve(t) = Swarm.GBEST.O;
end

semilogy(cgCurve);
xlabel('Iteration#')
ylabel('Weight')

OBJECTIVE FUNCTION

function cost = tunning(kk)


assignin('base','kk',kk);
sim('PSO_tunning_PID.slx');
cost= ITAE(length(ITAE));
end
torque
Both torque comparision
After optimize value of PID
Before PID optimization
After
Before
After

Before
After
Before

You might also like