MSWA交通流量分配基于相继加权平均算法(MSWA)交通流量分配算法的仿真

Posted fpga&matlab

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MSWA交通流量分配基于相继加权平均算法(MSWA)交通流量分配算法的仿真相关的知识,希望对你有一定的参考价值。

1.软件版本

matlab2021a

2.本算法理论知识

如图所示交通网络中,包含6个节点、11各路段、9个OD对。经枚举可得每个OD对间存在3条无折返有效路径,共27条。

各个OD对间的出行需求量如表所示:

O1

O2

O3

D1

80

50

20

D2

45

170

40

D3

30

20

25

每个路段的走行时间按照下式计算:

 其中,为路段a的流量

 

 利用相继加权平均算法(MSWA)求解配流结果,算法步骤如下:

 3.核心代码

clc
clear;
close all;
warning off;


%各个OD对间的出行需求量
qOD   = [80,50,20;
         45,170,40;
         30,20,25;];
[Rdo,Cdo] = size(qOD);

ta0   = [60 ,40,60 ,20 ,20 ,20 ,20 ,20 ,20 ,20 ,20];     
ca    = [100,40,160,300,300,300,300,300,300,300,300];     
Num   = length(ta0);%路段数量     

%迭代次数
Iter = 5000;
d    = 0.5;
es   = 0.1;

r     = zeros(1,Iter);
alpha = ones(1,Iter);
ya    = ones(Num,Iter);
xa    = zeros(Num,Iter);

