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


% The select oprator function 
function newpop=selection(pop,adapt,best_indiv) 
%选择算子 
%其中 
m=size(pop,2); 
l=size(pop,1); 
new_pop=zeros(size(pop)); 
ada_sum=0; 
ada_temp=0; 
for i=1:l 
    ada_sum=ada_sum+adapt(i); 
end 
 
for i=1:l-1 
    rd=rand; 
    temp=0; 
    s=1; 
    while(temp<rd)&(s<=l) 
        temp=temp+adapt(s)/ada_sum; 
        s=s+1; 
    end 
    if s==1 
        s=1; 
    else  
        s=s-1; 
    end 
    new_pop(i,:)=pop(s,:); 
 
end 
 
 
%最优解复制 
for i=1:m 
    new_pop(l,i)=best_indiv(i); 
end 
 
%将选择产生的新群体复制给pop种群 
for i=1:l 
    for j=1:m 
        newpop(i,j)=new_pop(i,j); 
    end 
end 
 
clear i; 
clear j; 
clear k; 
clear r; 
clear ada_temp; 
end