Immune Algorithm is a swarm intelligence search Algorithm with an iterative process of generate and test. Theoretically, in the iterative process, the immune algorithm is globally convergent on the premise of preserving the best individual of the previous generation.

Basic steps

  1. Antigen recognition. Input objective functions and various constraints as antigens for the immune algorithm.

  2. Initial antibody formation. Random generation of initial antibody population.

  3. Affinity computing. Calculate the fitness of antibodies.

  4. Immune treatment. Immune treatment includes immune selection, cloning, mutation and suppression.

    1. Immune selection: The selection of antibodies with high affinity based on their affinity.
    2. Cloning: Cloning of selected antibodies with high affinity.
    3. Variation: to clone the individual cross, variation operation, make its affinity change.
    4. Inhibition: selection of mutated antibodies and retention of antibodies with higher affinity.
  5. Group refresh. The immunoselected antibodies and immunosuppressed antibodies are formed into a set, and the antibodies with higher affinity are retained to make these antibodies enter a new population. New populations of deficient parts are randomly generated to increase diversity.

The flow chart

application

Application of %% immune optimization algorithm in location selection of logistics distribution center %% Clear environment % population size overbest=10; % memory size MAXGEN=100; % iteration number pcross=0.5; % cross probability pmutation=0.4; % variation probability ps=0.95; % diversity evaluation parameter Length =6; % number of distribution centers M=sizepop+overbest; Step1 identify the antigen and define the population information as a structure individuals = struct('fitness',zeros(1,M), 'concentration',zeros(1,M),'excellence',zeros(1,M),'chrom',[]); Step2 generate initial group of individuals with antibody. Chrom = popinit(M,length); trace=[]; % Optimal fitness and mean fitness were recorded in each generation %% Iterative optimization for III =1:MAXGEN %% Step3 Diversity evaluation of antibody population for I =1: Mindividuals. Fitness (I) = fitness(individuals.chrom(i,:)); % antibody and antigen affinity (fitness value) individuals. The concentration (I) = concentration (I, M, individuals); End % Combining affinity and concentration to evaluate the excellence of antibody, obtaining the breeding probability of individuals. Excellence = Excellence (individuals,M,ps); % Average fitness of contemporary best individuals and populations [best,index] = min(individuals. Fitness); % bestchrom = individuals. Chrom (index,:); % Find the optimal individual average = mean(individuals. Fitness); % calculate average fitness trace = [trace;best,average]; Step4 Form a parent group according to excellence and update the memory pool (add elite retention strategy, which can be controlled by S). Bestindividuals = Bestselect (individuals,M,overbest); % update individuals = bestselect(individuals,M,sizepop); Step5 Select, crossover, mutate, and then add antibodies to the memory bank to create a new population = Select(individuals,sizepop); % select individuals. The chrom = Cross (pcross, individuals chrom, sizepop, length); % cross individuals. The chrom = Mutation (pmutation, individuals chrom, sizepop, length); Variation individuals % = incorporate (individuals, sizepop bestindividuals, overbest); Figure (1) Plot (trace(:,1)); hold on plot(trace(:,2),'--'); Legend (' optimal fitness value ',' average fitness value ') title(' Immune algorithm convergence curve ','fontsize',12) xlabel(' iterations ','fontsize',12) yLabel (' fitness value ','fontsize',12) %% Draw the location map of the distribution center % city_coordinate=[1304,2312;3639,1315;4177,2244;3712,1399;3488,1535;3326,1556;3238,1229;4196,1044; 4312790; 4386570; 3007197; 2562175; 2788149; 2381167; 1332695; 3715167; 3918217; 4061237; 3780221; 3676257; 4029283; 4263293; 3429190; 3507237; 3394264; 3439320; 2935324; 3140355; 2545235; 2778282; 2370297 5]; ,90,90,60,70,70,40,90,90,70,60,40,40,40,20,80,90,70,100,50,50,50,80,70,80,40,40,60,70,50,30 carge = [20]; For I =1:31 distance(I,:)=dist(city_coordinate(I,:),city_coordinate(bestchrom,:)'); end [a,b]=min(distance'); index=cell(1,length); For I =1:length % index{I}=find(b== I); End figure(2) title(' optimal plan delivery route ') Cargox =city_coordinate(bestChrom,1); cargoy=city_coordinate(bestchrom,2); plot(cargox,cargoy,'rs','LineWidth',2,... 'MarkerEdgeColor','r',... 'MarkerFaceColor','b',... 'MarkerSize',20) hold on plot(city_coordinate(:,1),city_coordinate(:,2),'o','LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10) for i=1:31 x=[city_coordinate(i,1),city_coordinate(bestchrom(b(i)),1)]; y=[city_coordinate(i,2),city_coordinate(bestchrom(b(i)),2)]; plot(x,y,'c'); hold on endCopy the code

 

 

The complete code to download www.cnblogs.com/ttmatlab/p/…