遗传算法matlab源程序

遗传算法matlab源程序

ID:38426044

大小:30.00 KB

页数:7页

时间:2019-06-12

遗传算法matlab源程序_第1页
遗传算法matlab源程序_第2页
遗传算法matlab源程序_第3页
遗传算法matlab源程序_第4页
遗传算法matlab源程序_第5页
资源描述:

《遗传算法matlab源程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、问题:求在[-2,2]之间的最小值。Pc=0.7Pm=0.3L=20.原始程序:function[Bestvalue,Bestmember]=Genetic(gen,min,max,fitnessfunction,crossrate,mutationrate,membernumber,memberlength)gen=input('Pleaseinputthevalueofgen:');min=input('Pleaseinputthevalueofmin:');max=input('Pleaseinputth

2、evalueofmax:');crossrate=input('Pleaseinputthevalueofcrossrate:');mutationrate=input('Pleaseinputthevalueofmutationrate:');membernumber=input('Pleaseinputthevalueofmembernumber:');memberlength=input('Pleaseinputthevalueofmemberlength:');population=population

3、initialize1(membernumber,memberlength);mmm=population;globalcount;count=1;populationcode=population;%populationdata=populationdata1(populationcode,min,max);populationdata=zeros(size(populationcode,1),1);fori=1:size(populationcode,1)forj=1:size(populationcode

4、,2)populationdata(i)=populationdata(i)+populationcode(i,j).*(2.^(size(populationcode,2)-j));endpopulationdata(i)=min+populationdata(i).*(max-min)./(2.^(size(populationcode,2))-1);l=0;endfitness=fitness1(populationdata);whilecount

5、s,population);newpopulation=select(population,fitnessp);population=newpopulation;newpopulation=crossing(population,crossrate);population=newpopulation;newpopulation=mutation(population,mutationrate);population=newpopulation;%populationdata=populationdata1(po

6、pulation,min,max);populationdata=zeros(size(population,1),1);fori=1:size(population,1)forj=1:size(population,2)populationdata(i)=populationdata(i)+population(i,j).*(2.^(size(population,2)-j));endpopulationdata(i)=min+populationdata(i).*(max-min)./(2.^(size(p

7、opulation,2))-1);l=0;endfitness=fitness1(populationdata);[fitness,B]=sort(fitness);%根据实际问题调整排序方式Bestvalue=log(fitness(1));Bestmember=populationdata(B(1));fori=1:membernumberfitness(i)=fitness(i);endcount=count+1;enddisp(fitness);functionnewpopulation=select(

8、population,fitnessp)rate(1)=fitnessp(1);fori=2:size(population,1)rate(i)=rate(i-1)+fitnessp(i);endfori=1:(size(population,1)+1)r=rand(1);o=1;whiler>rate(o)o=o+1;endnewpopulation(i,:)=population(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。