数学建模基于元胞自动机的四车道交通流

Posted MatlabQQ1575304183

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数学建模基于元胞自动机的四车道交通流相关的知识,希望对你有一定的参考价值。

元胞自动机(CA)是一种用来仿真局部规则和局部联系的方法。典型的元

胞自动机是定义在网格上的,每一个点上的网格代表一个元胞与一种有限的状

态。变化规则适用于每一个元胞并且同时进行。

我们可以理解元胞自动机仿真需要理解三点。一是元胞,在matlab中可以理解为矩阵中的一点或多点组成的方形块,一般我们用矩阵中的一点代表一个元胞。二是变化规则,元胞的变化规则决定元胞下一刻的状态。三是元胞的状态,元胞的状态是自定义的,通常是对立的状态,比如生物的存活状态或死亡状态,红灯或绿灯,该点有障碍物或者没有障碍物等等。

clc;
clear;
close all;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%定义车辆占有??
%人工驾驶公交车(bus)???自动驾驶公交车(zdbus)???人工驾驶小汽车(car)???
%自动驾驶小汽车(zdcar)的生成概率p
syms q
q=0.3; %车辆占有??
q_storage=zeros(1,3);
data1 = [];
data2 = [];
data3 = [];
data4 = [];
data5 = [];
data6 = [];
data7 = [];
data8 = [];
data9 = [];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%主循??
while q<=1
    q=q+0.0025;
    if q>0.4025
        q=q+0.0025;
    end
    
    q_storage(1,1)=q;%之后可以设置各车道车辆占有率
    q_storage(1,2)=q;
    q_storage(1,3)=q;
    q_storage(1,4)=q;
%     q_storage(1,:)=0.6;
%     [lane_change_pos_bus,lane_change_pos_bus_qz1,lane_change_pos_zdbus,lane_change_pos_zdbus_qz1,lane_change_count_zdbus,lane_change_count_bus,lane_change_count_bus_qz1,lane_change_count_zdbus_qz1,all_temp_v,all_temp_cars,cars_in,cars_out] = revisePart2_function(q_storage);
%     [lane_change_pos_bus,lane_change_pos_bus_qz1,lane_change_pos_zdbus,lane_change_pos_zdbus_qz1,all_temp_v,all_temp_cars,cars_in,cars_out]=revisePart2_function2(q_storage);
   [lane_change_pos_zdbus_qz3,lane_change_pos_bus_qz3,lane_change_pos_bus4,lane_change_pos_zdbus4,lane_change_count_bus4,lane_change_count_zdbus4,lane_change_count_bus3,lane_change_count_zdbus3,lane_change_count_bus_qz3,lane_change_count_zdbus_qz3,lane_change_count_bus_qz2,lane_change_count_zdbus_qz2,lane_change_count_bus_qz1,lane_change_count_zdbus_qz1,lane_change_count_bus1,lane_change_count_zdbus1,lane_change_count_bus2,lane_change_count_zdbus2,lane_change_count_car,lane_change_count_zdcar,lane_change_pos_bus1,lane_change_pos_bus2,lane_change_pos_bus3,lane_change_pos_bus_qz1,lane_change_pos_bus_qz2,lane_change_pos_zdbus1,lane_change_pos_zdbus2,lane_change_pos_zdbus3,lane_change_pos_zdbus_qz1,lane_change_pos_zdbus_qz2,temp_v,temp_cars,cars_in,cars_out]=revisePart2_function_4(q_storage);
    %%计算相关数据
%     a1=cars_in;%每次循环对应的车流量
      b1 =(lane_change_count_bus1+lane_change_count_bus2+lane_change_count_bus3)/(lane_change_count_zdbus1+lane_change_count_zdbus2+lane_change_count_zdbus3+lane_change_count_bus1+lane_change_count_bus2+lane_change_count_bus3+lane_change_count_bus_qz1+lane_change_count_zdbus_qz1+lane_change_count_bus_qz2+lane_change_count_zdbus_qz2+lane_change_count_bus_qz3+lane_change_count_zdbus_qz3);%人工公交车自由换道率
      b2 =(lane_change_count_zdbus1+lane_change_count_zdbus2+lane_change_count_zdbus3)/(lane_change_count_zdbus1+lane_change_count_zdbus2+lane_change_count_zdbus3+lane_change_count_bus1+lane_change_count_bus2+lane_change_count_bus3+lane_change_count_bus_qz1+lane_change_count_zdbus_qz1+lane_change_count_bus_qz2+lane_change_count_zdbus_qz2+lane_change_count_bus_qz3+lane_change_count_zdbus_qz3);%自动公交车自由换道率
      b3 =b1+b2;%公交车自由换道率
