排队论经典程序MM1代码Word文件下载.docx

上传人:b****3 文档编号:17616619 上传时间:2022-12-07 格式:DOCX 页数:14 大小:20.97KB
下载 相关 举报
排队论经典程序MM1代码Word文件下载.docx_第1页
第1页 / 共14页
排队论经典程序MM1代码Word文件下载.docx_第2页
第2页 / 共14页
排队论经典程序MM1代码Word文件下载.docx_第3页
第3页 / 共14页
排队论经典程序MM1代码Word文件下载.docx_第4页
第4页 / 共14页
排队论经典程序MM1代码Word文件下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

排队论经典程序MM1代码Word文件下载.docx

《排队论经典程序MM1代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《排队论经典程序MM1代码Word文件下载.docx(14页珍藏版)》请在冰豆网上搜索。

排队论经典程序MM1代码Word文件下载.docx

area_3_in_q+=time_since_last_event;

3 //店内至少有一个顾客的概率

if(server_status==BUSY)//服务台忙,则店内至少有一个顾客

abv_1+=time_since_last_event;

4 //在店内顾客的平均数

if(server_status==BUSY)//服务台忙,总的顾客数为排队顾客数加一

area_num_in_h+=(num_in_q+1)*time_since_last_event;

5 total_of_server+=time_next_event[2]-sim_time;

//总的服务时间加一个服务时间为新的服务总时间

delay=sim_time-time_arrival[1];

//排队时间=当前时间-这个人来的时间

total_of_delays+=delay;

6 //离开时总的消耗时间大于15,必须在店内消耗15分钟以上的顾客数加一

if((delay+time_next_event[2]-sim_time)>

15)

abv_15++;

//到达时总的服务时间大于15,必须在店内消耗15分钟以上的顾客数加一

