matlab实现配流算法,交通分配之随机配流算法matlab源码(含最短路径算法).doc

41528d3028836879cd698677c3999917.gif交通分配之随机配流算法matlab源码(含最短路径算法).doc

本文档含两个m文件dial.m和dijkstra1.m,dial需要调用dijkstra1。算例如下:算法如下:Dial.medge=[112234455678;.243565768989;.222221212222;];n=9;weight=inf*ones(n,n);Q=1000;start=1;endn=9;r=zeros(1,n);s=zeros(1,n);theta=1;L=zeros(n);OD=zeros(n);%====================================================================fori=1:nweight(i,i)=0;endfori=1:size(edge,2)weight(edge(1,i),edge(2,i))=edge(3,i);endLmin=zeros(1,n);fori=1:n[dis,path]=dijkstra1(weight,i,9);s(i)=dis;%任意节点到终点s的最小时间[dis,path]=dijkstra1(weight,1,i);r(i)=dis;%起点r到任意节点最小时间endfori=1:nforj=1:nifweight(i,j)>0%所有路段似然值endendendLMax=2000;temp=0;tempr=zeros(1,n);rr=zeros(1,n);rr=r;%出发节点i排序fori=1:nMin=2000;forj=1:nifrr(j)0||OD(temps(j),tempi)==0tempOD=tempOD+OD(temps(j),tempi);endendfori=1:nsumlw=0;iftemps(j)==endnfortempi=1:9sumlw=sumlw+LW(tempi,temps(j));endOD(i,temps(j))=Q*LW(i,temps(j))/sumlw;elsefortempi=1:9sumlw=sumlw+LW(tempi,temps(j));endOD(i,temps(j))=LW(i,temps(j))*tempOD/sumlw;endendendODfunction[distance,path]=dijkstra1(A,s,e)%[DISTANCE,PATH]=DIJKSTRA(A,S,E)%returnsthedistanceandpathbetweenthestartnodeandtheendnode.%%A:adjcentmatrix%s:startnode%e:endnode%initializen=size(A,1);%nodenumberD=A(s,:);%distancevectorpath=[];%pathvectorvisit=ones(1,n);%nodevisibilityvisit(s)=0;%sourcenodeisunvisibleparent=zeros(1,n);%parentnode%theshortestdistancefori=1:n-1%BlueSethasn-1nodestemp=zeros(1,n);count=0;forj=1:nifvisit(j)temp=[temp(1:count)D(j)];elsetemp=[temp(1:count)inf];endcount=count+1;end[value,index]=min(temp);j=index;visit(j)=0;fork=1:nifD(k)>D(j)+A(j,k)D(k)=D(j)+A(j,k);parent(k)=j;endendenddistance=D(e);%theshortestdistancepathifparent(e)==0return;endpath=zeros(1,2*n);%pathpreallocationt=e;path(1)=t;count=1;whilet~=spath=[ppath(1:count)];t=p;count=count+1;endifcount>=2*nerror([ Thepathpreallocationlengthistooshort. ,. Pleaseredefinepathpreallocationparameter. ]);endpath(1)=s;path=path(1:count);

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值