A list,

1. Immune Algorithm

1.1 Basic steps of immune algorithm:

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

(2) Initial antibody generation. Random generation of initial antibody population.

(3) Affinity calculation. Calculate the fitness of antibodies. Comprehensive evaluation of each solution individual in the solution population, including the fitness (affinity) of the solution (antibody) and the problem (antigen) and the similarity between solutions (affinity)

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

(5) Immune selection: select antibodies with high affinity according to their affinity.

(6) Cloning: to replicate the selected antibody with high affinity.

(7) variation: to clone the individual crossover, variation operation, so that its affinity changes.

(8) Inhibition: Select mutated antibodies and retain those with higher affinity.

(9) 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 difference between immune algorithm and genetic algorithm



Immune algorithm is a multi-peak search algorithm designed to simulate the immune system’s ability to recognize the diversity of bacteria (that is, the immune system can recognize almost infinite kinds of bacteria), and its specific steps are as follows



Ii. Source code

%% Clean environment CLC; Clear %% Load scheduleData Jm T JmNumber Q % Process time %% Basic parameter NIND=40; % Number of individuals MAXGEN=80; % Maximum genetic algebra GGAP=0.9; Generation gap XOVR % =0.8; % crossover rate MUTR=0.1; % variance gen=0; [PNumber MNumber]=size(Jm); trace=zeros(2, MAXGEN); % Initial search result WNumber=PNumber*MNumber; %% Number=zeros(1,PNumber); % PNumber Number of artifactsfor i=1:PNumber Number(i)=MNumber; %MNumber Number of operations End % code2Layer, layer 1 process, layer 2 machine Chrom= Zeros (NIND,2*WNumber);
for j=1:NIND
    WPNumberTemp=Number;
    for i=1:WNumber % random production process val=unidrnd(PNumber);while WPNumberTemp(val)= =0val=unidrnd(PNumber); Chrom(j, I)= val; WPNumberTemp(val)=WPNumberTemp(val)- 1; % of the first2Temp=Jm{val, mnumber-wpNumberTemp (val)}; SizeTemp=length(Temp); % Chrom(j, I +WNumber)= unidrnd(SizeTemp); [PVal ObjV P S]= CAL (Chrom,JmNumber,T,Jm); %% loop searchwhileGen <MAXGEN % allocates fitness value FitnV=ranking(ObjV); % select operation SelCh=select('rws', Chrom, FitnV, GGAP); SelCh=across(SelCh,XOVR,Jm,T); SelCh=aberranceJm(SelCh,MUTR,Jm,T); % calculate target fitness value [PVal ObjVSel P S]= CAL (SelCh,JmNumber,T,Jm); % reinsert new population [Chrom ObjV] = REINS (Chrom, SelCh,1.1, ObjV, ObjVSel); % generation counter increment gen=gen+1; % Save the best value trace(1, gen)=min(ObjV);       
    trace(2, gen)=mean(ObjV); % records the best valueif gen==1Val1=PVal; Val2=P; MinVal=min(ObjV); % Minimum time STemp=S; End % records the smallest procedureif MinVal> trace(1,gen)
        Val1=PVal;
        Val2=P;
        MinVal=trace(1,gen); STemp=S; End end % PVal=Val1; % process time P=Val2; S = % process STemp; % scheduling gene with machine gene %% description solution change figure(1)
plot(trace(1:)); hold on; plot(trace(2, :).'-'); grid; legend('Change of solution'.'Change in population mean'); %% display the optimal solution figure(2);
MP=S(1,PNumber*MNumber+1:PNumber*MNumber*2);
for i=1:WNumber  
    val= P(1,i);
    a=(mod(val,100)); B = % process (/ (val - a)100); Temp = % workpiece Jm {b, a}; mText=Temp(MP(1,i));
    
    x1=PVal(1,i);
    x2=PVal(2,i);
    
    y1=mText- 1;
    y2=mText;
    PlotRec(x1,x2,mText);
    
    PlotRec(PVal(1,i),PVal(2,i),mText);
    hold on;
    function NewChrom=across(Chrom,XOVR,Jm,T)

% Chrom=[1 3 2 3 1 2 1 3 2; 
%     1 1 2 3 3 1 2 3 2;
%     1 3 2 3 2 2 1 3 1;
%     1 3 3 3 1 2 1 2 2; %]; % XOVR=0.7;

[NIND,WNumber]=size(Chrom);
WNumber=WNumber/2; NewChrom=Chrom; % initialize new population [PNumber MNumber]=size(Jm); Number=zeros(1,PNumber);
for i=1:PNumber
  Number(i)=1; SelNum=randperm(NIND); Num=floor(NIND/2); % Number of cross individual pairsfor i=1:2:Num
    ifXOVR>rand; Pos=unidrnd(WNumber); % cross positionwhile Pos==1Pos=unidrnd(WNumber); S1=Chrom(SelNum(I),1:WNumber);
        S2=Chrom(SelNum(i+1),1:WNumber); S11=S2; S22=S1; % initializes the new individual % of the intermediate fragment of the new individualCOPY      
        S11(1:Pos)=S1(1:Pos);      
        S22(1:Pos)=S2(1:Pos); % Comparison of S11 relative to S1,S22 relative to S2 gene S3=S11; S4=S1; S5=S22; S6=S2;for j=1:WNumber         
           Pos1=find(S4==S3(j),1);
           Pos2=find(S6==S5(j),1);
           if Pos1>0
               S3(j)=0;
               S4(Pos1)=0;
           end                         
           if Pos2>0
               S5(j)=0;
               S6(Pos2)=0;
           end
        end
        for j=1:WNumber          
          if S3(j)~=0% redundant gene Pos1=find(S11==S3(j),1);        
            Pos2=find(S4,1); S11(Pos1)=S4(Pos2); % Replacement of redundant genes with missing genes S4(Pos2)=0;       
          end 
          if S5(j)~=0              
            Pos1=find(S22==S5(j),1); 
            Pos2=find(S6,1);           
            S22(Pos1)=S6(Pos2);
            S6(Pos2)=0; S1=Chrom(SelNum(I),:); S2=Chrom(SelNum(i+1), :);for k=1:WNumber            
            Pos1=Find(S11(k),S1);           
            S11(WNumber+k)=S1(WNumber+Pos1);
            S1(Pos1)=0;
            
            Pos1=Find(S22(k),S2);           
            S22(WNumber+k)=S2(WNumber+Pos1);
            S2(Pos1)=0;
        end
Copy the code

3. Operation results



Fourth, note

Version: 2014 a