From 12e19ee37117299d3ea99e93c19d0d61b9663b8a Mon Sep 17 00:00:00 2001 From: TianZhendong <33273211+TianZhendong@users.noreply.github.com> Date: Thu, 11 Apr 2019 21:50:58 +0800 Subject: [PATCH] Create mutation --- GA_PID/mutation | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 GA_PID/mutation diff --git a/GA_PID/mutation b/GA_PID/mutation new file mode 100644 index 0000000..66c82ab --- /dev/null +++ b/GA_PID/mutation @@ -0,0 +1,12 @@ +function y= mutation(n,MutateRate,x) +%n为染色体长度 +%MutataRate为变异概率 +%x为待变异染色体 +rate=rand; %随机概率判断是否变异 +if rate<=MutateRate + mutate_pos=floor(rand*n+1); %产生一个变异位置 + x(mutate_pos)=floor(rand+1); %bianyi +end +y=x; +end +