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


function chrom=gjcrossover0(chrom,fits) 
  
k1=0.2; 
  
[nx,ny]=size(chrom); 
totalfit=sum(fits); %求适应值之和 
avefits=totalfit./nx; 
[maxfits,in]=max(fits); 
  
for i=1:nx/2 
    a=randperm(nx); 
    fits1=max(fits(a(1)),fits(a(2))); 
    fits2=min(fits(a(1)),fits(a(2))); 
    if (fits(a(1))+fits(a(2)))./2>avefits 
        pc=k1; 
    else 
        pc=(maxfits-fits1)./(maxfits-avefits); 
    end 
     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;