資源描述:
《雙圓道交通流ca模型matlab程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、%functionfrho,flux,vmeanl=ns2(rho,p,L,tmax)%注意:主函數(shù)一定不能像子函數(shù)一樣以function開頭。此程序?yàn)楹刂瓢粹oNS模型改編雙車道,無換道。%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(動(dòng)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產(chǎn)生25個(gè)隨機(jī)整數(shù),sort排序默認(rèn)升序v=vmax*ones(2
8、,ncar);%starteveryoneinitiallyatvmax[hl,h2]=plotcirc(L,x,0.1);flux=0;%numberofcarsthatpassthroug