

function NewChrom = cross_over(OldChrom, Pro)

% Identify the population size (Nc) and the chromosome length (Lc)
[Nc,Lc] = size(OldChrom);

% randomly chose the 
Xops = floor(Nc/2);
Xops
fflush(stdout);
DoCross = rand(Xops,1) < Pro;
odd = 1:2:Nc-1;
even = 2:2:Nc;

% create the mask matrix which containing the crossover position of 
% each chromosome pair
Mask(Xops,Lc) = 0; 

% create the intervals to form random variable [1,Lc-1]
% interval = [0:1/(Lc-1):1];
% obtain the uniform distributed probability of each chromosome pair

%prov = randint(Xops,1,[1,Lc-1]);
prov = randint(floor(Nc/2),1,[1,Lc-1]);

% fill the mask matrix
for i = 1:Xops
    if DoCross(i,1) == 1
        
        Mask(i,1:prov(i,1)) = ones(1,prov(i,1));

    end
end
           

% Perform crossover
NewChrom(odd,:) = (OldChrom(odd,:).* (~Mask)) + (OldChrom(even,:).*(Mask));
NewChrom(even,:) = (OldChrom(odd,:).*(Mask)) + (OldChrom(even,:).*(~Mask));


% If the number of individuals is odd, the last individual cannot be mated
% but must be included in the new population
if rem(Nc,2),
  NewChrom(Nc,:)=OldChrom(Nc,:);
end
