from
Genetic Algorithm to Optimise Schaffer's F6 Function
by Dean Kayton
A basic GA with a real-time plotting of evaluation funtion inputs and outputs
|
| [fitness,sel]=f6FitSel(f6EvalFun,popSize) |
function [fitness,sel]=f6FitSel(f6EvalFun,popSize)
%%% RANKED FITNESS %%%%
sortedMasses=sort(f6EvalFun);
for a=1:popSize
for b=1:popSize
if f6EvalFun(a)==sortedMasses(b)
rankOrder(a,:)=b;
end
end
end
fitness=rankOrder;
% %%% UNRANKED FITNESS %%%%
% fitness=f6EvalFun;
%Selection
prob = fitness./sum(fitness);
cumprob=cumsum(prob);
selNo=rand(popSize,1);
sel=zeros(popSize,1);
for k=1:popSize
sel(k,1)=find(cumprob>=selNo(k,1)==1,1);
end
|
|
Contact us