function [selectedInds fitness avgFitness] = selection(indsDec,y1,N) % y1=inline('sin((pi*x)/256)'); % fitness of individuals (f) fitness=y1(indsDec); % show individuals on function plot % clf % plot(indsDec,fitness,'rs','MarkerfaceColor','r','MarkerEdgeColor','k') % grid on % drawnow % pause(0.1) % average fitness (f nadvuceno) avgFitness=mean(fitness); % normalized fitness (ff) normFitness=fitness/avgFitness; % percentage for roulette wheel percFitness=normFitness/N; % cumulative fitness fKum fKum=100*cumsum(percFitness); rndNums=randi(1,N,100); selectedInds=zeros(1,N); for i=1:N selectedInds(i)=find(fKum>rndNums(i),1); end end