for m = 1:Iter
    %计算各OD对间各条有效路径的总走行时间
    if m == 1
        for i = 1:Num
            ta(i) = ta0(i)*(1 + 0.15*(0/ca(i))^4);
        end
    else
        for i = 1:Num
            ta(i) = ta0(i)*(1 + 0.15*(xa(i,m-1)/ca(i))^4);
        end  
    end
    %计算各OD对间各条有效路径的总走行时间,这个需要根据图上的连接路径自己计算
    %OD对间存在3条无折返有效路径
    TkOD(1,1,1)=ta(1);
    TkOD(1,1,2)=sum(ta([4,5,3,10,11]));
    TkOD(1,1,3)=sum(ta([4,2,11]));
    
    TkOD(1,2,1)=sum(ta([4,2]));
    TkOD(1,2,2)=sum(ta([1,8]));
    TkOD(1,2,3)=sum(ta([4,5,3,10]));
    
    TkOD(1,3,1)=sum(ta([4,5,3]));
    TkOD(1,3,2)=sum(ta([4,2,9]));
    TkOD(1,3,3)=sum(ta([1,8,9]));
    
    
    TkOD(2,1,1)=sum(ta([7,1]));
    TkOD(2,1,2)=sum(ta([2,11]));
    TkOD(2,1,3)=sum(ta([5,3,10,11]));
    
    TkOD(2,2,1)=sum(ta([2]));
    TkOD(2,2,2)=sum(ta([5,3,10]));
    TkOD(2,2,3)=sum(ta([7,1,8]));
    
    TkOD(2,3,1)=sum(ta([5,3]));
    TkOD(2,3,2)=sum(ta([2,9]));
    TkOD(2,3,3)=sum(ta([7,1,8,9]));    
    
    
    TkOD(3,1,1)=sum(ta([3,10,11]));
    TkOD(3,1,2)=sum(ta([6,2,11]));
    TkOD(3,1,3)=sum(ta([6,7,1]));
    
    TkOD(3,2,1)=sum(ta([6,2]));
    TkOD(3,2,2)=sum(ta([3,10]));
    TkOD(3,2,3)=sum(ta([6,7,1,8]));
    
    TkOD(3,3,1)=sum(ta([3]));
    TkOD(3,3,2)=sum(ta([6,2,9]));
    TkOD(3,3,3)=sum(ta([6,7,1,8,9]));       
 
    %网络加载
    TkOD = TkOD/100;%加这个语句,使得expTkod的值稍微大点,这样曲线效果明显点,否则太小了,看上去不明显
    for k = 1:3
        tmps(k) = sum(sum(exp(-1*TkOD(:,:,k))));
    end
    for i = 1:Rdo
        for j = 1:Cdo
            for k = 1:3
                PkOD(i,j,k) = tmps(k)/sum(tmps)*qOD(i,j);
            end
        end
    end
    %计算yam
    ya(1,m) = ta(1) *(PkOD(1,1,1)/ta(1) + PkOD(1,2,2)/sum(ta([1,8])) + PkOD(1,3,3)/sum(ta([1,8,9])) + PkOD(2,3,3)/sum(ta([7,1,8,9])) + PkOD(2,3,3)/sum(ta([7,1,8,9])) + PkOD(3,2,3)/sum(ta([6,7,1,8])) + PkOD(3,3,3)/sum(ta([6,7,1,8,9])));
    ya(2,m) = ta(2) *(PkOD(1,1,3)/sum(ta([4,2,11])) +PkOD(1,2,1)/sum(ta([4,2])) + PkOD(1,3,2)/sum(ta([4,2,9]))+ PkOD(2,1,2)/sum(ta([2,11]))+ PkOD(2,2,1)/sum(ta([2]))+PkOD(2,3,2)/sum(ta([2,9])) + PkOD(3,1,2)/sum(ta([6,2,11]))+ PkOD(3,2,1)/sum(ta([6,2]))+ PkOD(3,3,2)/sum(ta([6,2,9])));
    ya(3,m) = ta(3) *(PkOD(1,1,2)/sum(ta([4,5,3,10,11]))+PkOD(1,2,3)/sum(ta([4,5,3,10]))+PkOD(1,3,1)/sum(ta([4,5,3]))+PkOD(2,1,3)/sum(ta([5,3,10,11]))+PkOD(2,2,2)/sum(ta([5,3,10]))+PkOD(2,3,1)/sum(ta([5,3]))+PkOD(3,1,1)/sum(ta([3,10,11]))+PkOD(3,2,2)/sum(ta([3,10]))+PkOD(3,3,1)/sum(ta([3])));
    ya(4,m) = ta(4) *(PkOD(1,1,2)/sum(ta([4,5,3,10,11]))+PkOD(1,1,3)/sum(ta([4,2,11]))+PkOD(1,2,1)/sum(ta([4,2]))+PkOD(1,2,3)/sum(ta([4,5,3,10]))+PkOD(1,3,1)/sum(ta([4,5,3]))+PkOD(1,3,2)/sum(ta([4,2,9])));
    ya(5,m) = ta(5) *(PkOD(1,1,2)/sum(ta([4,5,3,10,11]))+PkOD(1,2,3)/sum(ta([4,5,3,10]))+PkOD(1,3,1)/sum(ta([4,5,3]))+PkOD(2,1,3)/sum(ta([5,3,10,11]))+PkOD(2,2,2)/sum(ta([5,3,10]))+PkOD(2,3,1)/sum(ta([5,3])));
    ya(6,m) = ta(6) *(PkOD(3,1,2)/sum(ta([6,2,11]))+PkOD(3,1,3)/sum(ta([6,7,1]))+PkOD(3,2,1)/sum(ta([6,2]))+PkOD(3,2,3)/sum(ta([6,7,1,8]))+PkOD(3,3,2)/sum(ta([6,2,9]))+PkOD(3,3,3)/sum(ta([6,7,1,8,9])));
    ya(7,m) = ta(7) *(PkOD(2,1,1)/sum(ta([7,1]))+PkOD(2,2,3)/sum(ta([7,1,8]))+PkOD(2,3,3)/sum(ta([7,1,8,9]))+PkOD(3,1,3)/sum(ta([6,7,1]))+PkOD(3,2,3)/sum(ta([6,7,1,8]))+PkOD(3,3,3)/sum(ta([6,7,1,8,9])));
    ya(8,m) = ta(8) *(PkOD(1,2,2)/sum(ta([1,8]))+PkOD(1,3,3)/sum(ta([1,8,9]))+PkOD(2,2,3)/sum(ta([7,1,8]))+PkOD(2,3,3)/sum(ta([7,1,8,9]))+PkOD(3,2,3)/sum(ta([6,7,1,8]))+PkOD(3,3,3)/sum(ta([6,7,1,8,9])));
    ya(9,m) = ta(9) *(PkOD(1,3,2)/sum(ta([4,2,9]))+PkOD(1,3,3)/sum(ta([1,8,9]))+PkOD(2,3,2)/sum(ta([2,9]))+PkOD(2,3,3)/sum(ta([7,1,8,9]))+PkOD(3,3,2)/sum(ta([6,2,9]))+PkOD(3,3,3)/sum(ta([6,7,1,8,9])));
    ya(10,m)= ta(10)*(PkOD(1,1,2)/sum(ta([4,5,3,10,11]))+PkOD(1,2,3)/sum(ta([4,5,3,10]))+PkOD(2,1,3)/sum(ta([5,3,10,11]))+PkOD(2,2,2)/sum(ta([5,3,10]))+PkOD(3,1,1)/sum(ta([3,10,11]))+PkOD(3,2,2)/sum(ta([3,10])));  
    ya(11,m)= ta(11)*(PkOD(1,1,2)/sum(ta([4,5,3,10,11]))+PkOD(1,1,3)/sum(ta([4,2,11]))+PkOD(2,1,2)/sum(ta([2,11]))+PkOD(2,1,3)/sum(ta([5,3,10,11]))+PkOD(3,1,1)/sum(ta([3,10,11]))+PkOD(3,1,2)/sum(ta([6,2,11])));   
    
    if m == 1
       r(m)     = m^d;  
    else
       r(m)     = r(m-1) + m^d; 
       alpha(m) = m^d/r(m);
       xa(:,m)    = (1-alpha(m))*xa(:,m-1) + alpha(m)*ya(:,m);
    end
    
    if mean(abs(xa(:,m)-ya(:,m))) <= es & m > 1
       m%输出迭代次数
       break;
    end
    
    %27个路径迭代曲线图
    indx=0;
    for i = 1:Rdo
        for j = 1:Cdo
            for k = 1:3
                indx=indx+1;
                dss(indx,m) = PkOD(i,j,k);
            end
        end
    end
    
