Content uploaded by Parastoo Alaei Roozbahni
Author content
All content in this area was uploaded by Parastoo Alaei Roozbahni on Oct 27, 2022
Content may be subject to copyright.
Artificial Immune
System
Dr. ghaemi
Parastoo Alaei
(AIS)
(Pathogens)
(Antigen)
B
Y B
Artificial Immune System
:
AIS
Shape Space
AIS
.
AIS
AIS
AIS
B
T
:
AIS
Code AIS
Matlab
clc
clear all;
close all;
%----
pop_size=20;
%
best_pop_size=5;
clone_size_factor=1;
%
MaxIter=100;
Max_error=0.000000002;
%
D=[Inf,13,10,Inf,Inf,20;
13,Inf,10,15,Inf,Inf;
10,10,Inf,11,Inf,2;
Inf,15,11,Inf,6,Inf;
Inf,Inf,Inf,6,Inf,9;
20,Inf,2,Inf,9,Inf] ;
CityNum=size(D,1);
%
if size(D,1)~=size(D,2)
disp('D is Incorrect')
return;
end
%
lb=1;
%
ub=10;
%
%--------------------
%
for i=1:pop_size
AntiBodies(:,i)=lb+(ub-lb)*rand
(1,CityNum);
end
Code AIS
Matlab
%
for Iter=1:MaxIter
%---------- ---------
%
for N=1:pop_size
[Ab_Match(N),tour(:,N)]=fit_fun(A
ntiBodies(:,N),D);
end
%
[Min_fit,index]=sort(Ab_Match);
%
Min_fit_Cel=AntiBodies(:,index);
%
Cel_best_pop=Min_fit_Cel(:,1:best
_pop_size);
%
%----------------------
Fit_best_pop=Min_fit(:,1:best_pop_
size);
%
Max_Fit=max(Fit_best_pop);
Min_Fit=min(Fit_best_pop);
Fit_best_pop=Fit_best_pop/Max_Fi
t;
%
%--------------------
clonePop=[];
for clone=1:best_pop_size
Num_Copy=round((clone_size_factor*pop_si
ze)/clone);
clone_best_pop= Cel_best_pop(:,clone);
clonePopi=repmat(clone_best_pop,[1,Num_
Copy]);
% %
%------------------
for z=1:Num_Copy
Mutate_rate= (1)*exp(-Fit_best_pop(clone)
); clonePopi(:,z)=clonePopi(:,z) + Mutate_rat
e*((rand(CityNum,1)-rand(CityNum,1))*Min_Fit);
clonePopi(clonePopi<lb)=lb+(ub-lb)*rand;
clonePopi(clonePopi>ub)=lb+(ub-lb)*rand;
end
Code AIS
Matlab
clonePop=[clonePop clonePopi]
;end
%--------------
%
%---------------------
clone=1;
while clone<=size(clonePop,
2) j=clone+1;
while j<=size(clonePop,2)
if isequal(clonePop(:,clo
ne),clonePop(:,j))
clonePop(j,:)=[];
end
j=j+1;
end
clone=clone+1;
end
%
for k=1:length(clonePop)
[MatchClonPop(k) ,tour(:,k)
]=fit_fun(clonePop(:,k),D);
end
%
[Min_fit,index]=sort(MatchClonPop);
Min_fit_clonePop=clonePop(:,index);
tour=tour(:,index);
%
Re_Cel_best_pop=Min_fit_clonePop(:,1:best
_pop_size);
AntiBodies(:,1:best_pop_size)=Re_Cel_best_
pop;
%
tour=tour(:,1:best_pop_size);
%
minF=Min_fit(1);
if Iter==1
%
MemoryCell=Min_fit_clonePop(:,1);
MemoryCellFit=minF;
%
BestTour=tour(:,1);
elseif MemoryCellFit>minF
Code AIS
Matlab
MemoryCell=Min_fit_clonePo
p(:,1);
MemoryCellFit=minF;
%
BestTour=tour(:,1);
end
if minF < Max_error
%
break
end
disp(['In Iteration ' num2str(I
ter) ' Shortest Path Len IS : ' n
um2str(MemoryCellFit)]);
end
disp('Best Path Is : ');
disp(BestTour);
disp(MemoryCellFit)
Thank you
And I hope you have a great day