function recombinatedInds = recombination(indsDec,selectedInds,N) indsToRecombinate=indsDec(selectedInds(:)); indsBin=dec2bin(indsToRecombinate,8); for i=1:2:(N-1) parent1=indsBin(i,:); parent2=indsBin(i+1,:); r=randi(1,2,7)+1; if (r(1)==r(2) && r(2)~=7) r(2)=r(2)+1; end if (r(1)==r(2) && r(2)~=1) r(2)=r(2)-1; end r=sort(r); child1=[parent1(1:r(1)) parent2((r(1)+1):r(2)) parent1((r(2)+1):N)]; child2=[parent2(1:r(1)) parent1((r(1)+1):r(2)) parent2((r(2)+1):N)]; recombinatedInds(i,:)=child1; recombinatedInds(i+1,:)=child2; end end