1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| function FFA
clear all
clc
N=input('Please Enter the Number of Firefly: ');
clc
maxGen=input('Please Provide the Stopping Criteria: ');
clc
alpha=input('Please Enter the value of alpha: ');
clc
Beta0=input('Please enter the Initial attractiveness: ');
clc
gamma=input('Please Provide the Absorption Coefficient (gamma): ');
clc
fitness=input('Select the test function: ');
clc
FIREFLY=input('Please Enter the Population of the FIREFLY: or\nPress zero(0) for the default population: ');
clc
if FIREFLY==0
pop=rand(N);
else
pop=FIREFLY;
end
popi=pop;
popj=rand(N);
Ii=objfunc(fitness,popi);
%this reprsent the light intesity of(pop)
%this reprsent the light intesity of(pop)
Ij=objfunc(fitness,popj);
%Ij=fitness+popj;
itr=0;
while itr<maxGen
itr=itr+1;
for i=1:N
for j=1:N
r=sqrt((popi(i)-popi(j))^2+(popj(i)-pop(j))^2);
if Ii<Ij
beta=Beta0*exp(-gamma*r.^2);
Ii=popj(i).*(1-beta)+popj(j).*beta+alpha.*(rand-0.5);
end
beta=Beta0*exp(-gamma*r.^2);
popi(i)=popi(i).*(1-beta)+popi(j).*beta+alpha.*(rand-0.5);
popj(i)=popj(i).*(1-beta)+popj(j).*beta+alpha.*(rand-0.5);
Iinew=objfunc(fitness,popi(i)); Ijnew=objfunc(fitness,popj(i));
end
end
if Iinew<Ijnew
Best_Soln=Iinew;
else Best_Soln=Ijnew;
end
end
disp(Best_Soln) |
Partager