Immune algorithm is a new intelligent search algorithm, which is inspired by the biological immune system, and it is a heuristic stochastic search algorithm combining deterministic and stochastic selection with the ability of "exploration" and "mining".
The main steps of the algorithm:
(1) Antigen recognition and initial antibody production.
(2) Antibody evaluation
(3) Immune operation
The characteristics of immune algorithm:
(1) Global search capability
(2) Diversity retention mechanism
(3) Strong robustness
(4) Parallel distributed search mechanism
Immune Algorithm Flowchart:
(1) Antigen recognition, that is, understand the problem to be optimized, analyze the feasibility of the problem, extract the prior knowledge, construct the appropriate affinity function, and make various constraints.
(2) The initial antibody group, by encoding the feasible solution of the problem into the solution space of antibodies, in the solution space randomly generated an initial population.
(3) To evaluate the affinity of each feasible solution in the population.
(4) Judge whether satisfies the algorithm termination condition, if satisfies the condition then terminates the algorithm optimization process, the output computation result, otherwise continues the optimization operation.
(5) Calculate antibody concentration and excitation degree.
(6) Immunological treatment, including immune selection, cloning, mutation and cloning inhibition.
Immune selection: According to the affinity and concentration of antibody in the population, select high quality antibody to activate it.
Cloning: Cloning and reproducing of activated antibodies and obtaining several copies;
Mutation: mutation operation of the cloned copy to make it occur affinity mutation;
Cloning inhibition: The mutation of the results of the selection, inhibit the affinity of low antibody, the retention of high affinity mutation results.
(7) Population refresh, with randomly generated new antibodies to replace the less stimulating antibody in the population, to form the next generation of antibodies, the step (3).
Immune algorithm solves TSP problem:
%%% A traveling businessman wants to visit 31 provincial capitals, need to select the shortest path%%%%% population np=200% immune individual dimension n=31% iteration g=1000% clone individual number of ncl=10% any two cities distance matrix D%%% Immune algorithm solves TSP problem% %%%%%%%%% Initialize%%%%%%% clear all; % clears all variables close to all; % clear Figure CLC; % of the 31 provincial capitals of the national capital city coordinates c=[1304 2312; 3639 1315; 4177 2244; 3712 1399; 3488 1535; 3326 1556; 3238 1229; 4196 1004; 4312 790; 4
386 570;
3007 1970;
2562 1756;
2788 1491;
2381 1676;
1332 695;
3715 1678;
3918 2179;
4061 2370;
3780 2212;
3676 2578;
4029 2838;
4263 2931;
3429 1908;
3507 2367;
3394 2643;
3439 3201;
2935 3240;
3140 3550;
2545 2357;
2778 2826; 2370 2975];%31 Capital coordinates n=size (c,1); The scale of the%tsp problem, that is, the number of cities D=zeros (N);
% of any two city distance interval matrices, initialization is 0 any two city distance interval matrix% for i=1:n for j=1:n D (i,j) = ((c (i,1) (j,1)) ^2+ (C (i,2)-C (j,2)) ^2) ^0.5; End End np=200; % immune individual number g=1000; % Max Immune Algebra F=zeros (N,NP); % is used to store the population for I=1:np F (:, i) =randperm (N); % randomly generated initial population end Len=zeros (np,1); % storage path length for I=1:NP len (i) =func3 (d,f (:, i), N);
% randomly generated initial population end [Sortlen,index]=sort (Len); Sortf=f (:, Index); % speciesGroup individual sort gen=0; % immune Algebra nc1=10; % clone number%%%%%%%%%%%%%%%%%%%%%% immune cycle%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% while gen<g%%%%%%%%%%%%%%%%% selective excitation degree before NP
/2 Individuals perform immunological operations%%%%%%%%%%% for I=1:NP/2 a=sortf (:, i);
Ca=repmat (A,1,NC1);
For J=1:nc1 P1=floor (1+n*rand ());
P2=floor (1+n*rand ());
While P1==p2 P1=floor (1+n*rand ());
P2=floor (1+n*rand ());
End percent element of the Exchange Temp=ca (P1,J);
Ca (p1,j) =ca (P2,J);
Ca (p2,j) =temp; End Ca (:, 1) =sortf (:, i); % reserved clone source individual%%%%%%%%%%%%%%%% cloning inhibition, the individual with the highest retention affinity%%%%%%%%%%%%%%%% for j=1:nc1 Calen (j) =func3 (D,ca
(:, J), N);
End [Sortcalen,index]=sort (Calen);
Sortca=ca (:, Index);
AF (:, i) =SORTCA (:, 1);
Alen (i) =sortcalen (1); End%%%%%%%%%%%%%%%%% population refresh%%%%%%%%%%% for i=1:nP/2 BF (:, i) =randperm (N); % randomly generated initial population blen (i) =func3 (D,BF (:, i), N);
% compute path length End%%%%%%%%%%%%%%%%% immune population combined with new population%%%%%%%%%%% F=[AF,BF];
Len=[alen,blen];
[Sortlen,index]=sort (Len);
Sortf=f (:, Index);
gen=gen+1;
Trace (gen) =sortlen (1); End%%%%%%%%%%%%%%%%%%%%%% Output Optimization results%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bestf=sortf (:, 1); % optimal variable bestlen=trace (end);
% optimal value%%%%% Figure 1 figure for i=1:n-1 plot ([C (BESTF (i), 1), C (BESTF (i+1), 1)],...
[C (BESTF (i), 2), C (BESTF (i+1), 2)], ' bo-');
Hold on;
End Plot ([C (BESTF (N), 1), C (BESTF (1), 1)],...
[C (BESTF (N), 2), C (BESTF (1), 2)], ' ro-');
Title ([' Optimize shortest distance: ', Num2str (Trace (end)]);
%%%% Figure 2 Figure plot (trace) xlabel (' Iteration number ') ylabel (' objective function value ') title (' Affinity Evolution curve ')
function len=func3 (d,f,n)
Len=d (f (N), F (1));
For I=1: (N-1)
len=len+d (f (i), F (i+1));
End End