%% GRADE evaluating and selecting new population

%% EVALUATE_GENERATION 
for i = SelectedSize+1:PoolSize;
    if Return_to_domain == 1
        for k = 1:Dim 
            while CH(i,k) < Domain(k,1) CH(i,k) = Domain(k,1); end
            while CH(i,k) > Domain(k,2) CH(i,k) = Domain(k,2); end
        end
    end 
    Force(i) = F( (CH(i,:))' );
    fitness_call = fitness_call+1; 
    if Force(i) < btg_value
        btg_value = Force(i);
        btg(:)=CH(i,:); 
    end 

end 
if btg_value < bsf_value 
    bsf(:) = btg(:);
    bsf_value = btg_value; 
    Feval(fitness_call, bsf_value, bsf);
end 
if displayconf
    display( sprintf( '%12d   %10g   %10g', fitness_call, btg_value, bsf_value) );
end

ActualSize = PoolSize;

%% SELECT 
while ActualSize > SelectedSize
    i1 = randsample(ActualSize,1); 
    i2 = randsample(ActualSize-1,1)+1; 
    if i1 == i2 i2 = i2-1; end 
    if Force(i1) < Force(i2) dead = i2;  
    else dead = i1; end
    last = ActualSize; 
    CH(dead,:) = CH(last,:); 
    Force(dead) = Force(last); 
    ActualSize = ActualSize-1; 
end
generation = generation+1;

%% author: Anicka Kucerova, Czech Technical University in Prague
%% version 0.0.4
%% 30 Mar 2009