📄 mutation.m
字号:
function ret=Mutation(pmutation,lenchrom,chrom,sizepop,opts,pop,bound)
% In this function,it fulfils a mutation among chromosomes
% pcorss input : probability of mutation
% lenchrom input : length of a chromosome
% chrom input : set of all chromosomes
% sizepop input : size of population
% opts input : tag for choosing method of crossover
% pop input : current serial number of generation and maximum gemeration
% ret output : new set of chromosome
switch opts
case 'simple' % mutation at single position
for i=1:sizepop
% select child at random
pick=rand;
while pick==0
pick=rand;
end
index=ceil(pick*sizepop);
pick=rand;
if pick>pmutation
continue;
end
% mutation position
pick=rand;
while pick==0
pick=rand;
end
pos=ceil(pick*sum(lenchrom));
v=bitget(chrom(index),pos);
v=~v;
chrom1=bitset(chrom(index),pos,v);
end
ret=chrom;
case 'float' % multiple position mutation
for i=1:sizepop
% select child at random
pick=rand;
while pick==0
pick=rand;
end
index=ceil(pick*sizepop);
pick=rand;
if pick>pmutation
continue;
end
% mutation position
pick=rand;
while pick==0
pick=rand;
end
pos=ceil(pick*sum(lenchrom));
v=chrom(i,pos);
v1=v-bound(pos,1);
v2=bound(pos,2)-v;
pick=rand;
if pick>0.5
delta=v2*(1-pick^((1-pop(1)/pop(2))^2));
chrom(i,pos)=v+delta;
else
delta=v1*(1-pick^((1-pop(1)/pop(2))^2));
chrom(i,pos)=v-delta;
end
end
ret=chrom;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -