From fee3ed30376c13c828c334b26469ed8d820937ef Mon Sep 17 00:00:00 2001 From: TianZhendong <33273211+TianZhendong@users.noreply.github.com> Date: Thu, 11 Apr 2019 21:48:41 +0800 Subject: [PATCH] Create selection --- GA/selection | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 GA/selection diff --git a/GA/selection b/GA/selection new file mode 100644 index 0000000..25702f6 --- /dev/null +++ b/GA/selection @@ -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 +