function M = MatingPool(P,f)
% M = MatingPool(P,f)
%This function inputs an initial population P, as a matrix whose rows are
%binary strings of the same length (for some GA problem), and an objective
%function f (for the GA).  The output is a matrix M of the same size as
%P, each of whose rows have been randomly selected from the rows of P where
%the probability that a given row is selected equals its fitness level
%divided by the sum of all the fitness values of the rows of P.  The 
%nonnegative fitness function used is simply max(0,f(x)).
[n s]=size(P);
for i=1:n
    Fitness(i)=max([0, feval(f, bin2int(P(i,:)))]);
end
Prop = Fitness/sum(Fitness);
for i=1:n
    t=rand; j=1; CutOff = Prop(j);
    while t >= CutOff
        j=j+1; CutOff = CutOff + Prop(j);
    end
    M(i,:)=P(j,:);
end

    
    
    