修理店仿真报告.docx

上传人:b****8 文档编号:10204128 上传时间:2023-02-09 格式:DOCX 页数:16 大小:50.21KB
下载 相关 举报
修理店仿真报告.docx_第1页
第1页 / 共16页
修理店仿真报告.docx_第2页
第2页 / 共16页
修理店仿真报告.docx_第3页
第3页 / 共16页
修理店仿真报告.docx_第4页
第4页 / 共16页
修理店仿真报告.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

修理店仿真报告.docx

《修理店仿真报告.docx》由会员分享,可在线阅读,更多相关《修理店仿真报告.docx(16页珍藏版)》请在冰豆网上搜索。

修理店仿真报告.docx

修理店仿真报告

修理店仿真报告

一、实验内容和目的

1、应用排队系统流程图,用C语言编制仿真程序,求解以下问题。

修理店只有一个修理工,来修理的顾客到达次数服从泊松分布,平均4人/h;修理时间服从指数分布,平均需6min。

试求(随机数发生器采用floatlcgrand(intstream),种子stream为自己学号的最后两位。

):

①修理店空闲的概率;

②店内有三个顾客的概率;

③店内至少有一个顾客的概率;

④在店内顾客的平均数;

⑤顾客在店内的平均逗留时间;

⑥顾客必须在店内消耗15分钟以上的概率。

2、将到达时间间隔和平均修理时间按如下要求修改后运行程序,给出运行结果。

(1)平均到达时间间隔

10+学号的最后一位

(2)平均修理时间

INT(平均到达时间间隔/3)

二、程序清单

/*Externaldefinitionsforsingle-serverqueueingsystem.*/

#include

#include

/*#include"lcgrand.h"Headerfileforrandom-numbergenerator.*/

#defineQ_LIMIT100/*Limitonqueuelength.*/

#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;

floata19,

total_of_server,

area_3_in_q,

abv_1,

area_num_in_h;

FILE*infile,*outfile;

/*Thefollowing3declarationsareforuseoftherandom-numbergenerator

lcgrandandtheassociatedfunctionslcgrandstandlcgrandgtforseed

management.Thisfile(namedlcgrand.h)shouldbeincludedinanyprogram

usingthesefunctionsbyexecuting

#include"lcgrand.h"

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");

fprintf(outfile,"Meaninterarrivaltime%11.3fminutes\n\n",

mean_interarrival);

fprintf(outfile,"Meanservicetime%16.3fminutes\n\n",mean_service);

fprintf(outfile,"Numberofcustomers%14d\n\n",num_delays_required);

/*Initializethesimulation.*/

initialize();

/*Runthesimulationwhilemoredelaysarestillneeded.*/

while(num_custs_delayed

/*Determinethenextevent.*/

timing();

/*Updatetime-averagestatisticalaccumulators.*/

update_time_avg_stats();

/*Invoketheappropriateeventfunction.*/

switch(next_event_type){

case1:

arrive();

break;

case2:

depart();

break;

}

}

/*Invokethereportgeneratorandendthesimulation.*/

report();

fclose(infile);

fclose(outfile);

return0;

}

 

voidinitialize(void)/*Initializationfunction.*/

{

/*Initializethesimulationclock.*/

sim_time=0.0;

/*Initializethestatevariables.*/

server_status=IDLE;

num_in_q=0;

time_last_event=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;

abv_1=0.0;

area_num_in_h=0.0;

total_of_server=0.0;

a19=0.0;

/*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=time_next_event[i];

next_event_type=i;

}

/*Checktoseewhethertheeventlistisempty.*/

if(next_event_type==0){

/*Theeventlistisempty,sostopthesimulation.*/

fprintf(outfile,"\nEventlistemptyattime%f",sim_time);

exit

(1);

}

/*Theeventlistisnotempty,soadvancethesimulationclock.*/

sim_time=min_time_next_event;

}

 

voidarrive(void)/*Arrivaleventfunction.*/

{

floatdelay;

/*Schedulenextarrival.*/

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

/*Checktoseewhetherserverisbusy.*/

if(server_status==BUSY){

/*Serverisbusy,soincrementnumberofcustomersinqueue.*/

++num_in_q;

/*Checktoseewhetheranoverflowconditionexists.*/

if(num_in_q>Q_LIMIT){

/*Thequeuehasoverflowed,sostopthesimulation.*/

fprintf(outfile,"\nOverflowofthearraytime_arrivalat");

fprintf(outfile,"time%f",sim_time);

exit

(2);

}

/*Thereisstillroominthequeue,sostorethetimeofarrivalofthe

arrivingcustomeratthe(new)endoftime_arrival.*/

time_arrival[num_in_q]=sim_time;

}

else{

/*Serverisidle,soarrivingcustomerhasadelayofzero.(The

followingtwostatementsareforprogramclarityanddonotaffect

theresultsofthesimulation.)*/

delay=0.0;

total_of_delays+=delay;

/*Incrementthenumberofcustomersdelayed,andmakeserverbusy.*/

++num_custs_delayed;

server_status=BUSY;

/*Scheduleadeparture(servicecompletion).*/

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

total_of_server+=time_next_event[2]-sim_time;

if((time_next_event[2]-sim_time)>19)

a19++;

}

}

 

