Cellular automata (CA) is a method used to simulate local rules and local connections. Typical of the yuan
Cellular automata are defined on a grid, where each point represents a cell with a finite form
State. The change rule applies to each cell and simultaneously.
We can understand three things about cellular automata simulation. One is cellular, which can be understood as a square block composed of one or more points in the matrix in MATLAB. Generally, we use a point in the matrix to represent a cellular. The second is the change rule. The change rule of cellular determines the state of cellular at the next moment. The third is the state of the cell. The state of the cell is self-defined and usually opposite, such as the living state or death state of the creature, the red light or the green light, the point with or without obstacles, and so on.
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);
Copy the code
Complete code or simulation consulting to add QQ1575304183