资源描述:
《双圆道交通流ca模型matlab程序》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、%functionfrho,flux,vmeanl=ns2(rho,p,L,tmax)%注意:主函数一定不能像子函数一样以function开头。此程序为含控制按钮NS模型改编双车道,无换道。%NS:ThisscriptimplementstheNagelSchreckenbergcellularautomatabased%trafficmodel.CarmoveforwardgovernedbyNSalgorithm:%%1.Acceleration.Ifthevehiclecanspeedupwithouthittingthespeed
2、%limitvmaxitwilladdonetoitsvelocity,vn-〉vn+1.Otherwise,%thevehiclehasconstantspeed,vn鉸?vn.%%2.Collisionprevention.Ifthedistancebetweenthevehicleandthecar%aheadofit,dn,islessthanorequaltovn,i.e.thenthvehicle%willcollideifitdoesn'tslowdown,thenvn紋?dn蓥?1.%%3.Randomslowing.Ve
3、hiclesoftenslowfornon-trafficreasons(cell%phones,coffeemugs,evenlaptops)anddriversoccasionallymake%irrationalchoices.Withsomeprobabilitypbrake,vn=?vn-1,%presumingvn>0.%%4.Vehiclemovement.Thevehiclesaredeterministicallymovedbytheir%velocities,xn->xn+vn.%%USAGE:flux=ns(rho,
4、p,L,tmax,isdraw)%rho=densityofthetraffic%p=probabilityofrandombraking%L=lengthoftheload%tmax=numberoftheiterations%animation=ifshowtheanimation(动M)ofthetraffic%spacetime=ifplotthespace-timeafterthesimuationended.%flux=fluxofthetraffic%%zhoulvwen:zhou.lv.wen@gmail.comrho=0
5、.25;p=0.25;L=100;tmax=100;i=0;%=========================%buildtheGUI%definetheplotbuttonplotbutton=uicontrol(style’,’pushbutton’,…’string'/Run’,...•fontsizef,12,…'position',[60,400,50,20],...'callback','run=l;');%definethestopbuttonerasebutton=uicontrol(,style7pushbutton
6、...’string’,Stop1,...’fontsize’,12,…'position1,[120,400,50,20],...'callback','freeze=lO/O=============================================%definetheQuitbuttonquitbutton=uicontrol(’style’,’pushbutton’”..•string','Quit•,…•fontsize’,12,…'positional80,400,50,20],...,callback,st
7、op=1;close;’);O/O=============================================vmax=5;%maximunspeed%placeadistributionwithdensitynear=round(L*rho);rho=ncar/L;xl=sort(randsample(1:L,near));x2=sort(randsample(1:L,near));x=[xl;x2];%randsample(l:L,near),从1-100产生25个随机整数,sort排序默认升序v=vmax*ones(2
8、,ncar);%starteveryoneinitiallyatvmax[hl,h2]=plotcirc(L,x,0.1);flux=0;%numberofcarsthatpassthroug