mutation.m

来自「matlab遗传算法程序」· M 代码 · 共 13 行

M
13
字号
function popnew=mutation(pop,pmut,n,length)
%变异函数
%pmut为变异概率
k=1;
while k<=n
    rk=rand();
    if rk<pmut
        pos=fix(rand()*2*length)+1;   %随机产生变异点
        pop(k,pos)=~pop(k,pos);       %对变异点进行变异
    end
    k=k+1;
end
popnew=pop;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?