You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
656 B

6 years ago
function [idx1,idx2] = selection(PopulationSize,FitnessSum,PopulationFitness,Index)
%轮盘赌法,确定要交叉的父母编号
%确定要交叉的父亲序号
m1=0;
r1=rand*FitnessSum;
for k=1:PopulationSize
m1=m1+PopulationFitness(k);
if r1<=m1
idx1=Index(k);
break;
end
end
%确定要交叉的母亲序号
m2=0;
r2=rand*FitnessSum;
for k=1:PopulationSize
m2=m2+PopulationFitness(k);
if r2<=m2
idx2=Index(k);
break;
end
end
end