欢迎来到天天文库
浏览记录
ID:12743540
大小:16.52 KB
页数:4页
时间:2018-07-18
《遗传算法中mut变异算子函数说明》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、%MUT.m%%Thisfunctiontakestherepresentationofthecurrentpopulation,%mutateseachelementwithgivenprobabilityandreturnstheresulting%population.%这个函数代表当前种群,其中的每一个元素在变异概率下发生变化,并返回新的种群。%Syntax:NewChrom=mut(OldChrom,Pm,BaseV)%语法:新种群=mut(当前种群,变异概率,染色体个体元素的变异的基本字符)%注意:变异概率省略时为0.7/Lind(Lind为染色体长度),Bas
2、eV省略时种群为二进制编码%Inputparameters:%输入参数:%%OldChrom-Amatrixcontainingthechromosomesofthe%currentpopulation.Eachrowcorrespondsto%anindividualsstringrepresentation.%当前种群-一个矩阵包含当前人口的染色体。每一行对应一个字符串表示。%%Pm-Mutationprobability(scalar).Defaultvalue%ofPm=0.7/Lind,whereLindisthechromosome%lengthisassume
3、difomitted.%变异概率-变异概率(标量)。假定如果省略时,其默认值为0.7/Lind(Lind是染色体长度)%%BaseV-Optionalrowvectorofthesamelengthasthe%chromosomestructuredefiningthebaseofthe%individualelementsofthechromosome.Binary%representationisassumedifomitted.%染色体个体元素的变异的基本字符-染色体的单个元素的字符由染色体结构(相同长度的行%向量)定义的,假定如果省略时,默认为是二进制的。%%Out
4、putparameter:%输出参数:%NewChrom-AMatrixcontainingamutatedversionof%OldChrom.%新种群-当前种群变异后的矩阵。%Author:AndrewChipperfield%Date:25-Jan-94%%TestedunderMATLABv6byAlexShenfield(21-Jan-03)%举例说明该函数,利用OldChrom=crtbp(5,5)得到OldChrom=1100100000010110100000110functionNewChrom=mut(OldChrom,Pm,BaseV)%新种群=mut
5、(当前种群,变异概率,染色体个体元素的变异的基本字符).%getpopulationsize(Nind)andchromosomelength(Lind)%得到个体数(Nind)和染色体长度(Lind)。[Nind,Lind]=size(OldChrom);%返回值为Nind=5,Lind=5%checkinputparameters%检查输入参数ifnargin<2,Pm=0.7/Lind;endifisnan(Pm),Pm=0.7/Lind;end%上面2个if条件用来确定Pm的值。%第一个if:如果输入参数个数小于2,返回Pm为0.7/Lind。%第二个if:如果输入
6、的Pm不是数,返回Pm为0.7/Lind。%注:nargin是用来判断输入变量个数的函数。Isnan的函数功能:判断函数组的元素是否是%NaN(NotaNumber)。例如输入isnan(NaN),返回值为1;输入isnan(3),返回值为0.if(nargin<3),BaseV=crtbase(Lind);endif(isnan(BaseV)),BaseV=crtbase(Lind);endif(isempty(BaseV)),BaseV=crtbase(Lind);end%上面的3个if条件用来确定BaseV的值。%第一个if:如果输入参数个数小于3,则执行BaseV=
7、crtbase(Lind)的命令,并返回BaseV%的值。%第二个if:如果输入的BaseV不是数(如:NaN),则也执行BaseV=crtbase(Lind)的命令,%并返回BaseV的值。%第三个if:如果输入的BaseV为空(如:[]),则也执行BaseV=crtbase(Lind)的命令,并返%回BaseV的值。%注:isempty的函数功能:判断一个数组是否为空。如果为空,返回值为1;如果非空,返%回值为0.例如输入isempty([]),返回值为1,;输入isempty(1),返回值为0。if(narg
此文档下载收益归作者所有