function newchrom=cross0(Chrom,FieldD)
whole=fix(length(FieldD)/2);number=1; %set mother and the other is father which not select
mather=[1:2:whole*2];
if rem(length(FieldD),2)==0
father=[length(FieldD):-2:2];
else
father=[length(FieldD)-1:-2:2];
end
% 选择母亲和父亲。。具体的换成二进制,再随机选取更好
for Time=1:1:whole
social(1,Time)=abs(Chrom(mather(Time))-Chrom(father(Time)));
end
mean0=sum(social)/length(social); %计算整个社会的近亲平均水平 setting as 0.75,最低变异为0.6 高于0.95的设置为0.95
%越相似的个体,交叉的概率越低
num=10*(mean0-min(social));
p=social/num-ones(1,length(social))*min(social)/num+0.6;
p(p>0.95)=0.95;
for Time=1:1:length(social)
if rand()<=p(Time)
Chrom(mather(Time))=0.4* Chrom(mather(Time))+0.6*Chrom(father(Time));
Chrom(father(Time))=0.6* Chrom(mather(Time))+0.4*Chrom(father(Time));
end
end
newchrom=Chrom;
end