1 简介
近年来,伴随着我国社会经济的快速发展和人们生活水平的普遍提高,整个社会对交通运输的需求日益增加,带来了交通运输业的空前繁忙和各种车辆的迅猛增加,这也使得我国复杂的交通流组成和相对落后的交通流管制措施之间的矛盾越发突出,进而导致我国部分城市道路出现了严重的交通拥挤和堵塞.在道路交通流运行的过程中,交通路口往往扮演者一个瓶颈的角色,因此对城市道路交通路口交通流的研究和仿真的研究,具有十分重要的现实意义. 元胞自动机(cellular automaton或cellular automata,简称CA)是一种在时间,空间和状态均离散的一种模型,具有算法简单,灵活和计算效率高等优点,因此元胞自动机成为道路交通流研究的一个重要工具.本文基于元胞自动机和交通流理论知识,研究,分析了影响机动车流运行的一些主要因素,并结合十字路口处的行人流,创建了一个斑马线和行人运行的组合元胞自动机模型,并基于此模型实现了一个模拟斑马线运行的仿真系统.
2 部分代码
clear all; close all; pes_rate = 0.25;%%行人流量(每秒钟) car_rate = 0.2;%%车辆流量(每秒钟) car_avg_speed = 12; w =21;%%马路宽度 l = 9;%%人行道宽度 road_len = 150; pes_avg_speed = 1.2/0.6;%%行人的平均速度,按照元胞计算 pes_max_speed = 1.8/0.6;%%行人的最大速度,按照元胞计算 p_move = 0.7; %无优势通道时移动概率%★★★ r_adv = [4,2]; %决策空间范围,宽为3行,矩阵两个元素分别为距其前后列数%★★★ cat_avg_speed = 10/0.6;%★★★这是啥? int_pes_num = ceil(w/pes_avg_speed*pes_rate);%%初始化行人个数 int_car_num = ceil(road_len/cat_avg_speed*car_rate);%%初始化汽车个数 num_l = floor(int_pes_num/2); num_r = int_pes_num-num_l; [space,ped_l,ped_r,v_space] = initialize_pes(w,l,num_l,num_r);%%初始化行人%%ped_l 上面行人排序,从上往下走 ,ped_r下面行人,从下往上走 % % ped_r.m(1)=8;%★★★ % ped_r.n(1)=1;%★★★ % [l_id,r_id,v_l,v_r] = initialize_car(int_car_num,int_car_num,road_len,l); % l_id = []; % r_id = [80];%★★★ car_vmax = 18.5; pes_vmax = 1.8/0.6; car_insert = []; pes_insert = []; sim_time = 40;%★★★这是仿真时长? add_car_num=0; add_pes_num=0; down_car_strat_id = l_id; down_car_isfinished = zeros(size(l_id)); dowvcar_is_wait = zeros(size(l_id)); downcar_cross_time = zeros(size(l_id)); down_start_time = zeros(size(l_id)); up_car_start_id = r_id; up_car_isfinished = zeros(size(r_id)); upcar_is_wait = zeros(size(r_id)); upcar_cross_time = zeros(size(r_id)); up_start_time = zeros(size(r_id)); down_cross_finish_time = []; down_finish_time = []; down_iswait_finished = []; up_cross_finish_time = []; up_finish_time = []; up_iswait_finished = []; down_finish_avg_v = []; up_finish_avg_v = []; down_pes_cross_time = zeros(size(ped_l.m)); down_pes_wait_time = zeros(size(ped_l.m)); up_pes_cross_time = zeros(size(ped_r.m)); up_pes_wait_time = zeros(size(ped_r.m)); down_pes_corss_time_finish= []; down_pes_wait_time_finish= []; up_pes_corss_time_finish= []; up_pes_wait_time_finish= []; % % l_id = [58,18];%★★★ % %%初始化车辆 figure(1); plot_map(ped_l,ped_r,space,20,l_id,r_id,road_len,l); sim_min_num = 2;%仿真时间%★★★ end if ismember(index-(min_ind-1)*60,down_car_gen_inde)%%添加车辆进入%★★★ l_id(end+1) = -3;%★★★ v_l(end+1) = round(car_vmax*rand(1));%★★★ down_start_time(end+1) = index;%★★★ dowvcar_is_wait(end+1) = 0;%★★★ downcar_cross_time(end+1) = 0;%★★★ down_car_strat_id(end+1) = -3;%★★★ add_car_num =add_car_num+1; end if ismember(index-(min_ind-1)*60,up_car_gen_inde)%%添加车辆进入%★★★ r_id(end+1) = road_len+l+4;%★★★ up_car_start_id(end+1) = road_len+l+4;%★★★ v_r(end+1) = round(car_vmax*rand(1)); up_start_time(end+1) = index;%★★★ upcar_is_wait(end+1) = 0;%★★★ upcar_cross_time(end+1) = 0;%★★★ add_car_num =add_car_num+1; end figure(1);clf; plot_map(ped_l,ped_r,space,20,l_id,r_id,road_len,l); pause(0.6); drawnow; car_space = get_carmap(l_id,r_id,w,l,road_len); [space,ped_l,ped_r,v_space,down_pes_cross_time,down_pes_wait_time,up_pes_cross_time,up_pes_wait_time,l_delete_id,r_delete_id]=update_pes(w,l,ped_l,ped_r,space,v_space,car_space,down_pes_cross_time,down_pes_wait_time,up_pes_cross_time,up_pes_wait_time); if ~isempty(l_delete_id) down_pes_corss_time_finish = [down_pes_corss_time_finish,down_pes_cross_time(l_delete_id)];%%通过行人通道时间 down_pes_wait_time_finish = [down_pes_wait_time_finish,down_pes_wait_time(l_delete_id)];%%行驶总时间 %%将有关数据删除 down_pes_cross_time(l_delete_id) = []; down_pes_wait_time(l_delete_id) = []; ped_l.m(l_delete_id) = []; ped_l.n(l_delete_id) = []; ped_l.p(l_delete_id) = []; end if ~isempty(r_delete_id) up_pes_corss_time_finish = [up_pes_corss_time_finish,up_pes_cross_time(r_delete_id)];%%通过行人通道时 figure(1);clf; plot_map(ped_l,ped_r,space,20,l_id,r_id,road_len,l); pause(0.6); drawnow; end end end norm_mean_time = l*0.6/car_avg_speed; finish_car_num = numel(up_finish_avg_v)+numel(down_finish_avg_v); road_capacity = 1650; saturation = finish_car_num*60/1650; fprintf('车辆平均车速:%4.3f\n',mean([up_finish_avg_v,down_finish_avg_v])); fprintf('车辆在人行横道处的平均延误时间:%4.3f\n',mean([down_cross_finish_time-norm_mean_time,up_cross_finish_time-norm_mean_time])); fprintf('车辆让行率:%4.3f\n',sum([down_iswait_finished,up_iswait_finished])/numel([down_iswait_finished,up_iswait_finished])); fprintf('饱和度:%4.3f\n',saturation); fprintf('行人平均通过时间:%4.3f\n',mean([down_pes_corss_time_finish,up_pes_corss_time_finish])); fprintf('行人平均等待时间:%4.3f\n',mean([up_pes_wait_time_finish,down_pes_wait_time_finish]));
3 仿真结果
4 参考文献
[1]闫晨. (2013). 基于元胞自动机的十字交通路口交通流的研究与仿真. (Doctoral dissertation, 北京交通大学).
部分理论引用网络文献,若有侵权联系博主删除。