www.pudn.com > TWVRP.rar > gjcrossover.m, change:2016-04-20,size:667b


function chrom=gjcrossover(chrom,fits) 
  
k1=0.8; 
% k2=0.9; 
[nx,ny]=size(chrom); 
totalfit=sum(fits); %求适应值之和 
fit1=fits./totalfit; %单个个体被选择的概率 
  
fitin=sort(fits); 
pc1=zeros(1,nx); 
for i=1:nx 
    for j=1:nx 
        if fits(i)==fitin(j); 
            pc1(i)=k1+(j-1)*((1-k1)^2)/(nx-1);%求交叉概率 
        end 
    end 
end 
for i=1:nx/2 
    a=randperm(nx); 
    pc=max(pc1(a(1)),pc1(a(2))); 
     if pc>=rand 
        b=randperm(ny); 
        c=[b(1),b(2)]; 
        d=sort(c); 
        e=chrom(a(1),d(1):d(2)); 
        f=chrom(a(2),d(1):d(2)); 
        chrom(a(1),d(1):d(2))=f; 
        chrom(a(2),d(1):d(2))=e; 
    end 
end 
  
  
chrom;