Browse Source

Create selection.m

master
TianZhendong 6 years ago
committed by GitHub
parent
commit
01077d4af1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      GA_PID/selection.m

25
GA_PID/selection.m

@ -0,0 +1,25 @@
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
Loading…
Cancel
Save