欢迎来到天天文库
浏览记录
ID:43849510
大小:76.31 KB
页数:5页
时间:2019-10-15
《排队模型(matlab代码)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、functionout=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——到
2、达机器数%b_count——修理机器数%e_count——损失机器数%初始化arrive_time=exprnd(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;%循环whilemin([arrive_time,leave_time])3、time];%记录时间序列ifcurrent_time==min(arrive_time)%机器到达子过程arrive_time(1)=[];%从事件表中抹去机器到达事件a_count=a_count+1;%累加到达机器数ifL4、time);%离开事件表排序else%无空闲修理工L=L+1;%更新队长c=[c,current_time];%记录机器到达时间序列endelse%机器离开子过程leave_time(1)=[];%从事件表中抹去机器离开事件arrive_time=[arrive_time,current_time+exprnd(mu1)];arrive_time=sort(arrive_time);%到达事件表排序e=[e,current_time];%记录机器离开时间序列ifL>s%有机器等待L=L-1;%更新队长b=[b,current_time];%记录修5、理开始时间序列leave_time=[leave_time,current_time+exprnd(mu2)];%产生新的机器离开事件leave_time=sort(leave_time);%离开事件表排序else%无机器等待L=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]).*6、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)/factorial(m-1).*(mu2/mu1)^2+factorial(m)/factorial(m-2).*(mu2/mu1)^2+factorial(m)/factorial(m-4).*(mu2/mu1)^4+factorial(m)/factori7、al(m-5).*(mu2/mu1)^5);fprintf('修理工空闲概率:%d',p_s)%修理工空闲概率fprintf('到达机器数:%d',a_count)%到达机器数fprintf('平均逗留时间:%f',sum(e-c(1:length(e)))/length(e))%平均逗留时间fprintf('平均等待时间:%f',sum(b-c(1:length(b)))/length(b))%平均等待时间fprintf('平均修理时间:%f',sum(e-b(1:length(e)))/length(e))%平均修理时间f8、printf('平均队长:%f',sum(diff([tt,T]).*LL)/T)%平均队长fprintf('平均等待队长:%f
3、time];%记录时间序列ifcurrent_time==min(arrive_time)%机器到达子过程arrive_time(1)=[];%从事件表中抹去机器到达事件a_count=a_count+1;%累加到达机器数ifL
4、time);%离开事件表排序else%无空闲修理工L=L+1;%更新队长c=[c,current_time];%记录机器到达时间序列endelse%机器离开子过程leave_time(1)=[];%从事件表中抹去机器离开事件arrive_time=[arrive_time,current_time+exprnd(mu1)];arrive_time=sort(arrive_time);%到达事件表排序e=[e,current_time];%记录机器离开时间序列ifL>s%有机器等待L=L-1;%更新队长b=[b,current_time];%记录修
5、理开始时间序列leave_time=[leave_time,current_time+exprnd(mu2)];%产生新的机器离开事件leave_time=sort(leave_time);%离开事件表排序else%无机器等待L=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]).*
6、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)/factorial(m-1).*(mu2/mu1)^2+factorial(m)/factorial(m-2).*(mu2/mu1)^2+factorial(m)/factorial(m-4).*(mu2/mu1)^4+factorial(m)/factori
7、al(m-5).*(mu2/mu1)^5);fprintf('修理工空闲概率:%d',p_s)%修理工空闲概率fprintf('到达机器数:%d',a_count)%到达机器数fprintf('平均逗留时间:%f',sum(e-c(1:length(e)))/length(e))%平均逗留时间fprintf('平均等待时间:%f',sum(b-c(1:length(b)))/length(b))%平均等待时间fprintf('平均修理时间:%f',sum(e-b(1:length(e)))/length(e))%平均修理时间f
8、printf('平均队长:%f',sum(diff([tt,T]).*LL)/T)%平均队长fprintf('平均等待队长:%f
此文档下载收益归作者所有