0% found this document useful (0 votes)
47 views2 pages

4/9/19 11:37 PM C:/Users/Anabil Samanta/Desk... /pso.m 1 of 2

1) The document describes a particle swarm optimization algorithm for minimizing an objective function. It initializes a population of particles with random positions within bounds and tracks the best historical position of each particle and the global best. 2) In each iteration, it updates the velocity of each particle based on its previous velocity, distance from its best position, and distance from the global best. It then updates each particle's position based on its new velocity. 3) The algorithm iterates until the global best value falls below a threshold or the maximum number of iterations is reached, at which point it outputs the global best value and number of iterations executed.

Uploaded by

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

4/9/19 11:37 PM C:/Users/Anabil Samanta/Desk... /pso.m 1 of 2

1) The document describes a particle swarm optimization algorithm for minimizing an objective function. It initializes a population of particles with random positions within bounds and tracks the best historical position of each particle and the global best. 2) In each iteration, it updates the velocity of each particle based on its previous velocity, distance from its best position, and distance from the global best. It then updates each particle's position based on its new velocity. 3) The algorithm iterates until the global best value falls below a threshold or the maximum number of iterations is reached, at which point it outputs the global best value and number of iterations executed.

Uploaded by

anabil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/9/19 11:37 PM C:\Users\Anabil Samanta\Desk...\pso.

m 1 of 2

clc
clear all
pop=input('Enter the population size :- ');
ite=input('Enter the no of iteration:- ');
d=4;
range=10;

velocity=zeros(pop,4);

velocity_maxlimit=3;
velocity_minlimit=-3;

c1=1.49455;
c2=1.49455;

wmin=0.49;
wmax=.95;
c=unifrnd(-5,5,pop,d);
for q=1:ite

for i=1:pop
sum=0;
for j=1:d
y=c(i,j)^2;
sum=sum+y;
end
z(i)=sum;
end

[pbest_value,index]=min(z);
pbest_solution=c(index,:);

if q==1
gbest_value=pbest_value;
gbest_solution=pbest_solution;
elseif pbest_value<gbest_value
gbest_solution=pbest_solution;
gbest_value=pbest_value;
else
end
m(q)=gbest_value;

% w=0.5+rand()/2;
w=((wmax-wmin)*q)/ite;

for l=1:pop
for k=1:d
velocity(l,k)=w*velocity(l,k)+c1*unifrnd(0,1)*(pbest_solution(k)-(c(l,
k)))+c2*unifrnd(0,1)*(gbest_solution(k)-(c(l,k)));
if velocity(l,k)>velocity_maxlimit
velocity(l,k)=velocity_maxlimit;
elseif velocity(l,k)<velocity_minlimit
velocity(l,k)=velocity_minlimit;
4/9/19 11:37 PM C:\Users\Anabil Samanta\Desk...\pso.m 2 of 2

else
end
end
end

for l=1:pop
for k=1:d
c(l,k)=c(l,k)+velocity(l,k);
if c(l,k)>range
c(l,k)=range;
elseif c(l,k)<-range
c(l,k)=range;
else
end
end
end

if gbest_value<=0.00001
break
else
continue
end
end

fprintf('Gbest value=%f',gbest_value);
fprintf('\n');
x=length(m);
fprintf('no.of iteration executed %d',x)
fprintf('\n')

You might also like