排队系统仿真 包含C.doc

上传人:laozhun 文档编号:2385390 上传时间:2023-02-17 格式:DOC 页数:9 大小:239.50KB
返回 下载 相关 举报
排队系统仿真 包含C.doc_第1页
第1页 / 共9页
排队系统仿真 包含C.doc_第2页
第2页 / 共9页
排队系统仿真 包含C.doc_第3页
第3页 / 共9页
排队系统仿真 包含C.doc_第4页
第4页 / 共9页
排队系统仿真 包含C.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《排队系统仿真 包含C.doc》由会员分享,可在线阅读,更多相关《排队系统仿真 包含C.doc(9页珍藏版)》请在三一办公上搜索。

1、排队系统仿真实验1. 实验目的离散事件系统大量存在于现实生活中。离散事件系统往往是随机的,具有复杂的变化关系,难以用常规的微分方程、差分方程等模型来描述,计算机仿真技术是解决这类问题的有效手段。排队系统是一种非常重要的离散事件系统,也是最早研究的离散事件系统。本实验通过设计一种最简单的单服务台排队系统仿真程序,深入理解排队系统的建模与仿真方法,掌握排队系统仿真的基本步骤和程序设计技术,了解离散事件系统仿真的一般原理。2. 排队系统仿真程序功能模拟一个单服务台单队列排队系统的运行过程,完成一定数量活动实体的服务过程,输出排队系统的常用统计指标。仿真运行时间(可由活动实体数确定)、活动实体到达平均

2、时间间隔、平均服务时间作为参数在程序运行时输入。3. 关键技术(1)随机数发生器乘同余法递推公式:程序中采用:(2)随机变量的产生变换抽样法指数分布随机变量的产生:其中,为到达(或服务)速率,1/到达时间平均间隔(或平均服务时间),u为随机数。(3)排队、到达、服务模式排队规则:先到先服务(FIFO);到达模式:泊松到达,即相邻两个顾客到达的时间间隔服从指数分布;服务模式:服务台为活动实体提供服务的时间是随机的,服从指数分布。(4)常用统计性能指标计算平均延误时间:其中,Di为第i个活动实体在队列中耽误的时间。平均滞留时间:其中,Wi为第i个活动实体在系统中滞留的时间,Si为第i个活动实体接受

3、服务台服务的时间。平均队长:其中,Q(t)为t时刻系统中队列的长度。平均实体数:其中,L(t)为t时刻系统中的活动实体数,Q(t)为t时刻队列的长度,S(t)为t时刻接受服务台服务的活动实体数。4. 程序架构(1)基本模块void initialize(void); /*变量初始化*/void timing(void);/*时间调度*/void arrive(void);/*到达事件处理*/void depart(void);/*离开事件处理*/void report(void);/*统计量输出*/void update_time_avg_stats(void);/*统计量的更新*/float

4、 expon(float mean);/*指数分布随机变量的变换抽样法*/(2)程序流程(main()函数)(3)到达事件处理流程(arrive()函数)(4)离开事件处理流程(depart()函数)5. 程序设计(1)定义#include #include /*#include lcgrand.h Header file for random-number generator. */#define Q_LIMIT 100 /* Limit on queue length. */#define BUSY 1 /* Mnemonics for servers being busy */#defi

5、ne 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_next_event3, total_of_delays;FILE *infile, *out

6、file;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. */ infile = fopen(mm1.in, r); outfile = fopen(mm1.ou

7、t, 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_delays_required); /* Write report heading and input parameters. */ fprintf(outfile, Single-server queueing systemnn); fprin

8、tf(outfile, Mean interarrival time%11.3f minutesnn, mean_interarrival); fprintf(outfile, Mean service time%16.3f minutesnn, mean_service); fprintf(outfile, Number of customers%14dnn, num_delays_required); /* Initialize the simulation. */ initialize(); /* Run the simulation while more delays are stil

9、l needed. */ while (num_custs_delayed num_delays_required) /* Determine the next event. */ timing(); /* Update time-average statistical accumulators. */ update_time_avg_stats(); /* Invoke the appropriate event function. */ switch (next_event_type) case 1: arrive(); break; case 2: depart(); break; /*

10、 Invoke the report generator and end the simulation. */ report(); fclose(infile); fclose(outfile); return 0;(3)初始化函数void initialize(void) /* Initialization function. */ /* Initialize the simulation clock. */ sim_time = 0.0; /* Initialize the state variables. */ server_status = IDLE; num_in_q = 0; ti

11、me_last_event = 0.0; /* Initialize the statistical counters. */ num_custs_delayed = 0; total_of_delays = 0.0; area_num_in_q = 0.0; area_server_status = 0.0; /* Initialize event list. Since no customers are present, the departure (service completion) event is eliminated from consideration. */ time_ne

12、xt_event1 = sim_time + expon(mean_interarrival); time_next_event2 = 1.0e+30;(4)时间调度函数void timing(void) /* Timing function. */ int 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_even

13、ti 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 of arrival of the arriving customer at the (new) end of time_arrival. */

14、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_of_delays += delay; /* Increment the number of customers delayed, and make

15、server busy. */ +num_custs_delayed; server_status = BUSY; /* Schedule a departure (service completion). */ time_next_event2 = sim_time + expon(mean_service); (6)离开事件处理函数void depart(void) /* Departure event function. */ int i; float delay; /* Check to see whether the queue is empty. */ if (num_in_q =

16、 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 number of customers in queue. */ -num_in_q; /* Compute the delay of the cu

17、stomer 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; time_next_event2 = sim_time + expon(mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i 16) * MULT1 + (lowprd 16); zi = (lowprd & 65535) - MODLUS) + (hi31 & 32767) 15); if (zi 16) * MULT2 + (lowprd 16); zi = (lowprd & 65535) - MODLUS) +(hi31 & 32767) 15); if (zi 7 | 1) / 16777216.0;

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

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号