function p=queue(mu,lamda)
customer=zeros(1000,6); %每一行代表是一位顾客,每一行的每一列所代表的意思如下所示
NO=1; %/*编号*/
intime=2; %/*进入队列时间*/
intertime=3; %/*他的下一个人到来的时间间隔*/
starttime=4; %/*开始接受服务时间*/
durtime=5; %/*服务所需时间*/
leavetime=6; %/*离开队列的时间*/
flag=1; %初始化flag=1,当flag=1时,采用泊松和指数分布,当flag=0时,采用平均和瑞利分布
%*********************************InitQueue();%初始化队列***********************
queue_customernum=0; %/*队列中接受服务的顾客数*/
curtime=1; %/*当前时间*/
first=0; %/*当前接受服务的顾客的编号*/
last=0; %/*当前队列最后一位顾客的编号*/
totalnum=0; %/*进入队列的总的顾客数*/
cusnum=zeros(1,100); %/*存放观察到的队列中接受服务的顾客数*/
p=zeros(1,11); %/*存放观察到的队列中接受服务的某个顾客数的出现的次数*/
%********************************customer_in();%顾客进入队列*******************
if queue_customernum~=10
totalnum=totalnum+1;
queue_customernum=queue_customernum+1;
customer(totalnum,NO)=totalnum;
customer(totalnum,intime)=curtime; %/*记录顾客进入时间*/
if flag==1
customer(totalnum,durtime)=poissrnd(mu,1,1); %/*产生随机数记录顾客服务所需时间*/ 泊松分布
customer(totalnum,intertime)=round(exprnd(lamda,1,1)*10); %/*此顾客的下一个顾客来的时间间隔*/ 指数分布
else
customer(totalnum,durtime)=unidrnd(mu,1,1); %/*产生随机数记录顾客服务所需时间*/ 均匀分布
customer(totalnum,intertime)=round(raylrnd(lamda,1,1)*10); %/*此顾客的下一个顾客来的时间间隔*/ 瑞利分布
end
last=last+1;
else
customer(totalnum,intertime)=customer(totalnum,intertime)+1;
end
%*****************************customer_serve();%顾客接受服务********************
first=first+1;
customer(first,starttime)=curtime; %/*得出开始服务时间和离开时间*/
customer(first,leavetime)=customer(first,durtime)+curtime;
%**************************************************************************
while curtime<=1000 %/*当前时间属于营业时间,允许顾客进入*/
curtime=curtime+1;
if customer(first,leavetime)==curtime
%customer_leave();%顾客离开队列
queue_customernum=queue_customernum-1;
%customer_serve();%顾客接受服务
first=first+1;
customer(first,starttime)=curtime; %/*得出开始服务时间和离开时间*/
customer(first,leavetime)=customer(first,durtime)+curtime;
end
if (customer(last,intime)+customer(last,intertime))==curtime
%customer_in(); %顾客进入队列 %/*判断是否有人符合要进的条件*/
if queue_customernum~=10
totalnum=totalnum+1;
queue_customernum=queue_customernum+1;
customer(totalnum,NO)=totalnum;
customer(totalnum,intime)=curtime; %/*记录顾客进入时间*/
if flag==1
customer(totalnum,durtime)=poissrnd(mu,1,1); %/*产生随机数记录顾客服务所需时间*/ 泊松分布
customer(totalnum,intertime)=round(exprnd(lamda,1,1)*10); %/*此顾客的下一个顾客来的时间间隔*/ 指数分布
else
customer(totalnum,durtime)=unidrnd(mu,1,1); %/*产生随机数记录顾客服务所需时间*/ 均匀分布
customer(totalnum,intertime)=round(raylrnd(lamda,1,1)*10); %/*此顾客的下一个顾客来的时间间隔*/ 瑞利分布
end
last=last+1;
else
customer(totalnum,intertime)=customer(totalnum,intertime)+1;
end
end
if rem(curtime,10)==0
cusnum(1,curtime/10)=queue_customernum;
end
end
%************************probability();%计算队列中顾客数为(0,1,。。。,10)时的概率**********
for i=1:1:100
if cusnum(1,i)==0
p(1,1)=p(1,1)+1;
elseif cusnum(1,i)==1
p(1,2)=p(1,2)+1;
elseif cusnum(1,i)==2
p(1,3)=p(1,3)+1;
elseif cusnum(1,i)==3
p(1,4)=p(1,4)+1;
elseif cusnum(1,i)==4
p(1,5)=p(1,5)+1;
elseif cusnum(1,i)==5
p(1,6)=p(1,6)+1;
elseif cusnum(1,i)==6
p(1,7)=p(1,7)+1;
elseif cusnum(1,i)==7
p(1,8)=p(1,8)+1;
elseif cusnum(1,i)==8
p(1,9)=p(1,9)+1;
elseif cusnum(1,i)==9
p(1,10)=p(1,10)+1;
elseif cusnum(1,i)==10
p(1,11)=p(1,11)+1;
end
end
%***************************list();%打印结果****************************
for j=1:1:11
p(1,j)=p(1,j)/100;
end
D118