end     
       
 
figure;
plot(dss(1,:),'r','linewidth',2);hold on;
plot(dss(2,:),'k','linewidth',2);hold on;
plot(dss(3,:),'b','linewidth',2);hold on;
plot(dss(4,:),'m','linewidth',2);hold on;
plot(dss(5,:),'g','linewidth',2);hold on;
plot(dss(6,:),'c','linewidth',2);hold on;
legend('路径1','路径2','路径3','路径4','路径5','路径6');
xlabel('迭代次数');
ylabel('收敛值');
grid on
 
    
figure;
plot(dss(7,:),'r','linewidth',2);hold on;
plot(dss(8,:),'k','linewidth',2);hold on;
plot(dss(9,:),'b','linewidth',2);hold on;
plot(dss(10,:),'m','linewidth',2);hold on;
plot(dss(11,:),'g','linewidth',2);hold on;
plot(dss(12,:),'c','linewidth',2);hold on;
legend('路径7','路径8','路径9','路径10','路径11','路径12');
xlabel('迭代次数');
ylabel('收敛值');
grid on


figure;
plot(dss(13,:),'r','linewidth',2);hold on;
plot(dss(14,:),'k','linewidth',2);hold on;
plot(dss(15,:),'b','linewidth',2);hold on;
plot(dss(16,:),'m','linewidth',2);hold on;
plot(dss(17,:),'g','linewidth',2);hold on;
plot(dss(18,:),'c','linewidth',2);hold on;
legend('路径13','路径14','路径15','路径16','路径17','路径18');
xlabel('迭代次数');
ylabel('收敛值');
grid on


figure;
plot(dss(19,:),'r','linewidth',2);hold on;
plot(dss(20,:),'k','linewidth',2);hold on;
plot(dss(21,:),'b','linewidth',2);hold on;
plot(dss(22,:),'m','linewidth',2);hold on;
plot(dss(23,:),'g','linewidth',2);hold on;
plot(dss(24,:),'c','linewidth',2);hold on;
legend('路径19','路径20','路径21','路径22','路径23','路径24');
xlabel('迭代次数');
ylabel('收敛值');
grid on

figure;
plot(dss(25,:),'r','linewidth',2);hold on;
plot(dss(26,:),'k','linewidth',2);hold on;
plot(dss(27,:),'b','linewidth',2);hold on;
legend('路径25','路径26','路径27');
xlabel('迭代次数');
ylabel('收敛值');
grid on


     

4.操作步骤与仿真结论

 

 5.参考文献

A06-50

以上是关于MSWA交通流量分配基于相继加权平均算法(MSWA)交通流量分配算法的仿真的主要内容,如果未能解决你的问题,请参考以下文章

基于MATLAB的神经网络BP算法改进LM算法的交通流量的源代码!

路径诱导系统

非正常情况下的移动加权平均算法

负载均衡算法

优化算法之指数加权平均详解

双边滤波算法原理及实现