教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 高等教育 >

附录2求解RDC的 MATLAB 编程源代码

来源:网络收集 时间:2026-08-01
导读: 附录:求解RDC的 MATLAB 编程源代码 程序用MATLAB 6.0 编制而成的,基于遗传算法的程序,实现了求解配送模型的过程。 1.适值函数 function [sol,eval]=fitness(sol,options) d=[0 8 12 15 18 40 20 32 16; 8 0 13 8 20 10 15 22 20; 12 13 0 15 20 20 15

附录:求解RDC的 MATLAB 编程源代码

程序用MATLAB 6.0 编制而成的,基于遗传算法的程序,实现了求解配送模型的过程。 1.适值函数

function [sol,eval]=fitness(sol,options) d=[0 8 12 15 18 40 20 32 16; 8 0 13 8 20 10 15 22 20; 12 13 0 15 20 20 15 15 15; 15 8 15 0 20 10 18 18 30; 18 20 20 20 0 20 15 15 20; 40 10 20 10 20 0 14 18 15; 20 15 15 18 15 14 0 14 20; 32 22 15 18 15 18 14 0 20; 16 20 15 30 20 15 20 20 0]; G=[0 3 5 2 6 4 4 1 3]; s=rand(size(G)) T=[0 2 2 1 2.5 1.5 2 0.5 1.5]; A=[0 6 6 7 8 7 7 7 9]; B=[0 9 8 9 12 11 10 10 12]; sum2=0; sum3=0; sum4=0; for k=1:4 for i=1:9 forj=1:9 if (sum2<=10) xijk=1; else xijk=0; end sum3=sum3+xijk; if (sum3==1) ykj=1; else ykj =0; end sum2=sum2+G(j)*ykj; sum4=sum4+ykj; End end end c1=s(i)-A(i); c2=B(i)-s(i); if ((sum2-10<=0)&(sum4==1)&(c1>=0)&(c2>=0)) fsum=0; for i=1:9 for j=1:9 fsum=fsum+d(i,j)*xijk; end end eval=fsum; else eval=-10000; end eval=-eval; 2.遗传算法求解的MATLAB 代码 %the matrix for distance d=[0 8 12 15 18 40 20 32 16; 8 0 13 8 20 10 15 22 20; 12 13 0 15 20 20 15 15 15; 15 8 15 0 20 10 18 18 30; 18 20 20 20 0 20 15 15 20; 40 10 20 10 20 0 14 18 15; 20 15 15 18 15 14 0 14 20; 32 22 15 18 15 18 14 0 20; 16 20 15 30 20 15 20 20 0]; G=[0 3 5 2 6 4 4 1 3]; T=[0 2 2 1 2.5 1.5 2 0.5 1.5]; A=[0 6 6 7 8 7 7 7 9]; B=[0 9 8 9 12 11 10 10 12]; bounds=[2;2;2;2;2;2;2;2;2]; flag=0; while flag<10 init=initializega(1,bounds,'fitness'); sum2=0; sum3=0; sum4=0; for k=1:4 for i=1:9 for j=1:9 if (sum2<=10) xijk=1; else xijk=0; end sum3=sum3+xijk; if (sum3==1) ykj=1;

else ykj=0; end sum2=sum2+G(j)*ykj; sum4=sum4+ykj; end end end s(i)=rand(size(G)) c1=s(i)-A(i); c2=B(i)-s(i); if ((sum2<=10)&(sum4==1)&(c1>=0)&(c2>=0)) flag=flag+1; initPop(flag,:)=init; else Continue end end [p endPop bpop traceJ=ga(bounds,'fitness',[],initPop,[1e-5 1 1],... 'maxGeomSelect',[0.08],['arithXover'],[20],'nonUnifMutate',[2 1 3]); 3.初始化函数的MATLAB 代码 function [pop]=initializega(num, bounds, evalFN,evalOps,options) defaults [1e-6 1] if nargin<5 options=[1e-6 1]; end if nargin<4 evalOps=[]; end if any(evalFN<48) if options(2)==1 estr=('x=pop(i,1); pop(i,xZomeLength)=', evalFN';']; else estr=('x=b2f(pop(i,:),bounds,bits); pop(i,xZomeLength)=', evalFN ';']; end else if options(2)==1 estr=['[ pop(i,:) pop(i,xZomeLength)]='evalFN'(pop(i,:),[0 evalOps]);']; else estr=('x=b2f(pop(i,:),bounds,bits);[x v]='evalFN… '(x,[0 evalOps]); pop(i,:)=(f2b(x,bounds,bits) v];']; end end numVars=size(bounds, 1); rng=(bounds(:,2)-bounds(:,1))'; if options(2)==1 xZomeLength=numVars+1; pop=zeros(num,xZomeLength); pop(:,1:numVars)=(ones(num,1)*rng).*(rand(num,numVars))+... (ones(num,1)*bounds(:,1)'); else bits=calcbits(bounds,options(1)); xZomeLength=sum(bits)+1; pop(i,:)=round(rand(num,sum(bits)+1)); end for i=1:num bits=calcbits(bounds,options(1)); pop(:,1:numVars)=(ones(num, 1 )*rng).*(rand(num,numVars))+... (ones(num, 1)*bounds(:,1)'); End 4.终止函数的MATLAB 代码 function (done)=maxGenTerm(ops,bPop,endPop) currentGen=ops(1); maxGen=ops(2); done=currentGen>=maxGen; 5.基于正态分布的序列选择函数MATLAB 代码 function[newPop]=normGeomSelect(oldPop,options) q=options(2); e=size(oldPop,2); n=size(oldPop,1); newPop=zeros(n,e); fit=zeros(n,1); x=zeros(n,2); x(:,1)=[n:-1:1]; (y x(:,2)]=sort(oldPop(:,e)); r=q/(1-(1-q)^n); fit(x(:,2))=r* (1-q).^(x(:,1)-1); fit=cumsum(fit); rNums=sort(rand(n, 1)); fitIn=1; newIn=1; while newIn<=n if(rNums(newIn)

6.交叉函数的MATLAB 代码 function [cl,c2]=arithXover(pl,p2,bounds,Ops) c1=pl*a+p2*(1-a); c2=pl*(1-a)+p2*a; 7.变异函数 function [parent]=nonUnifMutate(parent,bounds,Ops) cg=Ops(1); mg=Ops(3); b=Ops(4); df=bounds(:,2)-bounds(:,1); numVar=size(parent,2)-1; mPoint=round(rand*(num Var-1))+1; and=round(rand); if md newValue=parent(mPoint)+delta(cg,mg,bounds(mPoint,2)-parent(mPoint),b); else newValue=parent(mPoint)-delta(cg,mg,parent(mPoint)-bounds(mPoint,1),b); end parent(mPoint)=newValue;%Make the child 8.主运行函数GA 的MATLAB 代码 function [x,endPop,bPop,traceInfo]=ga(bounds,evalFN,evalOps,startPop,opts,... termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps) n=nargm; if n<2|n==6|n==10|n==12 disp('lnsufficient arguements') end if n<3 evalOps=[]; end if n<5 opts=[1e-6 1 0]; end if isempty(opts) opts=[1e-6 1 0]; end if any(evalFN<48) if opts(2)==1 e1str=['x=c1; c1(xZomeLength)=', evalFN';']; e2str=['x=c2; c2(xZomeLength)=', evalFN';']; else elstr=['x=b2f(endPop(j,:),bounds,bits); endPop(j,xZomeLength)=',... eval FN ';']; end else

附录2求解RDC的 MATLAB 编程源代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/615407.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)