⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutation.asv

📁 遗传算法解决排课问题
💻 ASV
字号:
% 2.6 变异
% 变异(mutation),基因的突变普遍存在于生物的进化过程中。变异是指父代中的每个个体的每一位都以概率 pm 翻转,即由“1”变为“0”,
% 或由“0”变为“1”。遗传算法的变异特性可以使求解过程随机地搜索到解可能存在的整个空间,因此可以在一定程度上求得全局最优解。
%遗传算法子程序
%Name: mutation.m
%变异

%*********三维变异算子***************
%步骤:
%1:产生0-1之间随机数rand,判断是否需要变异
%2:产生1-t(t表示时间间隔,模型中都为t=40)之间随机整数mpoint,mpoint1,交换t坐标分别为mpoint,mpoint1,T,r坐标相同的基因块值
function [newpop]=mutation(pop,pm)
[px,py]=size(pop);
newpop=ones(size(pop));
for i=1:px
    if(rand<pm) %产生一随机数与变异概率比较
       mpoint=round(rand*40);
       if mpoint<=1
          mpoint=1;
       end
       mpoint1=round(rand*40);
       if mpoint1<=1
          mpoint1=1;
       end
       for j=1:py
           [r,T,t]=bianma(j);  %解码
              if r==mpoint
                  if j>1
                     T1=[T1,T];
                     t1=[t1,t];
                  else
                      T1=T;
                      t1=t;
                  end
              elseif r==mpoint1
                  if j>1
                     T2=[T2,T];
                     t2=[t2,t];
                  else
                      T2=T;
                      t2=t;
                  end
              end
       end
       Z1=[T1;t1];
       Z2=[T2;t2];   %现在得出了mpoint,mpoint1的所有有关基因的另外两个编码
        for j=1:length(Z1)
            jj=1; 
            while jj<length(Z2)+1
                if Z1(:,j)==Z2(:,jj)
                    pop(i,bianma1(mpoint,Z1(1,j),Z1(2,j)))=pop(i,bianma1(mpoint1,Z2(1,jj),Z2(2,jj)));
                    %交换t坐标分别为mpoint,mpoint1,T,r坐标相同的基因块值
                else
                    jj=jj+1;
                end
            end
        end
    end
    newpop(i,:)=pop(i,:);
end

⌨️ 快捷键说明

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