matlab program for tlbo algorithm

2
clear; clc; G=[500 5.3 0.004 200 450 ; 400 5.5 0.006 150 350 ; 200 5.8 0.009 100 225] R=rand(20,2) L=800; s=zeros(20,1); i=1; while i<=20 P(i,1)=200+rand.*(450-200); P(i,2)=150+rand.*(350-150); P(i,3)=L-P(i,1)-P(i,2); if (P(i,3)<=225 && P(i,3)>=100) i=i+1; end i P end for i=1:20 for j=1:3 i j s(i) =s(i)+ G(j,1)+G(j,2).*P(i,j)+G(j,3).*P(i,j)^2 ; s end end s teacher=min(s) x=find(s==teacher) t=[P(x,1) P(x,2) P(x,3)] a=mean(P); for i=1:20 if i~=x q(i,:)=P(i,:)+rand.*((t(1,:)-rand.*a(1,:))) else q(i,:)=P(x,:) end end for i=1:5 for j=1:4 a=((i-1)*4)+j; nearby=[a-1 a+1 a+4 a-4]; for k=1:4 if(nearby(k)<=0 || nearby(k)>20) nearby(k)=0; end if(k==2 && nearby(k)>=((i*4)+1)) nearby(k)=0;

Upload: rajani51

Post on 14-Apr-2017

369 views

Category:

Engineering


6 download

TRANSCRIPT

Page 1: matlab program for TLBO algorithm

clear;clc;G=[500 5.3 0.004 200 450 ; 400 5.5 0.006 150 350 ; 200 5.8 0.009 100 225]R=rand(20,2)L=800; s=zeros(20,1); i=1; while i<=20 P(i,1)=200+rand.*(450-200); P(i,2)=150+rand.*(350-150); P(i,3)=L-P(i,1)-P(i,2); if (P(i,3)<=225 && P(i,3)>=100) i=i+1; end i P end for i=1:20 for j=1:3 i j s(i) =s(i)+ G(j,1)+G(j,2).*P(i,j)+G(j,3).*P(i,j)^2 ; s end end s teacher=min(s) x=find(s==teacher) t=[P(x,1) P(x,2) P(x,3)]a=mean(P);for i=1:20 if i~=x q(i,:)=P(i,:)+rand.*((t(1,:)-rand.*a(1,:))) else q(i,:)=P(x,:) endendfor i=1:5 for j=1:4 a=((i-1)*4)+j; nearby=[a-1 a+1 a+4 a-4]; for k=1:4 if(nearby(k)<=0 || nearby(k)>20) nearby(k)=0; end if(k==2 && nearby(k)>=((i*4)+1)) nearby(k)=0; end if(k==1 && nearby(k)==((i-1)*4)) nearby(k)=0; end nearbycost(k)=zeros; if(nearby(k)==0) nearbycost(k)=0; end if(nearby(k)~=0) nearbycost(k)=s(nearby(k));

Page 2: matlab program for TLBO algorithm

end end a nearby nearbycost bestneighbour=min(nearbycost(nearbycost~=0)) pos(i,j)=nearby(find(nearbycost==bestneighbour)) endendpost=pos'minnearby=zeros(20,1); for a=1:20 minnearby(a)=post(a) end minnearbyfor a=1:20 if s(a)<s(minnearby(a)) r(a,:)=P(i,:)+rand.*(P(minnearby(a),:)-P(i,:)); else r(a,:)=P(i,:)+rand.*(P(i,:)-P(minnearby(a),:)); endendr