www.pudn.com > LBG_GA.rar > crossover.m, change:2011-06-15,size:1011b


%交叉操作,概率为0.7,单点交叉 
%适应度低于平局适应度值的个体,对应较低的交叉和变异概率;高于平均适应度值的个体,对应较高的交叉和变异概率 
function cro_pop=crossover(pop,adapt,pc)   %pop为50*32*12 
global gen 
m=size(pop,1); 
n=size(pop,2); 
% k1=0.01; 
% k2=0.02; 
 
for i=1:2:m-1 
    cross_P=rand;   %随机产生一个数,以比较交叉概率 求最小值要k1《k2 
%     if min(adapt(i),adapt(i+1))<=mean(adapt) 
%         pc=k1*(min(adapt)-min(adapt(i),adapt(i+1))/(min(adapt(i),adapt(i+1))-mean(adapt))); 
%     else 
%         pc=k2; 
%     end 
    if cross_P<pc %交叉概率线性变换,由0.9下降到0.3 
%        if cross_P<pc 
        cross_pos=round(n*rand);   %交叉位置为0~9,若位置为0或1,则不进行交叉操作 
        if or(cross_pos==0,cross_pos==1) 
            continue; 
        end 
     
        for j=cross_pos:n 
            temp=pop(i,j); 
            pop(i,j)=pop(i+1,j); 
            pop(i+1,j)=temp; 
        end 
    end 
end 
cro_pop=pop; 
clear i; 
clear j; 
clear temp; 
clear cross_P; 
clear cross_pos; 
end