%Immune Algorithm based on the immune network model for function
f(x1,x2) optimum
%copy right SCUT Guangxing Tan 2005.02.18
clear all;
%Parameters
Size=120;
G=200;
CodeL=15;
E=round(rand(Size,2*CodeL)); %Initial Code
%Main Program
for k=1:1:G
time(k)=k;
for s=1:1:Size
m=E(s,:);
y1=0;y2=0;
%Uncoding
m1=m(1:1:CodeL);
for i=1:1:CodeL
y1=y1+m1(i)*2^(i-1);
end
x1=10.24*y1/65535.0-5.12;
m2=m(CodeL+1:1:2*CodeL);
for i=1:1:CodeL
y2=y2+m2(i)*2^(i-1);
end
x2=10.24*y2/65535.0-5.12;
%f(X1,X2)=(a/(b+(x1*x1+x2*x2)))*(a/(b+(x1*x1+x2*x2)))+(x1*x1+x2*x
2)*(x1*x1+x2*x2)
%here -5.12=<x1<-2, -5.12=<x2<=5.12, a=3.0, b=0.05;
%
f(X1,X2)=90+(a/(b+(x1*x1+x2*x2)))*(a/(b+(x1*x1+x2*x2)))+(x1*x1+x2
*x2)*(x1*x1+x2*x2)
% here -2=<x1<=5.12, -5.12=<x2<=5.12
% f(X)=(-x+3*M_PI-0.5)(1+sinx*sinx) if 1.5M_PI<x<=2M_PI;
if x1<-2