




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、排隊系統(tǒng)仿真實驗1. 實驗?zāi)康碾x散事件系統(tǒng)大量存在于現(xiàn)實生活中。離散事件系統(tǒng)往往是隨機的,具有復(fù)雜的變化關(guān)系,難以用常規(guī)的微分方程、差分方程等模型來描述,計算機仿真技術(shù)是解決這類問題的有效手段。排隊系統(tǒng)是一種非常重要的離散事件系統(tǒng),也是最早研究的離散事件系統(tǒng)。本實驗通過設(shè)計一種最簡單的單服務(wù)臺排隊系統(tǒng)仿真程序,深入理解排隊系統(tǒng)的建模與仿真方法,掌握排隊系統(tǒng)仿真的基本步驟和程序設(shè)計技術(shù),了解離散事件系統(tǒng)仿真的一般原理。2. 排隊系統(tǒng)仿真程序功能模擬一個單服務(wù)臺單隊列排隊系統(tǒng)的運行過程,完成一定數(shù)量活動實體的服務(wù)過程,輸出排隊系統(tǒng)的常用統(tǒng)計指標(biāo)。仿真運行時間(可由活動實體數(shù)確定)、活動實體到達(dá)平均
2、時間間隔、平均服務(wù)時間作為參數(shù)在程序運行時輸入。3. 關(guān)鍵技術(shù)(1)隨機數(shù)發(fā)生器乘同余法遞推公式:程序中采用:(2)隨機變量的產(chǎn)生變換抽樣法指數(shù)分布隨機變量的產(chǎn)生:其中,為到達(dá)(或服務(wù))速率,1/到達(dá)時間平均間隔(或平均服務(wù)時間),u為隨機數(shù)。(3)排隊、到達(dá)、服務(wù)模式排隊規(guī)則:先到先服務(wù)(FIFO);到達(dá)模式:泊松到達(dá),即相鄰兩個顧客到達(dá)的時間間隔服從指數(shù)分布;服務(wù)模式:服務(wù)臺為活動實體提供服務(wù)的時間是隨機的,服從指數(shù)分布。(4)常用統(tǒng)計性能指標(biāo)計算平均延誤時間:其中,Di為第i個活動實體在隊列中耽誤的時間。平均滯留時間:其中,Wi為第i個活動實體在系統(tǒng)中滯留的時間,Si為第i個活動實體接受
3、服務(wù)臺服務(wù)的時間。平均隊長:其中,Q(t)為t時刻系統(tǒng)中隊列的長度。平均實體數(shù):其中,L(t)為t時刻系統(tǒng)中的活動實體數(shù),Q(t)為t時刻隊列的長度,S(t)為t時刻接受服務(wù)臺服務(wù)的活動實體數(shù)。4. 程序架構(gòu)(1)基本模塊void initialize(void); /*變量初始化*/void timing(void);/*時間調(diào)度*/void arrive(void);/*到達(dá)事件處理*/void depart(void);/*離開事件處理*/void report(void);/*統(tǒng)計量輸出*/void update_time_avg_stats(void);/*統(tǒng)計量的更新*/float
4、 expon(float mean);/*指數(shù)分布隨機變量的變換抽樣法*/(2)程序流程(main()函數(shù))(3)到達(dá)事件處理流程(arrive()函數(shù))(4)離開事件處理流程(depart()函數(shù))5. 程序設(shè)計(1)定義#include <stdio.h>#include <math.h>/*#include "lcgrand.h" Header file for random-number generator. */#define Q_LIMIT 100 /* Limit on queue length. */#define BUSY 1 /*
5、 Mnemonics for server's being busy */#define IDLE 0 /* and idle. */int next_event_type, num_custs_delayed, num_delays_required, num_events, num_in_q, server_status;float area_num_in_q, area_server_status, mean_interarrival, mean_service, sim_time, time_arrivalQ_LIMIT + 1, time_last_event, time_n
6、ext_event3, total_of_delays;FILE *infile, *outfile;float lcgrand(int stream);void initialize(void);void timing(void);void arrive(void);void depart(void);void report(void);void update_time_avg_stats(void);float expon(float mean);(2)主程序main() /* Main function. */ /* Open input and output files. */ inf
7、ile = fopen("mm1.in", "r"); outfile = fopen("mm1.out", "w"); /* Specify the number of events for the timing function. */ num_events = 2; /* Read input parameters. */ fscanf(infile, "%f %f %d", &mean_interarrival, &mean_service, &num_delay
8、s_required); /* Write report heading and input parameters. */ fprintf(outfile, "Single-server queueing systemnn"); fprintf(outfile, "Mean interarrival time%11.3f minutesnn", mean_interarrival); fprintf(outfile, "Mean service time%16.3f minutesnn", mean_service); fprintf
9、(outfile, "Number of customers%14dnn", num_delays_required); /* Initialize the simulation. */ initialize(); /* Run the simulation while more delays are still needed. */ while (num_custs_delayed < num_delays_required) /* Determine the next event. */ timing(); /* Update time-average stati
10、stical accumulators. */ update_time_avg_stats(); /* Invoke the appropriate event function. */ switch (next_event_type) case 1: arrive(); break; case 2: depart(); break; /* Invoke the report generator and end the simulation. */ report(); fclose(infile); fclose(outfile); return 0;(3)初始化函數(shù)void initiali
11、ze(void) /* Initialization function. */ /* Initialize the simulation clock. */ sim_time = 0.0; /* Initialize the state variables. */ server_status = IDLE; num_in_q = 0; time_last_event = 0.0; /* Initialize the statistical counters. */ num_custs_delayed = 0; total_of_delays = 0.0; area_num_in_q = 0.0
12、; area_server_status = 0.0; /* Initialize event list. Since no customers are present, the departure (service completion) event is eliminated from consideration. */ time_next_event1 = sim_time + expon(mean_interarrival); time_next_event2 = 1.0e+30;(4)時間調(diào)度函數(shù)void timing(void) /* Timing function. */ int
13、 i; float min_time_next_event = 1.0e+29; next_event_type = 0; /* Determine the event type of the next event to occur. */ for (i = 1; i <= num_events; +i) if (time_next_eventi < min_time_next_event) min_time_next_event = time_next_eventi; next_event_type = i; /* Check to see whether the event l
14、ist is empty. */ if (next_event_type = 0) /* The event list is empty, so stop the simulation. */ fprintf(outfile, "nEvent list empty at time %f", sim_time); exit(1); /* The event list is not empty, so advance the simulation clock. */ sim_time = min_time_next_event;(5)到達(dá)事件處理函數(shù)void arrive(vo
15、id) /* Arrival event function. */ float delay; /* Schedule next arrival. */ time_next_event1 = sim_time + expon(mean_interarrival); /* Check to see whether server is busy. */ if (server_status = BUSY) /* Server is busy, so increment number of customers in queue. */ +num_in_q; /* Check to see whether
16、 an overflow condition exists. */ if (num_in_q > Q_LIMIT) /* The queue has overflowed, so stop the simulation. */ fprintf(outfile, "nOverflow of the array time_arrival at"); fprintf(outfile, " time %f", sim_time); exit(2); /* There is still room in the queue, so store the time
17、 of arrival of the arriving customer at the (new) end of time_arrival. */ time_arrivalnum_in_q = sim_time; else /* Server is idle, so arriving customer has a delay of zero. (The following two statements are for program clarity and do not affect the results of the simulation.) */ delay = 0.0; total_o
18、f_delays += delay; /* Increment the number of customers delayed, and make server busy. */ +num_custs_delayed; server_status = BUSY; /* Schedule a departure (service completion). */ time_next_event2 = sim_time + expon(mean_service); (6)離開事件處理函數(shù)void depart(void) /* Departure event function. */ int i;
19、float delay; /* Check to see whether the queue is empty. */ if (num_in_q = 0) /* The queue is empty so make the server idle and eliminate the departure (service completion) event from consideration. */ server_status = IDLE; time_next_event2 = 1.0e+30; else /* The queue is nonempty, so decrement the
20、number of customers in queue. */ -num_in_q; /* Compute the delay of the customer who is beginning service and update the total delay accumulator. */ delay = sim_time - time_arrival1; total_of_delays += delay; /* Increment the number of customers delayed, and schedule departure. */ +num_custs_delayed
21、; time_next_event2 = sim_time + expon(mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i <= num_in_q; +i) time_arrivali = time_arrivali + 1; (7)輸出函數(shù)void report(void) /* Report generator function. */ /* Compute and write estimates of desired measures of performan
22、ce. */ fprintf(outfile, "nnAverage delay in queue%11.3f minutesnn", total_of_delays / num_custs_delayed); fprintf(outfile, "Average number in queue%10.3fnn", area_num_in_q / sim_time); fprintf(outfile, "Server utilization%15.3fnn", area_server_status / sim_time); fprint
23、f(outfile, "Time simulation ended%12.3f minutes", sim_time);(8)統(tǒng)計量更新函數(shù)void update_time_avg_stats(void) /* Update area accumulators for time-average statistics. */ float time_since_last_event; /* Compute time since last event, and update last-event-time marker. */ time_since_last_event = si
24、m_time - time_last_event; time_last_event = sim_time; /* Update area under number-in-queue function. */ area_num_in_q += num_in_q * time_since_last_event; /* Update area under server-busy indicator function. */ area_server_status += server_status * time_since_last_event;(9)隨機數(shù)及隨機變量產(chǎn)生函數(shù)float expon(fl
25、oat mean) /* Exponential variate generation function. */ /* Return an exponential random variate with mean "mean". */ return -mean * log(lcgrand(1);#define MODLUS 2147483647#define MULT1 24112#define MULT2 26143/* Set the default seeds for all 100 streams. */static long zrng = 1, 197327291
26、2, 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, 413
27、682397, 726466604, 336157058,1432650381,1120463904, 595778810, 877722890,1046574445, 68911991,2088367019, 748545416, 622401386,2122378830, 640690903, 1774806513,2132545692,2079249579, 78130110, 852776735,1187867272, 1351423507,1645973084,1997049139, 922510944,2045512870, 898585771, 243649545,1004818771, 773686062, 403188473, 372279877,1901633463, 498067494,2087759558, 493157915, 597104727,1530940798,1814496276, 536444882,1663153658, 855503735, 67784357,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 康復(fù)輔具的跨國合作與市場準(zhǔn)入考核試卷
- 木材切割精度控制技術(shù)考核試卷
- 停車設(shè)備行業(yè)營銷策略與渠道建設(shè)考核試卷
- 圖書、報刊行業(yè)風(fēng)險管理考核試卷
- 電工培訓(xùn)課件
- 再生物資回收在氣候變化適應(yīng)策略中的應(yīng)用考核試卷
- 家居紡織品的文化與藝術(shù)欣賞考核試卷
- 土地利用規(guī)劃中的鄉(xiāng)村景觀規(guī)劃考核試卷
- 快遞商鋪轉(zhuǎn)讓合同范本
- 采購合作合同范本
- 2023年新改版教科版五年級下冊科學(xué)全冊教案(附知識點)
- 固定式塔式起重機基礎(chǔ)設(shè)計及計算
- 奶牛性控凍精的使用細(xì)則:張相文 整理
- GB/T 34376-2017數(shù)控板料折彎機技術(shù)條件
- GB/T 22492-2008大豆肽粉
- 三年級下冊豎式脫式計算
- 《財務(wù)風(fēng)險的識別與評估管理國內(nèi)外文獻(xiàn)綜述》
- ??谑写媪糠抠I賣合同模板(范本)
- 經(jīng)典文學(xué)作品中的女性形象研究外文文獻(xiàn)翻譯2016年
- 高爐煤氣安全知識的培訓(xùn)
- 2008 年全國高校俄語專業(yè)四級水平測試試卷
評論
0/150
提交評論