matlab、lingo程序代码3-背包问题遗传算法资料资料

matlab、lingo程序代码3-背包问题遗传算法资料资料

ID:41688198

大小:13.12 KB

页数:3页

时间:2019-08-30

matlab、lingo程序代码3-背包问题遗传算法资料资料_第1页
matlab、lingo程序代码3-背包问题遗传算法资料资料_第2页
matlab、lingo程序代码3-背包问题遗传算法资料资料_第3页
资源描述:

《matlab、lingo程序代码3-背包问题遗传算法资料资料》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、背包问题---遗传算法解决functionPopulation1=GA_copy(Population,p,w0,w)%复制算子%Population为种群n=length(Population(:,1));fvalue=zeros(1,n);fori=1:nfvalue(i)=GA_beibao_fitnessvalue(Population(i,:),p,w0,w);endfval=fvalue/sum(fvalue);F(1)=0;forj=1:nF(j+1)=0;fork=1:jF(j+1)=F(j+1)+fval(k);endendfori=1:ntest=rand;for

2、j=1:nif((test>=F(j))&&(test

3、forz=1:lPOP(j,z)=Population(i,z);endPOP(j,l+1)=i;p(j)=randint(1,1,[1l-1]);j=j+1;endendk0=j-1;k=floor(k0/2);ifk>=1form=1:kfort=p(2*m-1)+1:ls=POP(2*m-1,t);POP(2*m-1,t)=POP(2*m,t);POP(2*m,t)=s;endendform=1:k0fori=1:lPopulation1(POP(m,l+1),i)=POP(m,i);endendendfunctionfitnessvalue=GA_fitnessvalue(x

4、,p,w0,w)%使用惩罚法计算适应度值%x为染色体%p为背包问题中每个被选物体的价值%w0为背包问题中背包总容积%w为背包问题中每个被选物品的容积l=length(x);fori=1:la(i)=p(i).*x(i);endf=sum(a);b=min(w0,abs(sum(w)-w0));fori=1:lwx(i)=w(i).*x(i);endifabs(sum(wx)-w0)>b*0.99p=0.99;elsep=abs(sum(wx)-w0)/b;endfitnessvalue=f*(1-p)*(1-p)*(1-p);functionPopulation=GA_Initial

5、(n,P)%n为染色体长度,即所供选择的物品总数%P为初始种群大小fori=1:Pforj=1:ntemp=rands(1,1);iftemp>0Population(i,j)=1;elsePopulation(i,j)=0;endendendfunctionPopulation1=GA_tubian(Population,pe_tubian)%遗传算法突变算子%pe为突变概率Population1=Population;n=length(Population(:,1));m=length(Population(1,:));fori=1:nforj=1:mtest=rand;ifte

6、st

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

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

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