資源簡(jiǎn)介
基于OV模型的典型交通流跟馳模型MATLAB程序,可通過(guò)調(diào)節(jié)靈敏度、車頭間距等參數(shù)改變仿真條件,可為學(xué)習(xí)最有速度模型的初學(xué)者提供一定的幫助
代碼片段和文件信息
clear;
clc;
?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?%%選擇駕駛員反應(yīng)時(shí)間有延誤還是無(wú)延誤的模型modelType=0表示無(wú)延誤,
?%%?modelType=1表示有延誤delay
?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%modelType=0;%0%初始認(rèn)為是無(wú)延誤
modelType=0;
draw3d=0;%繪制三維曲線0---不繪制;1-繪制
draw2d=1;%繪制2d曲線
drawother=1;%繪制其它輔助曲線
?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?%%變量初始化區(qū)
?%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CAR=100;%?total?car?number總仿真車輛數(shù)
ALLSTEP=10000;%total?simulation?steps總仿真步數(shù)
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);%駕駛員刺激反應(yīng)系數(shù)
simTime=0.1;%?simulation?time?step
del=0.1;%反應(yīng)延遲時(shí)間
%delStep=0.1*10;%延遲步數(shù)
x=1:1:ALLSTEP;%?xaxis?scale
xx=1:1:1500;%實(shí)際采樣步數(shù)
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
%駕駛員反應(yīng)系數(shù)的不同分布情況下的交通流特性研究
%每輛車對(duì)應(yīng)一個(gè)司機(jī)。每個(gè)司機(jī)對(duì)應(yīng)一個(gè)反應(yīng)刺激系
%固定值
driverPara(1:CAR)=1;
%正態(tài)分布
%?driverPara=0.5+sqrt(0.01)*randn(1CAR);?
?%均值為0.5差為1/12
%均勻分布
?%driverPara=unifrnd(0.20.81CAR);?%rand(1CAR);%不應(yīng)[01]會(huì)出現(xiàn)極值現(xiàn)象,與實(shí)際不符
?%泊松分布
%?driverPara=poissrnd(.51CAR)?%泊松分布的數(shù)學(xué)期望為lamda
%指數(shù)分布
?%driverPara=?exprnd(21CAR);?%指數(shù)分布的數(shù)學(xué)期望為1/lamda
?%二項(xiàng)分布
%?driverPara=binornd(30.21CAR)/10?%數(shù)學(xué)期望為np;方差為np(1-p)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?%%核心算法代碼區(qū)?modelType=1?有延誤,modelType=0無(wú)延誤
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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??%第一輛車單獨(dú)考慮,作為頭車與第一車相連
????????????????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();%加有隨機(jī)擾動(dòng)項(xiàng)
????????????????end
????????????else%如果不是頭車
?????????????????
評(píng)論
共有 條評(píng)論