if((time_next_event[2]-sim_time)>

abv_15++;

程序代码:

/*Externaldefinitionsforsingle-serverqueueingsystem.*/

#include<

stdio.h>

math.h>

/*#include"

lcgrand.h"

Headerfileforrandom-numbergenerator.*/

#defineQ_LIMIT100/*Limitonqueuelength.队伍最长100人*/

#defineBUSY1/*Mnemonicsforserver'

sbeingbusy忙碌状态*/

#defineIDLE0/*andidle.空闲状态*/

intnext_event_type,//下一个事件类型

num_custs_delayed,//已模拟的顾客数

num_delays_required,//模拟的顾客数

num_events,//事件数

num_in_q,//队列中的顾客数

server_status;

//服务状态

floatarea_num_in_q,//有顾客的时间

area_server_status,//总的服务时间

mean_interarrival,//平均顾客到达时间间隔

mean_service,//平均服务时间

sim_time,//模拟时间

time_arrival[Q_LIMIT+1],//到来的时间

time_last_event,//上一个事件的时间

time_next_event[3],//下一个事件的时间

total_of_delays;

//总的排队时间

////////////////////////////////////////////////////////////////////////////////////

//添加的变量

floatabv_15,//15分钟以上的顾客数量

total_of_server,//所有顾客的总的服务时间

area_3_in_q,//有3个顾客的时间

abv_1,//至少有一个顾客的时间

area_num_in_h;

//顾客总数

FILE*infile,*outfile;

/*Thefollowing3declarationsareforuseoftherandom-numbergenerator

lcgrandandtheassociatedfunctionslcgrandstandlcgrandgtforseed

management.Thisfile(namedlcgrand.h)shouldbeincludedinanyprogram

usingthesefunctionsbyexecuting

#include"

beforereferencingthefunctions.*/

floatlcgrand(intstream);

voidlcgrandst(longzset,intstream);

longlcgrandgt(intstream);

 

voidinitialize(void);

voidtiming(void);

voidarrive(void);

voiddepart(void);

voidreport(void);

voidupdate_time_avg_stats(void);

floatexpon(floatmean);

main()/*Mainfunction.*/

{

/*Openinputandoutputfiles.*/

infile=fopen("

mm1.in"

"

r"

);

outfile=fopen("

mm1.out"

w"

/*Specifythenumberofeventsforthetimingfunction.*/

num_events=2;

//两种事件

/*Readinputparameters.*/

fscanf(infile,"

%f%f%d"

&

mean_interarrival,&

mean_service,

&

num_delays_required);

/*Writereportheadingandinputparameters.输出*/

fprintf(outfile,"

Single-serverqueueingsystem\n\n"

Meaninterarrivaltime%11.3fminutes\n\n"

mean_interarrival);

Meanservicetime%16.3fminutes\n\n"

mean_service);

Numberofcustomers%14d\n\n"

num_delays_required);

/*Initializethesimulation.初始化仿真*/

initialize();

//初始化

/*Runthesimulationwhilemoredelaysarestillneeded.没服务完,仿真继续*/

while(num_custs_delayed<

num_delays_required){//当已服务顾客数小于1000时

/*Determinethenextevent.确定下一事件*/

timing();

/*Updatetime-averagestatisticalaccumulators.时间记录更新*/

update_time_avg_stats();

/*Invoketheappropriateeventfunction.根据事件的不同,调用不同的函数*/

switch(next_event_type){

case1:

arrive();

//到达

break;

case2:

depart();

//离开

}

/*Invokethereportgeneratorandendthesimulation.*/

report();

fclose(infile);

fclose(outfile);

return0;

}

voidinitialize(void)/*Initializationfunction.*/

/*Initializethesimulationclock.仿真时间置为0*/

sim_time=0.0;

/*Initializethestatevariables.最开始状态初始化*/

server_status=IDLE;

//服务空闲

num_in_q=0;

//队伍里无人排队

time_last_event=0.0;

//上一个事件的时间,最开始肯定是0开始

/*Initializethestatisticalcounters.*/

num_custs_delayed=0;

//已经服务的人数

total_of_delays=0.0;

//总的排队时间

area_num_in_q=0.0;

//有顾客的时间

area_server_status=0.0;

//总的服务时间

/////////////////////////////////////////////////////////////////////////////////

//添加的变量的初始化

area_3_in_q=0.0;

//有3个顾客的时间

abv_1=0.0;

area_num_in_h=0.0;

//顾客的总数

total_of_server=0.0;

//所有顾客的所有的服务的时间

abv_15=0.0;

//消耗15分钟以上的顾客数

/*Initializeeventlist.初始化事件列表Sincenocustomersarepresent,thedeparture

(servicecompletion)eventiseliminatedfromconsideration.无顾客存在和离开*/

time_next_event[1]=sim_time+expon(mean_interarrival);

//下一事件是来的时间

time_next_event[2]=1.0e+30;

//下一事件是离开的时间

voidtiming(void)/*Timingfunction.*/

inti;

floatmin_time_next_event=1.0e+29;

//像指针一样的对于当前服务的人来说下一个事件的时间

next_event_type=0;

/*Determinetheeventtypeofthenexteventtooccur.接下来将要发生的事件的类型*/

for(i=1;

i<

=num_events;

++i)

if(time_next_event[i]<

min_time_next_event){//下一事件是来的时间跟离开时间比较

min_time_next_event=time_next_event[i];

next_event_type=i;

/*Checktoseewhethertheeventlistisempty.*/

if(next_event_type==0){

/*Theeventlistisempty,sostopthesimulation.无事件,停止仿真过程*/

\nEventlistemptyattime%f"

sim_time);

exit

(1);

/*Theeventlistisnotempty,soadvancethesimulationclock.有事件,进行仿真过程*/

sim_time=min_time_next_event;

//仿真的时间就是当前事件的时间

voidarrive(void)/*Arrivaleventfunction.*/

floatdelay;

/*Schedulenextarrival.计划下一次的到来*/

/*Checktoseewhetherserverisbusy.检测是否在服务状态*/

if(server_status==BUSY){

/*Serverisbusy,soincrementnumberofcustomersinqueue.在服务则排队多一人*/

++num_in_q;

/*Checktoseewhetheranoverflowconditionexists.检测人数是否超出*/

if(num_in_q>

Q_LIMIT){

/*Thequeuehasoverflowed,sostopthesimulation.*/

\nOverflowofthearraytime_arrivalat"

time%f"

exit

(2);

/*Thereisstillroominthequeue,sostorethetimeofarrivalofthe

arrivingcustomeratthe(new)endoftime_arrival.队列中仍有空间时,记录新到达的时间*/

time_arrival[num_in_q]=sim_time;

//在这个时间的时候有这么多的排队人数,用于计算3顾客的问题

else{//服务空闲的状况

/*Serverisidle,soarrivingcustomerhasadelayofzero.(The

followingtwostatementsareforprogramclarityanddonotaffect

theresultsofthesimulation.)*/

delay=0.0;

/*Incrementthenumberofcustomersdelayed,andmakeserverbusy.*/

++num_custs_delayed;

//已经模拟的顾客数加1

server_status=BUSY;

//人到来,服务开始

/*Scheduleadeparture(servicecompletion).服务完成*/

time_next_event[2]=sim_time+expon(mean_service);

//这个人离开的时间为现在时间+服务时间

//总的服务时间加上当前服务时间,更新总的服务时间

total_of_server+=time_next_event[2]-sim_time;

//总的服务时间大于15,必须在店内消耗15分钟以上的顾客数加一

15)//如果这个人服务时间超过15分钟则耗费15分钟人数加1

voiddepart(void)/*Departureeventfunction.讨论离开事件*/

/*Checktoseewhetherthequeueisempty.检测队列是否为空*/

if(num_in_q==0){

/*Thequeueisemptysomaketheserveridleandeliminatethe

departure(servicecompletion)eventfromconsideration.队列空,服务空闲*/

//离开的时间无限大(无人离开)

else{

/*Thequeueisnonempty,sodecrementthenumberofcustomersin

queue.有人离开,队列人数减少*/

--num_in_q;

/*Computethedelayofthecustomerwhoisbeginningserviceandupdate

thetotaldelayaccumulator.*/

/*Incrementthenumberofcustomersdelayed,andscheduledeparture.已经服务人数+1*/

//服务人数加1

//当前接受服务的人的离开时间

//总的消耗时间大于15,必须在店内消耗15分钟以上的顾客数加一

/*Moveeachcustomerinqueue(ifany)uponeplace.有人离开,队列前移*/

=num_in_q;

++i)

time_arrival[i]=time_arrival[i+1];

//人的到达时间也前移

voidreport(void)/*Reportgeneratorfunction.*/

/*Computeandwriteestimatesofdesiredmeasuresofperformance.*/

\n\nAveragedelayinqueue%11.3fminutes\n\n"

total_of_delays/num_custs_delayed);

Averagenumberinqueue%10.3f\n\n"

area_num_in_q/sim_time);

Serverutilization%15.3f\n\n"

area_server_status/sim_time);

Timesimulationended%12.3fminutes"

printf("

统计量:

\n"

////////////////////////////////////////////////////////////////////////

//总时间减去服务台忙的时间除以总时间,得到服务台空闲的概率

%24.3f\n"

%20.3f\n"

%16.3f\n"

④在

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 建筑土木

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1