資源描述:
《多服務(wù)臺(tái)排隊(duì)系統(tǒng)的仿真.doc》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、.實(shí)驗(yàn)3---多服務(wù)臺(tái)排隊(duì)系統(tǒng)的仿真姓名:學(xué)號(hào):一、目標(biāo)任務(wù)已知一個(gè)系統(tǒng)有N個(gè)服務(wù)員,能力相等,服務(wù)時(shí)間服從指數(shù)分布。顧客的到達(dá)時(shí)間間隔服從指數(shù)分布。用Monte-Carlo仿真,分別求按下列方案的總體平均排隊(duì)時(shí)間:①M(fèi)
2、M
3、N。②N個(gè)單通道系統(tǒng)并列,按1/N概率分裂到達(dá)流。③N個(gè)單通道并列,挑選最短的隊(duì)。要求:①給出程序設(shè)計(jì)的過(guò)程。②如果采用固定的N,則要求N>2。③至少取ρ=0.3和ρ=0.7兩種強(qiáng)度運(yùn)行程序。④對(duì)結(jié)果進(jìn)行分析。二、編程語(yǔ)言Matlab三、關(guān)鍵代碼方案一:N=3;%服務(wù)員人數(shù)r=6;%顧客到達(dá)流強(qiáng)度u=20;%服務(wù)
4、員服務(wù)強(qiáng)度T=1000000;%仿真運(yùn)行時(shí)間avg_wait_time=[];%平均等待時(shí)間fori=1:100%模擬排隊(duì)函數(shù)server_time=[0.0,0.0,0.0];%用來(lái)保存服務(wù)員下一空閑時(shí)間time=0;%絕對(duì)時(shí)鐘,初始為0client_num=0;%顧客總數(shù),初始為0CRTime=0;%顧客到達(dá)時(shí)間間隔ServeTime=0;%顧客服務(wù)時(shí)間server_id=0;%當(dāng)前進(jìn)入排隊(duì)窗口的服務(wù)員編號(hào)total_wait_time=0;%系統(tǒng)中到達(dá)顧客的總等待時(shí)間while1CRTime=exprnd(1/r);%按指數(shù)分布
5、產(chǎn)生顧客到達(dá)時(shí)間間隔time=time+CRTime;%更新系統(tǒng)的絕對(duì)時(shí)鐘精選word范本!.iftime>Tbreak;endclient_num=client_num+1;%顧客數(shù)加1ServeTime=exprnd(1/u);%按指數(shù)分布產(chǎn)生顧客服務(wù)間隔server_id=mod(client_num,N);%按1..N的順序循環(huán)排入服務(wù)員窗口ifserver_id==0server_id=N;endifserver_time(1,server_id)<=time%如果當(dāng)前server_id號(hào)服務(wù)員空閑,則直接接收服務(wù)serve
6、r_time(1,server_id)=time+ServeTime;%服務(wù)員下一空閑時(shí)間為當(dāng)前絕對(duì)時(shí)鐘加上當(dāng)前服務(wù)時(shí)間else%否則所有服務(wù)員都在忙碌,顧客要排隊(duì)等候total_wait_time=total_wait_time+server_time(1,server_id)-time;%顧客排隊(duì)等候時(shí)間為當(dāng)前服務(wù)員下一空閑時(shí)間減去絕對(duì)時(shí)鐘server_time(1,server_id)=server_time(1,server_id)+ServeTime;endendavg_wait_time=[avg_wait_time,to
7、tal_wait_time/client_num];end%計(jì)算平均等待時(shí)間mean_avg_wait_time=mean(avg_wait_time);fprintf('ρ=%2.1f平均等待時(shí)間%6.5f',r/u,mean_avg_wait_time);%打印平均等待時(shí)間%繪制每次仿真的平均等待時(shí)間和總體平均等待時(shí)間線(xiàn)狀圖x=1:100;%plot(x,avg_wait_time,x,mean_avg_wait_time);scatter(x,avg_wait_time,'.');方案二:N=3;%服務(wù)員人數(shù)r=6;%顧客到
8、達(dá)流強(qiáng)度u=20;%服務(wù)員服務(wù)強(qiáng)度T=1000;%仿真運(yùn)行時(shí)間avg_wait_time=[];%平均等待時(shí)間fori=1:100精選word范本!.%模擬排隊(duì)函數(shù)server_time=[0.0,0.0,0.0];%用來(lái)保存服務(wù)員下一空閑時(shí)間time=0;%絕對(duì)時(shí)鐘,初始為0client_num=0;%顧客總數(shù),初始為0CRTime=0;%顧客到達(dá)時(shí)間間隔ServeTime=0;%顧客服務(wù)時(shí)間server_id=0;%當(dāng)前進(jìn)入排隊(duì)窗口的服務(wù)員編號(hào)total_wait_time=0;%系統(tǒng)中到達(dá)顧客的總等待時(shí)間while1CRTime
9、=exprnd(1/r);%按指數(shù)分布產(chǎn)生顧客到達(dá)時(shí)間間隔time=time+CRTime;%更新系統(tǒng)的絕對(duì)時(shí)鐘iftime>Tbreak;endclient_num=client_num+1;%顧客數(shù)加1ServeTime=exprnd(1/u);%按指數(shù)分布產(chǎn)生顧客服務(wù)時(shí)間間隔server_id=randi([1N]);%按1/N的概率排入服務(wù)員窗口ifserver_time(1,server_id)<=time%如果當(dāng)前server_id號(hào)服務(wù)員空閑,則直接接收服務(wù)server_time(1,server_id)=time+Se
10、rveTime;%服務(wù)員下一空閑時(shí)間為當(dāng)前絕對(duì)時(shí)鐘加上當(dāng)前服務(wù)時(shí)間else%否則所有服務(wù)員都在忙碌,顧客要排隊(duì)等候total_wait_time=total_wait_time+server_time(1,server_