可直接在matlab中使用。使用monte carlo模擬的方法精確地得到m/d/c,和m/m/c等傳統排隊系統的各項數量指標。
在模擬中,按照服從給定的possion分布的lamuda隨機生成乘客的到達時間,模擬乘客到達;按定長分布或possion分布的規律隨機生成服務時間。當乘客到達系統時,先考慮系統內是否有空閒的服務台,若此時有空閒服務台,則乘客任意進入乙個空閒服務台,同時標記該服務台正在進行服務;若沒有,則該乘客進入等待佇列,直至出現空閒服務台時,再按進入等待佇列的先後次序依次接受服務。當達到設定的模擬事件後,結束模擬並輸出結果。
clc
clear
for
temp=1:10
trial = 10;
p0result =
zeros
(1,trial);
pcresult=
zeros
( 1,trial);
pwresult=
zeros
( 1,trial);
lsresult=
zeros
(1,trial);
lqresult=
zeros
( 1,trial);
wsresult=
zeros
(1,trial);
wqresult=
zeros
( 1,trial);
for
m=1:trial
lambda=0.0852+(0.534-0.0852)*(temp-1)/10; mu=0.089; t=50000;
n=0;
lq=0; ls=0;
wq=0; ws=0;
p0=0; pc=0; pw=0;
busy=
zeros
(1, c);
arrive=0; nextarrive=0;
time1=
zeros
(1, c);
time2=t*ones(1,c);
nextarrive =exprnd(1/lambda);
min=nextarrive;
for
i=1:c
if time2(i)<
minmin
=time2(i);
endend
while min
if min
== nextarrive
arrive=nextarrive;
nextarrive = arrive+exprnd(1/lambda);
n=n+1;
busytotal=0;
for
i=1:c
busytotal=busytotal+busy(i);
endproduct=1;
for
i=1:c
product=product*busy(i);
endif
((lq==0)&&(busytotal==0))
p0=p0 +1;
endif
((lq==0)&&(product==1))
pc=pc+1;
endif
(product==1)
pw=pw+1;
endif
product==0
ls=ls+lq+busytotal;
count=0;
for
i=1:c
if busy(i)==0
count=count+1;
empty(count)=i;
endend
select = randint(1,1,[1,count]);
j= empty(select);
time1(j)=arrive;
busy(j)=1;
time1(j) = time1(j) + exprnd(1/mu);
time2(j)=time1(j);
else
ls=ls+lq+c;
lq=lq+1;
endelse
k=1;
for
i=1:c
if time2(k)>time2(i)
k=i;
endendif
lq==0
busy(k)=0;
time2(k)=t;
else
lq=lq-1;
time1(k)=time1(k) + exprnd(1 /mu);
time2(k)=time1(k);
endend
min=nextarrive;
for
i=1:c
if time2(i)<
minmin
=time2(i);
endend
endif
n==0
disp
(』äˇ cäâê´ sijät´zý˝uìˇ cˇ nçëöøðâêäèët』);
else
p0=p0/n; pc=pc/n;pw=pw/n;
ls=ls/n; lq=ls-lambda/mu;
ws=ls/lambda; wq=lq/lambda;
p0result(m)=p0;
pcresult(m)=pc;
pwresult(m)=pw;
lsresult(m)=ls;
lqresult(m)=lq;
wsresult(m)=ws;
wqresult(m)=wq;
endend
p0finalresult(temp)=
mean
(p0result); p0std(temp)=
std
(p0result);
pcfinalresult(temp)=
mean
(pcresult); pcstd(temp)=
std
(pcresult);
pwfinalresult(temp)=
mean
(pwresult); pwstd(temp)=
std
(pwresult);
lsfinalresult(temp)=
mean
(lsresult); lsstd(temp)=
std
(lsresult);
lqfinalresult(temp)=
mean
(lqresult); lqstd(temp)=
std
(lqresult);
wsfinalresult(temp)=
mean
(wsresult); wsstd(temp)=
std
(wsresult);
wqfinalresult(temp)=
mean
(wqresult); wqstd(temp)=
std
(wqresult);
final(temp,:)=[p0finalresult(temp),pcfinalresult(temp), pwfinalresult(temp), lqfinal
end
排隊論基礎
參考 運籌學教程 胡運權 排隊論是對排隊問題的研究,表示為隨機聚散服務系統。聚即為到達,散即為離去,隨機指的是顧客的到達情況與每個顧客接受服務的時間是隨機的。一般來說,顧客的相繼到達時間與服務時間這兩個量至少有乙個量是未知的。因此,排隊論一般被稱為隨機服務系統理論。以下僅介紹基本概念 說明顧客如何到...
排隊論在食堂排隊中的運用
一 問題描述 排隊在日常生活中是非常常見的現象。在學校中,每次到了飯點的時間,食堂都會水洩不通,對於同學們來說,減少排隊等待時間是同學們的需求,但是對於食堂來說,增加視窗的同時,也會相應增加運營成本,如何設定視窗的數量,達到雙方都能接受並相對滿意的程度是值得分析的。理論準備1 排隊系統的符號一般形式...
猴子排隊演算法
一群猴子排成一圈,按1,2,n依次編號。然後從第1只開始數,數到第m只,把它踢出圈,從它後面再開始數,再數到第m只,在把它踢出去 如此不停的進行下去,直到最後只剩下乙隻猴子為止,那只猴子就叫做大王。要求程式設計模擬此過程,輸入m n,輸出最後那個大王的編號。function yuesefu n,m ...