排队系统仿真 包含C.doc_第1页
排队系统仿真 包含C.doc_第2页
排队系统仿真 包含C.doc_第3页
排队系统仿真 包含C.doc_第4页
排队系统仿真 包含C.doc_第5页
已阅读5页,还剩5页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

排队系统仿真实验1. 实验目的离散事件系统大量存在于现实生活中。离散事件系统往往是随机的,具有复杂的变化关系,难以用常规的微分方程、差分方程等模型来描述,计算机仿真技术是解决这类问题的有效手段。排队系统是一种非常重要的离散事件系统,也是最早研究的离散事件系统。本实验通过设计一种最简单的单服务台排队系统仿真程序,深入理解排队系统的建模与仿真方法,掌握排队系统仿真的基本步骤和程序设计技术,了解离散事件系统仿真的一般原理。2. 排队系统仿真程序功能模拟一个单服务台单队列排队系统的运行过程,完成一定数量活动实体的服务过程,输出排队系统的常用统计指标。仿真运行时间(可由活动实体数确定)、活动实体到达平均时间间隔、平均服务时间作为参数在程序运行时输入。3. 关键技术(1)随机数发生器乘同余法递推公式:程序中采用:(2)随机变量的产生变换抽样法指数分布随机变量的产生:其中,为到达(或服务)速率,1/到达时间平均间隔(或平均服务时间),u为随机数。(3)排队、到达、服务模式排队规则:先到先服务(fifo);到达模式:泊松到达,即相邻两个顾客到达的时间间隔服从指数分布;服务模式:服务台为活动实体提供服务的时间是随机的,服从指数分布。(4)常用统计性能指标计算平均延误时间:其中,di为第i个活动实体在队列中耽误的时间。平均滞留时间:其中,wi为第i个活动实体在系统中滞留的时间,si为第i个活动实体接受服务台服务的时间。平均队长:其中,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 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 */#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_next_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. */ infile = 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_delays_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(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 statistical 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)初始化函数void initialize(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; 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)时间调度函数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_eventi 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. */ 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 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 = 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 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; time_next_event2 = sim_time + expon(mean_service);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论