A list,

Immune algorithm is a search algorithm with stronger robustness and faster convergence speed, which overcomes the deficiency of genetic algorithm. It can solve the degradation phenomenon in genetic algorithm very well, so it has a wide application in solving complex optimal problems. For example, the traveling salesman problem: a businessman starts from a certain city and visits all the target cities, each of which must be visited only once. The specific process is as follows: 1 individual coding and fitness function (1) In algorithm implementation, the objective function of TSP problem corresponds to antigen, and the solution of the problem corresponds to antibody. (2) The antibodies are coded in the order of traversing the city, and each antibody code string is as follows :V1, V2… , Vn, where V represents the serial number of the traversal city. The fitness function is the reciprocal of path length Td:

The intersection and mutation operator are crossed by a single point, where the position of intersection and mutation point is determined randomly. In the algorithm, the inheritance of individual genotype and the diversity of individual characteristics needed for further optimization were evaluated, and a kind of partial path mutation method was designed. In this method, one section of the full length path is selected each time, and the starting point and end point of the sub-section of the path are determined by the evaluation results. The specific operation is the continuous n transposition, where the size of n is determined by the genetic algebra K. 3. Immune operator There are two types of immune operator: total immunity (non-specific immunity) and target immunity (specific immunity). Total immunity refers to the immune type that every individual in the population has a rabbit epidemic operation in every link after the action of the evolutionary operator. Target immunity is a type of immune response that occurs only at the point of action after a certain judgment after an evolutionary operation. For the traveling salesman problem, it is extremely difficult to find a vaccine suitable for the whole antigen (i.e., global problem solving), so we use target immunization. In solving the problem from each city point before you choose a path to the nearest points around each point, as a point of the city during the implementation of algorithm for target immune operation when the note of vaccine after genetic operation, random individuals vaccinated, then the immune detection, namely to test the vaccinated individuals: if improved fitness, continued to; On the contrary, if its fitness is not as good as that of the parent generation, it indicates that serious degeneration occurs in the process of crossover and mutation, and then the individual will be replaced by the corresponding individual in the parent generation. In the selection stage, the probability of being selected is calculated first, and then the corresponding conditions are judged. 4 Case The scale of 8 cities is selected below, and the coordinates of the cities are randomly generated.

Ii. Source code

clear all
clc
N=8; % Number of cities M=N- 1; % Number of species pos=randn(N,2); %% Generate city coordinates global D; % city distance data D=zeros(N,N);for i=1:N
    for j=i+1:N
        dis=(pos(i,1)-pos(j,1)). ^2+(pos(i,2)-pos(j,2)). ^2;
        D(i,j)=dis^(0.5);
        D(j,i)=D(i,j);
    end
end
unction result = CharRecompose(A)
global D;
index = A(1.2:end);
tmp = A(1.1);
result = [tmp];
[m,n] = size(index);
while n>=2
    len = D(tmp,index(1));
    tmpID = 1;
    for s = 2:n
        if len > D(tmp,index(s))
            tmpID = s;
            len = D(tmp,index(s));
        end
        function result = DisplaceInit(A)
[m,n] = size(A);
tmpCol = 0;
for col = 1:n
    if A(1,col) == 1
        tmpCol = col;
        break;
    end
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a