I'm trying to get the solution of economic load despatch using particle swarm optimization. I've written the code but during updating the velocity and particle position in the second iteration, it does not generate the power value of generator which adds up to 850. Somehow the algorithm isn't converging. Please try to run it in MATLAB
clear all
clc
%Initialization
c1 = 2.0, c2 = 2.0
wmax = 0.9, wmin = 0.4
count = 0,countv=0
p1min = 100,p1max = 600
p2min = 50,p2max = 200
p3min = 100,p3max = 400
v1min = -50, v1max = 300
v2min = -25, v2max = 100
v3min = -50, v3max = 200
pd = 850
counter=0
for i=1:10000
sum1=0;
if count<10
g(i-counter,1) = (p1max - p1min)*rand() + p1min
g(i-counter,2) = (p2max - p2min)*rand() + p2min
g(i-counter,3) = (p3max - p3min)*rand() + p3min
sum1=round(g(i-counter,1)+g(i-counter,2)+g(i-counter,3))
if sum1==pd
count=count+1;
else
g(i-counter,:)=[]
counter=counter+1;
end
end
end
for i=1:10 %COST FUNCTION FOUND
f(i,1) = 0.0016*(g(i,1))^2+7.92*g(i,1)+561 + 0.0048*(g(i,2))^2+ 7.92*g(i,2) + 78 + 0.0019*(g(i,3))^2 + 7.85*g(i,3) + 310
end
total1 = [f g]
for i=1:10 %Intial VELOCITY OBTAINED
v(i,1)= v1min + rand()*(v1max-v1min)
v(i,2)= v2min + rand()*(v2max-v2min)
v(i,3)= v3min + rand()*(v3max-v3min)
countv = countv +1
if countv == 10
break
end
end
ginti = 0
for k=1:100
w=wmax - ((wmax-wmin)/100)*k %K TO BE GET FROM FINAL LOOP
gbest=min(total1(:,:)) %PBEST AND GBEST FOUND
pbest=total1(:,:)
counter = 0
count = 0
%VELOCITY IS TO BE UPDATED
for i=1:100000
if count<10
vnew(i-counter,1) = w*v(i-counter,1) + c1*rand()*(pbest(i-counter,2)-g(i-counter,1)) + c2*rand()*(gbest(1,2)-g(i-counter,1))
vnew(i-counter,2) = w*v(i-counter,2) + c1*rand()*(pbest(i-counter,3)-g(i-counter,2)) + c2*rand()*(gbest(1,3)-g(i-counter,2))
vnew(i-counter,3) = w*v(i-counter,3) + c1*rand()*(pbest(i-counter,4)-g(i-counter,3)) + c2*rand()*(gbest(1,4)-g(i-counter,3))
gnew(i-counter,1) = g(i-counter,1) + vnew(i-counter,1)
gnew(i-counter,2) = g(i-counter,2) + vnew(i-counter,2)
gnew(i-counter,3) = g(i-counter,3) + vnew(i-counter,3)
if gnew(i-counter,1)<=600 & gnew(i-counter,1)>=100 & gnew(i-counter,2)>=50 & gnew(i-counter,2)<=200& gnew(i-counter,3)>=100 & gnew(i-counter,3) <=400 & round(gnew(i-counter,1) + gnew(i-counter,2) + gnew(i-counter,3))==pd
count = count + 1;
else
vnew(i-counter,:) = []
gnew(i-counter,:) = []
counter = counter+1;
end
end
end
for i=1:10 % UPDATED COST FUNCTION FOUND
fnew(i,1) = 0.00156*(gnew(i,1))^2+7.92*gnew(i,1)+561 + 0.00194*(gnew(i,2))^2+ 7.85*gnew(i,2) + 310 + 0.00482*(gnew(i,3))^2 + 7.97*gnew(i,3) + 78
end
total2 = [fnew gnew]
% COMPARISON OF THE TWO TABLES
for i=1:10
if (total1(i,1)<=total2(i,1))
total3(i,:)= total1(i,:)
else
total3(i,:)= total2(i,:)
end
end
total1=total3
g(:,1)=total3(:,1)
g(:,2)=total3(:,2)
g(:,3)=total3(:,3)
ginti= ginti + 1
end