交通分配之随机配流算法matlab源码(含最短路径算法)_第1页
交通分配之随机配流算法matlab源码(含最短路径算法)_第2页
交通分配之随机配流算法matlab源码(含最短路径算法)_第3页
交通分配之随机配流算法matlab源码(含最短路径算法)_第4页
交通分配之随机配流算法matlab源码(含最短路径算法)_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

交通分配之随机配流算法matlab源码(含最短路径算法)本文档含两个m文件dial.m和dijkstra1.m,dial需要调用dijkstra1。算例如下:算法如下:edge=[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&&weight(i,j)<inf&&r(i)<r(j)&&s(i)>s(j)L(i,j)=exp(theta*(r(j)-r(i)-weight(i,j)));%所有路段似然值endendendLMax=2000;temp=0;tempr=zeros(1,n);rr=zeros(1,n);rr=r;%出发节点i排序fori=1:nMin=2000;forj=1:nifrr(j)<min<p="">Min=rr(j);temp=j;endendrr(temp)=Max;tempr(i)=temp;LW=zeros(n);%前向计算路段权重fori=1:nforj=1:nifi==startLW(tempr(i),j)=L(tempr(i),j);elsesumlw=0;fortempi=1:9sumlw=sumlw+LW(tempi,tempr(i));endLW(tempr(i),j)=L(tempr(i),j)*sumlw;endendendtemprLWMax=2000;temp=0;temps=zeros(1,n);ss=s;%到达节点j排序fori=1:nMin=2000;forj=1:nifss(j)<min<p="">Min=ss(j);temp=j;endendss(temp)=Max;temps(i)=temp;endtemps%反向装载流量forj=1:ntempOD=0;fortempi=1:9ifOD(temps(j),tempi)>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~=s&&t>0p=parent(t);path=[ppath(1:count)];t=p;count=count+1;endifcount>=2*nerror(['Thepat

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论