• 大小: 13KB
    文件类型: .m
    金币: 2
    下载: 0 次
    发布日期: 2024-02-06
  • 语言: Matlab
  • 标签: 车流仿真  

资源简介

基于OV模型的典型交通流跟驰模型MATLAB程序,可通过调节灵敏度、车头间距等参数改变仿真条件,可为学习最有速度模型的初学者提供一定的帮助

资源截图

代码片段和文件信息

clear;
clc;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%选择驾驶员反应时间有延误还是无延误的模型modelType=0表示无延误,
 %% modelType=1表示有延误delay
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%modelType=0;%0%初始认为是无延误
modelType=0;
draw3d=0;%绘制三维曲线0---不绘制;1-绘制
draw2d=1;%绘制2d曲线
drawother=1;%绘制其它辅助曲线
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%变量初始化区
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CAR=100;% total car number总仿真车辆数
ALLSTEP=10000;%total simulation steps总仿真步数
PI=3.1415926;%圆周率值
roadlength=800;% the length of the simulation road
Vmax=2;%freeway car velocity
Hc=1.5;  %the safe distance between following cars
%driverPara=0.5;% driver sensitivity factor
driverPara=zeros(1CAR);%驾驶员刺激反应系数
simTime=0.1;% simulation time step
del=0.1;%反应延迟时间
%delStep=0.1*10;%延迟步数
x=1:1:ALLSTEP;% xaxis scale
xx=1:1:1500;%实际采样步数
mCar=length(xx);
initDis=roadlength/CAR; %the average distance between cars
%some matrixes used in the simulation
Headway=initDis*ones(CARALLSTEP);%headway between cars
OV=zeros(CARALLSTEP);%the optimal velocity of i car
Velocity=zeros(CARALLSTEP);%the current speed for every car
Pos=zeros(CARALLSTEP);%the position of every car
Acc=zeros(CARALLSTEP);%the acceleration of every car

%Acc(:1)
%Initialation of the simulation
w=rand()%some small disturbance
%驾驶员反应系数的不同分布情况下的交通流特性研究
%每辆车对应一个司机。每个司机对应一个反应刺激系
%固定值
driverPara(1:CAR)=1;
%正态分布
% driverPara=0.5+sqrt(0.01)*randn(1CAR); 
 %均值为0.5差为1/12
%均匀分布
 %driverPara=unifrnd(0.20.81CAR); %rand(1CAR);%不应[01]会出现极值现象,与实际不符
 %泊松分布
% driverPara=poissrnd(.51CAR) %泊松分布的数学期望为lamda
%指数分布
 %driverPara= exprnd(21CAR); %指数分布的数学期望为1/lamda
 %二项分布
% driverPara=binornd(30.21CAR)/10 %数学期望为np;方差为np(1-p)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %%核心算法代码区 modelType=1 有延误,modelType=0无延误
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:1:CAR-1
    if i==CAR/2
        Pos(CAR/21)=Pos(CAR/2-11)+initDis+0.5;
        Velocity(i1)=0;
        Acc(i1)=1;
    elseif i==CAR/2+1
        Pos(CAR/2+11)=Pos(CAR/21)+initDis-0.5;   
        Velocity(i1)=0;
        Acc(i1)=1;
    else
        Pos(i1)=initDis*i;
        Velocity(i1)=0;
        Acc(i1)=1;
    end 
end
 Velocity(CAR1)=3;%头车速度值
 Acc(CAR1)=1;
 Pos(CAR1)=initDis*CAR;
    %%%end for initialization of each car position 
 if modelType==1 %如果是有延迟delay的交通流模型
     for n=1:1:ALLSTEP-1
        for m=CAR:-1:1
            if m==CAR  %第一辆车单独考虑,作为头车与第一车相连
                if n==1
                     Headway(CAR1)=roadlength+Pos(1n)-Pos(CARn);%+Velocity(11)*del-Velocity(CAR1)*del;%+rand();%
                else
                     Headway(CARn)=roadlength+Pos(1n)-Pos(CARn);%+Velocity(1n-1)*del-Velocity(CARn-1)*del;%+rand();%加有随机扰动项
                end
            else%如果不是头车
                 

评论

共有 条评论

相关资源