§4.6变异算子1、离散变异算子—mut(低级函数)调用格式①NewChrom=mut(OldChrom,Pm)②NewChrom=mutt(OldChrom,Pm,BaseV)功能以概率Pm对种群OldChrom中的每个个体的元素进行变异。如果染色体和种群结构中允许不同的基本字符,则mut允许用一个附加的变量BaseV来指定染色体中每一元素的基本字符。各个选项的含义OldChrom—父代种群;NewChrom—子代种群;Pm—变异概率,默认为Pm=0.7/Lind;BaseV—染色体每位基因的变异的基本字符集。例1在命令窗口中输入OldChrom=crtbp(4,8)OldChrom=11111000010110001010010000101011%创建初始种群NewChrom=mut(OldChrom)NewChrom=11111000011110001010010000101011%以默认概率(0.7/8=0.0875)进行变异%以概率0.5进行变异NewChrom=mut(OldChrom,0.5)NewChrom=01011010101111100011110001111101例2在命令窗口中输入BaseV=crtbase([35],[84])BaseV=88844444%建立基本向量[Chrom,Lind,BaseV]=crtbp(6,BaseV)Chrom=423110310522100105103001155100324052321003533010Lind=8BaseV=88844444%创建初始种群NewChrom=mut(Chrom,0.078,BaseV)NewChrom=423110310522130205103001155102324052321006533010%以概率0.078进行变异调用格式①NewChrom=mutbga(OldChrom,FieldDR)②NewChrom=mutbga(OldChrom,FieldDR,MutOpt)功能以给定的概率对实值种群OldChrom中的每个个体的元素进行变异。2、实值变异算子——mutbga(低级函数)OldChrom——父代种群;NewChrom——子代种群;FieldDR——变量范围;MutOpt——是一个具有两个参数的可选项。MutOpt(1)指定变异概率,缺省为1/Nvar;MutOpt(2)是[0,1]之间的一个量,压缩变异的范围,默认为1(不压缩)。各个选项的含义例3在命令窗口中输入FieldDR=[-10,-5,-3,-1;10,5,3,1]FieldDR=-10-5-3-110531%定义变量范围Chrom=crtrp(6,FieldDR)Chrom=-9.0144-0.68130.61190.92271.42111.3427-1.4786-0.85594.01713.03032.24070.10689.2458-4.16120.0804-0.41605.01044.45461.39590.71594.79994.1594-0.4666-0.3285%产生初始种群NewChrom=mutbga(Chrom,FieldDR)NewChrom=-9.0144-0.68130.61190.92371.42111.3426-1.4787-0.85594.01713.03032.24070.10689.2458-4.16120.0804-0.41605.01044.45461.39590.71594.79994.1594-0.4667-0.3285%以默认概率(1/4=0.25)进行变异NewChrom=mutbga(Chrom,FieldDR,[1/41])NewChrom=-9.0144-0.68130.60020.92271.42111.3427-1.4786-0.85594.01713.03032.24070.10689.2458-4.16120.0804-0.41606.33914.45461.39590.71594.79994.1594-0.4655-0.3289%以概率0.25进行变异,步长为1调用格式①NewChrom=mutate(MUT_F,OldChrom,FieldDR)②NewChrom=mutbga(MUT_F,OldChrom,FieldDR,MutOpt)③NewChrom=mutbga(MUT_F,OldChrom,FieldDR,MutOpt,SUBPOP)功能以给定的概率对种群OldChrom中的每个个体的进行变异。3、个体变异算子——mutate(高级函数)各个选项的含义MUT_F—是一字符串,包含低级变异函数的名称;OldChrom—父代种群;NewChrom—子代种群;FieldDR—对于实值变量,FieldDR为一个2×Nvar的矩阵,指定每个变量的边界;对于离散变量,FieldDR为一个1×Nvar的矩阵,指定每个变量的基本字符;如果FieldDR省略或为NaN,则假设变量为二进制表示。MutOpt——是一个具有两个参数的可选项。MutOpt(1)指定变异概率,缺省为1/Nvar;MutOpt(2)是[0,1]之间的一个量,压缩变异的范围,默认为1(不压缩)。SUBPOP——指明OldChrom中子种群的数量,如果省略或为NaN,则假设SUBPOP=1,在OldChrom中每个子种群的大小必须相等。各个选项的含义例4在命令窗口中输入Chrom=crtbp(4,6)Chrom=001010100111010110001000%产生初始种群NewChrom=mutate('mut',Chrom)NewChrom=101010100111010110001000%调用低级函数mut以默认概率进行变异BaseV=[334444]BaseV=334444Chrom=crtbp(4,BaseV)Chrom=213222121233020331112322%根据基本字符集产生初始种群NewChrom=mutate('mut',Chrom,BaseV,1/2)NewChrom=020230001223123232002221%调用低级函数mut以0.5概率进行变异%定义变量范围例6在命令窗口中输入FieldDR=[0,0,0,0,0,0,0,0;8,8,8,4,4,4,4,4]FieldDR=0000000088844444%产生初始种群Chrom=crtrp(6,FieldDR)Chrom=7.19616.84837.55392.97563.78430.65312.66970.27315.54210.89666.70843.22733.26350.84401.24370.50093.51722.33252.06742.55033.72100.86721.22650.66465.60820.77960.34321.00511.23982.60722.88273.64574.87773.17960.04710.57731.07530.21113.81760.54502.39912.66654.59532.60622.14580.91720.52462.4680%调用低级函数mutbga进行变异NewChrom=mutate('mutbga',Chrom,FieldDR)NewChrom=7.19616.84837.55392.97563.78430.65312.66970.33565.54210.89666.70843.22783.26350.84441.24370.50093.51722.33252.06742.55033.72100.86721.22650.66465.60820.77960.34321.00511.23982.60722.88273.64574.87773.17960.04710.57731.07530.21013.81760.54502.39912.66654.59532.60622.14580.91720.52462.5305