1、function out=MMSmteam(s,m,mu1,mu2,T)%M/M/S/m 排队模型%s修理工个数%m机器源数%T时间终止点%mu1机器离开-到达时间服从指数分布%mu2修理时间服从指数分布%事件表:% p_s修理工空闲概率% arrive_time机器到达事件% leave_time机器离开事件%mintime事件表中的最近事件%current_time当前时间%L队长%tt时间序列%LL队长序列%c机器到达时间序列%b修理开始时间序列%e机器离开时间序列%a_count到达机器数%b_count修理机器数%e_count损失机器数%初始化arrive_time=exprnd(
2、mu1,1,m);arrive_time=sort(arrive_time);leave_time=;current_time=0;L=0;LL=L;tt=current_time;c=;b=;e=;a_count=0;%循环while min(arrive_time,leave_time)s %有机器等待L=L-1; %更新队长b=b,current_time;%记录修理开始时间序列leave_time=leave_time,current_time+exprnd(mu2);%产生新的机器离开事件leave_time=sort(leave_time);%离开事件表排序else %无机器等待L
3、=L-1; %更新队长endendLL=LL,L; %记录队长序列endWs=sum(e-c(1:length(e)/length(e);Wq=sum(b-c(1:length(b)/length(b);Wb=sum(e-b(1:length(e)/length(e);Ls=sum(diff(tt,T).*LL)/T;Lq=sum(diff(tt,T).*max(LL-s,0)/T;p_s=1.0/(factorial(m)/factorial(m).*(mu2/mu1)0+factorial(m)/factorial(m-1).*(mu2/mu1)1+factorial(m-2)/facto
4、rial(m-1).*(mu2/mu1)2+factorial(m)/factorial(m-2).*(mu2/mu1)2+factorial(m)/factorial(m-4).*(mu2/mu1)4+factorial(m)/factorial(m-5).*(mu2/mu1)5);fprintf(修理工空闲概率:%dn,p_s)%修理工空闲概率fprintf(到达机器数:%dn,a_count)% 到达机器数fprintf(平均逗留时间:%fn,sum(e-c(1:length(e)/length(e)%平均逗留时间fprintf(平均等待时间:%fn,sum(b-c(1:length(b
5、)/length(b)%平均等待时间fprintf(平均修理时间:%fn,sum(e-b(1:length(e)/length(e)% 平均修理时间fprintf(平均队长:%fn,sum(diff(tt,T).*LL)/T)%平均队长fprintf(平均等待队长:%fn,sum(diff(tt,T).*max(LL-s,0)/T)%平均等待队长for i=0:mp(i+1)=sum(LL=i).*diff(tt,T)/T;%队长为 i 的概率fprintf(队长为%d 的概率 :%fn,i,p(i+1);endfprintf(机器不能马上得到修理的概率:%fn,1-sum(p(1:s)%机器
6、不能马上得到修理的概率out=Ws,Wq,Wb,Ls,Lq,p;function out=MMSkteam(s,k,mu1,mu2,T)%多服务台%s服务台个数%k最大顾客等待数%T时间终止点%mu1到达时间间隔服从指数分布%mu2服务时间服从指数分布%事件表:% arrive_time顾客到达事件% leave_time顾客离开事件%mintime事件表中的最近事件%current_time当前时间%L队长%tt时间序列%LL队长序列%c顾客到达时间序列%b服务开始时间序列%e顾客离开时间序列%a_count到达顾客数%b_count服务顾客数%e_count损失顾客数%初始化arrive_
7、time=exprnd(mu1);leave_time=;current_time=0;L=0;LL=L;tt=current_time;c=;b=;e=;a_count=0;b_count=0;e_count=0;%循环while min(arrive_time,leave_time)s %有顾客等待L=L-1; %更新队长b=b,current_time;%记录服务开始时间序列leave_time=leave_time,current_time+exprnd(mu2);leave_time=sort(leave_time);%离开事件表排序else %无顾客等待L=L-1; %更新队长en
8、dendLL=LL,L; %记录队长序列endWs=sum(e-c(1:length(e)/length(e);Wq=sum(b-c(1:length(b)/length(b);Wb=sum(e-b(1:length(e)/length(e);Ls=sum(diff(tt,T).*LL)/T;Lq=sum(diff(tt,T).*max(LL-s,0)/T;fprintf(到达顾客数:%dn,a_count)% 到达顾客数fprintf(服务顾客数:%dn,b_count)% 服务顾客数fprintf(损失顾客数:%dn,e_count)% 损失顾客数fprintf(平均逗留时间:%fn,Ws
9、)%平均逗留时间fprintf(平均等待时间:%fn,Wq)%平均等待时间fprintf(平均服务时间:%fn,Wb)%平均服务时间fprintf(平均队长:%fn,Ls)% 平均队长fprintf(平均等待队长:%fn,Lq)% 平均等待队长if k=inffor i=0:s+kp(i+1)=sum(LL=i).*diff(tt,T)/T;%队长为 i 的概率fprintf(队长为%d 的概率 :%fn,i,p(i+1);endelsefor i=0:3*sp(i+1)=sum(LL=i).*diff(tt,T)/T;%队长为 i 的概率fprintf(队长为%d 的概率 :%fn,i,p(i+1);end endfprintf(顾客不能马上得到服务的概率:%fn,1-sum(p(1:s)%顾客不能马上得到服务的概率out=Ws,Wq,Wb,Ls,Lq,p;