simplemutation.m

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

M
38
字号
function G=SimpleMutation(G,Pm)

%[m,n]=size(G);
%
%for i=1:m
%    for j=1:n
%        if rand<Pm
%            G(i,j)=~G(i,j);
%        end
%    end
%end
%
%B=zeros(size(G));
%for i=1:m
%    for j=1:n
%        if rand<Pm
%            G(i,j)=1;
%        end
%    end
%end
%G=xor(G,B);
%
%for i=1:m
%    B=rand(1,n);
%    B(B<Pm)=0;
%    B(B>=Pm)=1;
%    B=~B;
%    G(i,:)=xor(G(i,:),B);
%end
%
%B=rand(size(G));
%B(B<Pm)=0;
%B(B>=Pm)=1;
%B=~B;
%G=xor(G,B);


G=xor(G,rand(size(G))<Pm);

⌨️ 快捷键说明

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