voiddepart(void)/*Departureeventfunction.*/

{

inti;

floatdelay;

/*Checktoseewhetherthequeueisempty.*/

if(num_in_q==0){

/*Thequeueisemptysomaketheserveridleandeliminatethe

departure(servicecompletion)eventfromconsideration.*/

server_status=IDLE;

time_next_event[2]=1.0e+30;

}

else{

/*Thequeueisnonempty,sodecrementthenumberofcustomersin

queue.*/

--num_in_q;

/*Computethedelayofthecustomerwhoisbeginningserviceandupdate

thetotaldelayaccumulator.*/

delay=sim_time-time_arrival[1];

total_of_delays+=delay;

/*Incrementthenumberofcustomersdelayed,andscheduledeparture.*/

++num_custs_delayed;

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

total_of_server+=time_next_event[2]-sim_time;

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

a19++;

/*Moveeachcustomerinqueue(ifany)uponeplace.*/

for(i=1;i<=num_in_q;++i)

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

}

}

 

voidreport(void)/*Reportgeneratorfunction.*/

{

/*Computeandwriteestimatesofdesiredmeasuresofperformance.*/

fprintf(outfile,"\n\nAveragedelayinqueue%11.3fminutes\n\n",

total_of_delays/num_custs_delayed);

fprintf(outfile,"Averagenumberinqueue%10.3f\n\n",

area_num_in_q/sim_time);

fprintf(outfile,"Serverutilization%15.3f\n\n",

area_server_status/sim_time);

fprintf(outfile,"Timesimulationended%12.3fminutes",sim_time);

printf("统计量:

\n");

printf("①修理店空闲的概率:

%24.3f\n",(sim_time-area_server_status)/sim_time);

printf("②店内有三个顾客的概率:

%20.3f\n",area_3_in_q/sim_time);

printf("③店内至少有一个顾客的概率:

%16.3f\n",abv_1/sim_time);

printf("④在店内顾客的平均数:

%22.3f\n",area_num_in_h/sim_time);

printf("⑤顾客在店内的平均逗留时间:

%16.3f\n",(total_of_delays+total_of_server)/num_custs_delayed);

printf("⑥顾客必须在店内消耗19分钟以上概率:

%8.3f\n\n",a19/num_custs_delayed);

printf("仿真时间:

%12.3fminutes\n\n",sim_time);

}

 

voidupdate_time_avg_stats(void)/*Updateareaaccumulatorsfortime-average

statistics.*/

{

floattime_since_last_event;

/*Computetimesincelastevent,andupdatelast-event-timemarker.*/

time_since_last_event=sim_time-time_last_event;

time_last_event=sim_time;

/*Updateareaundernumber-in-queuefunction.*/

area_num_in_q+=num_in_q*time_since_last_event;

/*Updateareaunderserver-busyindicatorfunction.*/

area_server_status+=server_status*time_since_last_event;

if(server_status==BUSY)

if(num_in_q==2)

area_3_in_q+=time_since_last_event;

if(server_status==IDLE)

if(num_in_q==3)

area_3_in_q+=time_since_last_event;

if(server_status==BUSY)

abv_1+=time_since_last_event;

if(server_status==IDLE)

if(num_in_q>0)

abv_1+=time_since_last_event;

if(server_status==BUSY)

area_num_in_h+=(num_in_q+1)*time_since_last_event;

if(server_status==IDLE)

area_num_in_h+=num_in_q*time_since_last_event;

}

 

floatexpon(floatmean)/*Exponentialvariategenerationfunction.*/

{

/*Returnanexponentialrandomvariatewithmean"mean".*/

return-mean*log(lcgrand(29));

}

 

/*Primemodulusmultiplicativelinearcongruentialgenerator

Z[i]=(630360016*Z[i-1])(mod(pow(2,31)-1)),basedonMarseandRoberts'

portableFORTRANrandom-numbergeneratorUNIRAN.Multiple(100)streamsare

supported,withseedsspaced100,000apart.Throughout,inputargument

"stream"mustbeanintgivingthedesiredstreamnumber.Theheaderfile

lcgrand.hmustbeincludedinthecallingprogram(#include"lcgrand.h")

beforeusingthesefunctions.

Usage:

(Threefunctions)

1.ToobtainthenextU(0,1)randomnumberfromstream"stream,"execute

u=lcgrand(stream);

wherelcgrandisafloatfunction.Thefloatvariableuwillcontainthe

nextrandomnumber.

2.Tosettheseedforstream"stream"toadesiredvaluezset,execute

lcgrandst(zset,stream);

wherelcgrandstisavoidfunctionandzsetmustbealongsettothe

desiredseed,anumberbetween1and2147483646(inclusive).Default

seedsforall100streamsaregiveninthecode.

3.Togetthecurrent(mostrecentlyused)integerinthesequencebeing

generatedforstream"stream"intothelongvariablezget,execute

zget=lcgrandgt(stream);

wherelcgrandgtisalongfunction.*/

/*Definetheconstants.*/

#defineMODLUS2147483647

#defineMULT124112

#defineMULT226143

/*Setthedef

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

当前位置:首页 > 高等教育 > 文学

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

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