%     b4=sum(cell2mat(lane_change_pos_bus))/lane_change_count_bus;%人工公交换道比例=人工自由换道/总换道次??
%     b5=sum(cell2mat(lane_change_pos_zdbus))/lane_change_count_zdbus;%网联公交换道比例=网联自由换道/总换道次??
%     b6=(sum(cell2mat(lane_change_pos_bus))+sum(cell2mat(lane_change_pos_zdbus)))/(lane_change_count_zdbus+lane_change_count_zdbus);%总公交换道比??=总自由换道次??/总次??
      b7=(sum(cell2mat(lane_change_pos_bus1))+sum(cell2mat(lane_change_pos_bus2))+sum(cell2mat(lane_change_pos_bus3))+sum(cell2mat(lane_change_pos_bus_qz1))+sum(cell2mat(lane_change_pos_bus_qz2))+sum(cell2mat(lane_change_pos_bus_qz3)))/(lane_change_count_bus1+lane_change_count_bus2+lane_change_count_bus3+lane_change_count_bus_qz1+lane_change_count_bus_qz2+lane_change_count_bus_qz3);%人工公交自由换道平均位置
      b8=(sum(cell2mat(lane_change_pos_zdbus1))+sum(cell2mat(lane_change_pos_zdbus2))+sum(cell2mat(lane_change_pos_zdbus_qz1))+sum(cell2mat(lane_change_pos_zdbus_qz2)))/(lane_change_count_zdbus1+lane_change_count_zdbus2+lane_change_count_zdbus_qz1+lane_change_count_zdbus_qz2);%网联公交自由换道平均位置
      b9=(sum(cell2mat(lane_change_pos_bus1))+sum(cell2mat(lane_change_pos_bus2))+sum(cell2mat(lane_change_pos_bus3))+sum(cell2mat(lane_change_pos_bus_qz1))+sum(cell2mat(lane_change_pos_bus_qz2))+sum(cell2mat(lane_change_pos_bus_qz3))+sum(cell2mat(lane_change_pos_zdbus1))+sum(cell2mat(lane_change_pos_zdbus2))+sum(cell2mat(lane_change_pos_zdbus3))+sum(cell2mat(lane_change_pos_zdbus_qz1))+sum(cell2mat(lane_change_pos_zdbus_qz2))+sum(cell2mat(lane_change_pos_zdbus_qz3)))/(lane_change_count_bus1+lane_change_count_bus2+lane_change_count_bus3+lane_change_count_bus_qz1+lane_change_count_bus_qz2+lane_change_count_bus_qz3+lane_change_count_zdbus1+lane_change_count_zdbus2+lane_change_count_zdbus3+lane_change_count_zdbus_qz1+lane_change_count_zdbus_qz2+lane_change_count_zdbus_qz3); 
%     b10=((sum(sum(all_temp_v)'))*2.5*3.6)/sum((sum(all_temp_cars==2)'/2)+(sum(all_temp_cars==4)'/4));%平均速度
%       b11=((sum((sum(all_temp_cars==2)'/2)+(sum(all_temp_cars==4)'/4)))*1000)/(260*3600*2.5);%车流密度
%       b12=((sum((sum(all_temp_cars==2)'/2)+(sum(all_temp_cars==4)')/2)))*1000/(260*3600*2.5);%车流密度折算
%     b13=cars_in;%流量   
      b14=cars_out;
      b15=lane_change_count_bus1;
      b16=lane_change_count_bus2;
      b17=lane_change_count_bus3;
      b18=lane_change_count_bus4;
      b19=lane_change_count_bus_qz1;
      b20=lane_change_count_bus_qz2;
      b21=lane_change_count_bus_qz3;
      b22=lane_change_count_zdbus1;
      b23=lane_change_count_zdbus2;
      b24=lane_change_count_zdbus3;
      b25=lane_change_count_zdbus4;
      b26=lane_change_count_zdbus_qz1;
      b27=lane_change_count_zdbus_qz2;
      b28=lane_change_count_zdbus_qz3;
      b29=lane_change_count_car;
      b30=lane_change_count_zdcar;

data1 = [data1; [b1,b2,b3,b7,b8,b9,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30]];
data2 = [data2;[lane_change_pos_bus1';'#']];
data3 = [data3;[lane_change_pos_zdbus1';'#']];
data4 = [data4;[lane_change_pos_bus2';'#']];
data5 = [data5;[lane_change_pos_zdbus2';'#']];
data6 = [data6;[lane_change_pos_bus3';'#']];
data7 = [data7;[lane_change_pos_zdbus3';'#']];
data8 = [data8;[lane_change_pos_bus4';'#']];
data9 = [data9;[lane_change_pos_zdbus4';'#']];
end

% xlswrite('s51.xlsx',data1,1);
% xlswrite('s51.xlsx',data2,2);
% xlswrite('s51.xlsx',data3,3);
% xlswrite('s51.xlsx',data4,4);
% xlswrite('s51.xlsx',data5,5);
% xlswrite('s51.xlsx',data6,6);
% xlswrite('s51.xlsx',data7,7);
% xlswrite('s51.xlsx',data8,8);
% xlswrite('s51.xlsx',data9,9);

完整代码或者仿真咨询添加QQ1575304183

以上是关于数学建模基于元胞自动机的四车道交通流的主要内容,如果未能解决你的问题,请参考以下文章

元胞自动机基于元胞自动机模拟双车道交通流模型含靠右行驶matlab源码

元胞自动机基于matlab元胞自动机单车道交通流(时空图)含Matlab源码 1681期

元胞自动机基于matlab激进策略元胞自动机三车道(开放辅路,软件园影响)交通流模型含Matlab源码 1298期

元胞自动机基于matlab保守策略元胞自动机三车道(开放辅路,软件园影响)交通流模型含Matlab源码 1295期

元胞自动机基于matlab激进策略元胞自动机三车道(不开放辅路,软件园影响)交通流模型含Matlab源码 1297期

元胞自动机基于matlab保守策略元胞自动机三车道(不开放辅路,软件园影响)交通流模型含Matlab源码 1294期