资源简介

采用排挤机制的小生境遗传算法仿真程序(MATLAB仿真)

资源截图

代码片段和文件信息

%小生境遗传算法主程序 
function f=NicheSGA_1; 
%Optimizationstyle=‘Min‘;VarietyNumber=1;Xmin=[0];Xmax=[10*pi];PopulationSize=100;GenotypeLength=20;MaxGeneration=100;L=5; 
Optimizationstyle=‘Max‘;VarietyNumber=1;Xmin=[0];Xmax=[1];PopulationSize=100;GenotypeLength=20;MaxGeneration=100;L=0.18; 
Pc=0.9;Pm=0.01;N=PopulationSize/2;Penalty=10^(-30); 
initpop=randint(PopulationSizeVarietyNumber*GenotypeLength+VarietyNumber+2); 
oldpop=decode(OptimizationstyleVarietyNumberPopulationSizeXminXmaxGenotypeLengthinitpop); 
[Bindex]=sort(oldpop(:VarietyNumber*GenotypeLength+VarietyNumber+2)); 
oldpop=[oldpop(index(:):)]; 
temp1=oldpop(PopulationSize-N+1:PopulationSize:); 
k=1; 
while k<=MaxGeneration 
    newpop=selection(VarietyNumberPopulationSizeGenotypeLengtholdpop); 
    randorder=randperm(PopulationSize); 
    for i=1:2:(PopulationSize-1) 
        parent1=newpop(randorder(i):); 
        parent2=newpop(randorder(i+1):); 
        [child1child2]=crossover(VarietyNumberGenotypeLengthparent1parent2Pc); 
        newpop(randorder(i):)=child1; 
        newpop(randorder(i+1):)=child2; 
    end 
    for i=1:PopulationSize 
        newpop(i:)=mutation(VarietyNumberGenotypeLengthPmnewpop(i:)); 
    end 
    newpop=decode(OptimizationstyleVarietyNumberPopulationSizeXminXmaxGenotypeLengthnewpop); 
    faveragevalue(k)=mean(newpop(:VarietyNumber*GenotypeLength+VarietyNumber+1)); 
    if (Optimizationstyle==‘Max‘) 
        optimization(kVarietyNumber+1)=max(newpop(:VarietyNumber*GenotypeLength+VarietyNumber+1)); 
    else 
        optimization(kVarietyNumber+1)=min(newpop(:VarietyNumber*GenotypeLength+VarietyNumber+1)); 
    end 
    [tfindex]=ismember(optimization(kVarietyNumber+1)newpop(:VarietyNumber*GenotypeLength+VarietyNumber+1)); 
    optimization(k1:VarietyNumber)=newpop(indexVarietyNumber*GenotypeLength+1:VarietyNumber*GenotypeLength+VarietyNumber); 
    temp2=[temp1‘ newpop‘]‘; 
    temp2=niche(PopulationSizeVarietyNumberGenotypeLengthNLPenaltytemp2); 
    [Bindex]=sort(temp2(:VarietyNumber*GenotypeLength+VarietyNumber+2)); 
    temp2=[temp2(index(:):)]; 
    temp1=temp2(PopulationSize+1:PopulationSize+N:); 
    oldpop=temp2(N+1:PopulationSize+N:); 
    k=k+1; 
end 
if (Optimizationstyle==‘Max‘) 
    optimizationf=max(optimization(:VarietyNumber+1)) 
else 
    optimizationf=min(optimization(:VarietyNumber+1)) 
end 
[tfindex]=ismember(optimizationfoptimi

评论

共有 条评论