版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
計(jì)算機(jī)仿真排隊(duì)系統(tǒng)實(shí)驗(yàn)報(bào)告(附代碼)14100字
計(jì)算機(jī)仿真實(shí)驗(yàn)報(bào)告第一題1.作業(yè)內(nèi)容應(yīng)用排隊(duì)系統(tǒng)流程圖,用C語(yǔ)言編制仿真程序,求解以下問題。修理店只有一個(gè)修理工,來修理的顧客到達(dá)次數(shù)服從泊松分布,平均4人/h;修理時(shí)間服從指數(shù)分布,平均需6min。試求(隨機(jī)數(shù)發(fā)生器采用floatlcgrand(intstream),種子stream為自己學(xué)號(hào)的最后兩位。):①修理店空閑的概率;②店內(nèi)有三個(gè)顧客的概率;③店內(nèi)至少有一個(gè)顧客的概率;④在店內(nèi)顧客的平均數(shù);⑤顧客在店內(nèi)的平均逗留時(shí)間;⑥顧客必須在店內(nèi)消耗15分鐘以上的概率。統(tǒng)計(jì)量實(shí)現(xiàn)算法:①修理店空閑的概率;p1=1-area_server_status/sim_timearea_server_status:總服務(wù)時(shí)間(即修理工在這段仿真時(shí)間里非空閑時(shí)間)sim_time:總仿真時(shí)間用1減去非空閑概率,即為空閑概率。②店內(nèi)有三個(gè)顧客的概率;p2=Three_people_time/sim_time增加變量Three_people_time,即有三個(gè)顧客在店內(nèi)的時(shí)間。三個(gè)顧客在店里,也就是說一個(gè)顧客在理發(fā),兩個(gè)人在排隊(duì),此時(shí),無(wú)論是來一個(gè)新的客人或者離開一個(gè)客人,都會(huì)破壞這種三個(gè)人的狀態(tài),所以我們每次要統(tǒng)計(jì)的,就是這種三個(gè)人的狀態(tài)持續(xù)的時(shí)間。因此,用到的是time_since_last_event這個(gè)變量,該變量用于統(tǒng)計(jì)兩種狀態(tài)(事件,包括離開和到來)之間的事件。因此,在每次計(jì)算完time_since_last_event之后,考察隊(duì)伍中的人數(shù)是否為2,若為2,則把該段time_since_last_event加到Three_people_time中。仿真結(jié)束時(shí),用Three_people_time/總仿真時(shí)間,即為店內(nèi)有三個(gè)顧客的概率。③店內(nèi)至少有一個(gè)顧客的概率;p3=p3=1-idle_time/sim_time增加變量idle_time,即店里空閑的概率(沒有顧客),用1減去一個(gè)顧客都沒有的概率,就是至少有一個(gè)顧客的概率。判斷店里空閑的方法是,如果當(dāng)前有一個(gè)顧客來了,他不需要排隊(duì),就意味著這之前店里是空閑著的。這里仍用到time_since_last_event,在這個(gè)客人來之前的這段時(shí)間店里空閑,因此把這個(gè)時(shí)間段加給idle_time,以此累加,最后得到總的空閑時(shí)間。④在店內(nèi)顧客的平均數(shù);mean_customer=1.0*num_custs_delayed/sim_time在這里我計(jì)算的是店里平均每分鐘的顧客數(shù)(包括等待的和正在理發(fā)的)。num_cust_delayed是在這段仿真時(shí)間里總共出現(xiàn)的顧客,除以仿真時(shí)間,就是店內(nèi)顧客平均數(shù)。⑤顧客在店內(nèi)的平均逗留時(shí)間;mean_stay_time=(area_num_in_q+area_server_status)/(1.0*num_custs_delayed)對(duì)于任意一位顧客,他在店里逗留的時(shí)間=排隊(duì)時(shí)間+理發(fā)時(shí)間。area_num_in_q統(tǒng)計(jì)的是隊(duì)列中的顧客等待的總時(shí)間,而area_server_status統(tǒng)計(jì)的是所有顧客理發(fā)的總時(shí)間,相加就是所有顧客在店里逗留的時(shí)間,除以顧客的人數(shù),就是顧客平均逗留時(shí)間。⑥顧客必須在店內(nèi)消耗15分鐘以上的概率。p6=1.0*count15/num_custs_delayed增加變量count15,用于統(tǒng)計(jì)在店內(nèi)消耗15分鐘以上的顧客人數(shù),再增加變量single_cust_time,用于統(tǒng)計(jì)單個(gè)顧客在店內(nèi)消耗的時(shí)間。這里有兩種情況。(1)不用排隊(duì)。那么該顧客在店里消耗的時(shí)間就是理發(fā)時(shí)間,即single_cust_time=time_next_event[2]-sim_time。time_next_event[2]=sim_time+expon(mean_service)。(2)要排隊(duì)。那么single_cust_time=delay+time_next_event[2]-sim_time。delay是當(dāng)前有一位顧客離開時(shí),得到的下一位將要理發(fā)的顧客(即隊(duì)首顧客)的等待時(shí)間。每一位顧客到店里時(shí)都會(huì)有一個(gè)time_arrival[]將其抵達(dá)時(shí)刻記錄下來,因此,輪到他時(shí),用sim_time減去time_arrival[]就得到了他等待的時(shí)間。等待時(shí)間加上理發(fā)時(shí)間,就是這位顧客在店里消耗的時(shí)間。以上可計(jì)算出單個(gè)顧客在店里消耗的時(shí)間,與15分鐘比較,若超過,加入count15中,count15除以總?cè)藬?shù),就是所求概率。對(duì)原程序的修改點(diǎn):去掉了文件操作,用提示輸入的方式輸入?yún)?shù),可多次輸入。增加變量count15,Three_people_time,idle_time,single_cust_time。作用見上面六小題具體算法。代碼:#include<stdio.h>#include<math.h>#include<stdlib.h>/*#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,count15;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,Three_people_time,idle_time,single_cust_time,time_since_last_event;/*Thefollowing3declarationsareforuseoftherandom-numbergeneratorlcgrandandtheassociatedfunctionslcgrandstandlcgrandgtforseedmanagement.Thisfile(namedlcgrand.h)shouldbeincludedinanyprogramusingthesefunctionsbyexecuting#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);intmain()/*Mainfunction.*/{/*Specifythenumberofeventsforthetimingfunction.*/charchoice;num_events=2;while(1){printf("Starttosimulate?(Y/N)");getchar();scanf("%c",&choice);if(choice=='N')exit(0);printf("\n\nPleaseentertheinterarrivaltime(min):");scanf("%f",&mean_interarrival);printf("\nPleaseentertheservingtime(min):");scanf("%f",&mean_service);printf("\nPleaseenterthenumberofcustomer:");scanf("%d",&num_delays_required);/*Initializethesimulation.*/initialize();/*Runthesimulationwhilemoredelaysarestillneeded.*/while(num_custs_delayed<num_delays_required){/*Determinethenextevent.*/timing();/*Updatetime-averagestatisticalaccumulators.*/update_time_avg_stats();/*Invoketheappropriateeventfunction.*/switch(next_event_type){case1:arrive();break;case2:depart();break;}}/*Invokethereportgeneratorandendthesimulation.*/report();}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;//InitializethevariablesIaddedThree_people_time=0.0;idle_time=0.0;count15=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){min_time_next_event=time_next_event[i];next_event_type=i;}/*Checktoseewhethertheeventlistisempty.*/if(next_event_type==0){/*Theeventlistisempty,sostopthesimulation.*/printf("\nEventlistemptyattime%f",sim_time);exit(0);}/*Theeventlistisnotempty,soadvancethesimulationclock.*/sim_time=min_time_next_event;}voidarrive(void)/*Arrivaleventfunction.*/{floatdelay;/*Schedulenextarrival.*/time_next_event[1]=sim_time+expon(mean_interarrival);//computewhenthenextpeoplearrive/*Checktoseewhetherserverisbusy.*/if(server_status==BUSY){/*Serverisbusy,soincrementnumberofcustomersinqueue.*/++num_in_q;/*Checktoseewhetheranoverflowconditionexists.*/if(num_in_q>Q_LIMIT){/*Thequeuehasoverflowed,sostopthesimulation.*/printf("\nOverflowofthearraytime_arrivalat");printf("time%f",sim_time);exit(2);}/*Thereisstillroominthequeue,sostorethetimeofarrivalofthearrivingcustomeratthe(new)endoftime_arrival.*/time_arrival[num_in_q]=sim_time;//recordthetimewhenthispersonarrived}else{/*Serverisidle,soarrivingcustomerhasadelayofzero.(Thefollowingtwostatementsareforprogramclarityanddonotaffecttheresultsofthesimulation.)*/delay=0.0;//noneedtowaittotal_of_delays+=delay;idle_time+=time_since_last_event;/*Incrementthenumberofcustomersdelayed,andmakeserverbusy.*/++num_custs_delayed;server_status=BUSY;/*Scheduleadeparture(servicecompletion).*/time_next_event[2]=sim_time+expon(mean_service);//computetheservetimeofthisperson(toknowwhenhewillleave)single_cust_time=time_next_event[2]-sim_time;if(single_cust_time>=15)count15++;}}voiddepart(void)/*Departureeventfunction.*/{inti;floatdelay;/*Checktoseewhetherthequeueisempty.*/if(num_in_q==0){/*Thequeueisemptysomaketheserveridleandeliminatethedeparture(servicecompletion)eventfromconsideration.*/server_status=IDLE;time_next_event[2]=1.0e+30;}else{/*Thequeueisnonempty,sodecrementthenumberofcustomersinqueue.*/--num_in_q;/*Computethedelayofthecustomerwhoisbeginningserviceandupdatethetotaldelayaccumulator.*/delay=sim_time-time_arrival[1];//howlongdoesthispersonwaitinthequeuetotal_of_delays+=delay;//thetotalwaiting-timeofpeopleinthequeue/*Incrementthenumberofcustomersdelayed,andscheduledeparture.*/++num_custs_delayed;time_next_event[2]=sim_time+expon(mean_service);//computetheservetimeofthispersonsingle_cust_time=delay+time_next_event[2]-sim_time;if(single_cust_time>=15)count15++;/*Moveeachcustomerinqueue(ifany)uponeplace.*/for(i=1;i<=num_in_q;++i)time_arrival[i]=time_arrival[i+1];//FIFO,afterthefirstperson'sdeparture,thequeuemoves.}}voidreport(void)/*Reportgeneratorfunction.*/{/*Computeandwriteestimatesofdesiredmeasuresofperformance.*/floatp1,p2,p3,p6,mean_customer,mean_stay_time;p1=1-area_server_status/sim_time;p2=Three_people_time/sim_time;p3=1-idle_time/sim_time;mean_customer=1.0*num_custs_delayed/sim_time;mean_stay_time=(area_num_in_q+area_server_status)/(1.0*num_custs_delayed);p6=1.0*count15/num_custs_delayed;printf("\n\nSingle-serverqueueingsystem\n\n");printf("Meaninterarrivaltime%11.3fminutes\n\n",mean_interarrival);printf("Meanservicetime%16.3fminutes\n\n",mean_service);printf("Numberofcustomers%14d\n\n",num_delays_required);printf("Hereisthereport:\n");printf("\n\n修理店空閑的概率為:%11.3f\n\n",p1);printf("\n\n店內(nèi)有三個(gè)顧客的概率為:%11.3f\n\n",p2);printf("\n\n店內(nèi)至少有一個(gè)顧客的概率為:%11.3f\n\n",p3);printf("\n\n在店內(nèi)顧客的平均數(shù)為%11.3f人每分鐘\n\n",mean_customer);printf("\n\n顧客在店內(nèi)的平均逗留時(shí)間為%11.3f分鐘\n\n",mean_stay_time);printf("\n\n顧客必須在店內(nèi)消耗15分鐘以上的概率為:%11.3f\n\n",p6);printf("Timesimulationended%12.3fminutes\n\n",sim_time);}voidupdate_time_avg_stats(void)/*Updateareaaccumulatorsfortime-averagestatistics.*/{/*Computetimesincelastevent,andupdatelast-event-timemarker.*/time_since_last_event=sim_time-time_last_event;//howmuchtimepastfromthelastevent(arriveordeparture)time_last_event=sim_time;//recordthemomentoflasteventif(num_in_q==2)Three_people_time+=time_since_last_event;/*Updateareaundernumber-in-queuefunction.*/area_num_in_q+=num_in_q*time_since_last_event;//countthetotalwaiting-timeofpeopleinthequeue/*Updateareaunderserver-busyindicatorfunction.*/area_server_status+=server_status*time_since_last_event;//countthetotalserving-time}floatexpon(floatmean)/*Exponentialvariategenerationfunction.*/{/*Returnanexponentialrandomvariatewithmean"mean".*/return-mean*log(lcgrand(3));}/*PrimemodulusmultiplicativelinearcongruentialgeneratorZ[i]=(630360016*Z[i-1])(mod(pow(2,31)-1)),basedonMarseandRoberts'portableFORTRANrandom-numbergeneratorUNIRAN.Multiple(100)streamsaresupported,withseedsspaced100,000apart.Throughout,inputargument"stream"mustbeanintgivingthedesiredstreamnumber.Theheaderfilelcgrand.hmustbeincludedinthecallingprogram(#include"lcgrand.h")beforeusingthesefunctions.Usage:(Threefunctions)1.ToobtainthenextU(0,1)randomnumberfromstream"stream,"executeu=lcgrand(stream);wherelcgrandisafloatfunction.Thefloatvariableuwillcontainthenextrandomnumber.2.Tosettheseedforstream"stream"toadesiredvaluezset,executelcgrandst(zset,stream);wherelcgrandstisavoidfunctionandzsetmustbealongsettothedesiredseed,anumberbetween1and2147483646(inclusive).Defaultseedsforall100streamsaregiveninthecode.3.Togetthecurrent(mostrecentlyused)integerinthesequencebeinggeneratedforstream"stream"intothelongvariablezget,executezget=lcgrandgt(stream);wherelcgrandgtisalongfunction.*//*Definetheconstants.*/#defineMODLUS2147483647#defineMULT124112#defineMULT226143/*Setthedefaultseedsforall100streams.*/staticlongzrng[]={1,1973272912,281629770,20006270,1280689831,2096730329,1933576050,913566091,246780520,1363774876,604901985,1511192140,1259851944,824064364,150493284,242708531,75253171,1964472944,1202299975,233217322,1911216000,726370533,403498145,993232223,1103205531,762430696,1922803170,1385516923,76271663,413682397,726466604,336157058,1432650381,1120463904,595778810,877722890,1046574445,68911991,2088367019,748545416,622401386,2122378830,640690903,1774806513,2132545692,2079249579,78130110,852776735,1187867272,1351423507,164597308
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026廣東深圳市龍崗中心醫(yī)院招聘勞務(wù)派遣人員55人筆試參考題庫(kù)及答案解析
- 2026云南昆明高新區(qū)第二幼兒園招聘6人筆試備考試題及答案解析
- 技術(shù)服務(wù)響應(yīng)時(shí)間承諾保證承諾書4篇
- 2026年度許昌煙草機(jī)械有限責(zé)任公司招聘人員38人筆試模擬試題及答案解析
- 2026內(nèi)蒙古錫林郭勒盟蘇尼特左旗招聘醫(yī)療衛(wèi)生專業(yè)技術(shù)人員8人筆試備考題庫(kù)及答案解析
- 2026云南省玉溪實(shí)驗(yàn)中學(xué)教師招聘18人筆試備考試題及答案解析
- 2026年湖南湘潭市公安局招聘30名留置看護(hù)巡邏警務(wù)輔助人員考試備考題庫(kù)及答案解析
- 2026江西興宜全過程項(xiàng)目咨詢有限公司招聘1人考試備考題庫(kù)及答案解析
- 2026四川巴中市第一批就業(yè)見習(xí)崗位140人筆試備考試題及答案解析
- 2026河南國(guó)控集團(tuán)社會(huì)招聘3人筆試模擬試題及答案解析
- 光纖激光打標(biāo)機(jī)說明書
- 勞動(dòng)者個(gè)人職業(yè)健康監(jiān)護(hù)檔案
- 《兩角和與差的正弦、余弦、正切公式》示范公開課教學(xué)PPT課件【高中數(shù)學(xué)人教版】
- 治理現(xiàn)代化下的高校合同管理
- 境外宗教滲透與云南邊疆民族地區(qū)意識(shí)形態(tài)安全研究
- GB/T 28920-2012教學(xué)實(shí)驗(yàn)用危險(xiǎn)固體、液體的使用與保管
- GB/T 26389-2011衡器產(chǎn)品型號(hào)編制方法
- GB/T 16588-2009帶傳動(dòng)工業(yè)用多楔帶與帶輪PH、PJ、PK、PL和PM型:尺寸
- 人大企業(yè)經(jīng)濟(jì)學(xué)考研真題-802經(jīng)濟(jì)學(xué)綜合歷年真題重點(diǎn)
- 建筑抗震鑒定標(biāo)準(zhǔn)課件
- 人教版二年級(jí)數(shù)學(xué)下冊(cè)《【全冊(cè)】完整版》優(yōu)質(zhì)課件
評(píng)論
0/150
提交評(píng)論