資源簡介
基于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%如果不是頭車
?????????????????
- 上一篇:matlab空間桁架計算程序
- 下一篇:基于粒子群算法的非合作博弈的matlab程序
評論
共有 條評論