排队论经典程序MM1代码_第1页
排队论经典程序MM1代码_第2页
排队论经典程序MM1代码_第3页
排队论经典程序MM1代码_第4页
排队论经典程序MM1代码_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

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

文档简介

1、修理店仿真报告一.问题:修理店空闲的概率;店内有三个顾客的概率;店内至少有一个顾客的概率;在店内顾客的平均数;顾客在店内的平均逗留时间;顾客必须在店内消耗15分钟以上的概率。二.求解问题的方法:修理店空闲的概率:(sim_time-area_server_status) / sim_time);店内有三个顾客的概率:area_3_in_q/sim_time);店内至少有一个顾客的概率:abv_1/sim_time);在店内顾客的平均数:area_num_in_h/sim_time);顾客在店内的平均逗留时间:(total_of_delays+total_of_server)/ num_cust

2、s_delayed );顾客必须在店内消耗15分钟以上概率:abv_15/num_custs_delayed);三。求解过程中计算统计量的方法: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 = BUSY)服务台忙,则店内至少有一个顾客abv_1 += time_s

3、ince_last_event;在店内顾客的平均数if(server_status = BUSY)服务台忙,总的顾客数为排队顾客数加一area_num_in_h += (num_in_q+1) * time_since_last_event;total_of_server += time_next_event2-sim_time;总的服务时间加一个服务时间为新的服务总时间delay = sim_time - time_arrival1; 排队时间=当前时间-这个人来的时间total_of_delays += delay;离开时总的消耗时间大于15,必须在店内消耗15分钟以上的顾客数加一if(d

4、elay+time_next_event2-sim_time)15)abv_15+;到达时总的服务时间大于15,必须在店内消耗15分钟以上的顾客数加一if(time_next_event2-sim_time)15)abv_15+;程序代码:/* External definitions for single-server queueing system. */#include #include /*#include lcgrand.h Header file for random-number generator. */#define Q_LIMIT 100 /* Limit on queue

5、 length.队伍最长 100 人 */#define BUSY 1 /* Mnemonics for servers being busy 忙碌状态*/#define IDLE 0 /* and idle.空闲状态 */intnext_event_type, /F一个事件类型num_custs_delayed, /E 模拟的顾客数 num_delays_required, /模拟的顾客数 num_events,停件数num_in_q, 队列中的顾客数server_status;/ 艮务状态float area_num_in_q,侑顾客的时间area_server_status,总的 服务时

6、间mean_interarrival,/平均顾客到达时间间隔mean_service,/平均服务时间sim_time, 模拟时间time_arrivalQ_LIMIT + 1, / 到来的时间time_last_event, /_匕个事件的时间time_next_event3,/下一个事件的时间total_of_delays;/总的排队时间/添加的变量float abv_15,total_of_server, area_3_in_q,abv_1,area_num_in_h;/15分钟以上的顾客数量所有顾客的总的服务时间有3个顾客的时间至少有一个顾客的时间顾客总数/FILE *infile, *

7、outfile;/* The following 3 declarations are for use of the random-number generatorlcgrand and the associated functions lcgrandst and lcgrandgt for seedmanagement. This file (named lcgrand.h) should be included in anyprogramusing these functions by executing#include legrand.hbefore referencing the fu

8、nctions. */float lcgrand(int stream);void lcgrandst(long zset, int stream);long lcgrandgt(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);main() /* Main function. */* Open input and out

9、put 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 parameter

10、s.输出 */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.初始化仿真 *

11、/initialize。;/ 初始化/* Run the simulation while more delays are still needed 没月艮务完, 仿真继续*/while (num_custs_delayed num_delays_required) 当 已月艮务顾 客数小于1000时/* Determine the next event.确定下一事件 */timing();/* Update time-average statistical accumulators.时间记录更新*/update_time_avg_stats();/* Invoke the appropria

12、te event function.根据事件的不同, 调 用不同的函数*/switch (next_event_type) arrive();/至 U 达break;depart();/离开break;/* Invoke the report generator and end the simulation. */report();fclose(infile);fclose(outfile);return 0;void initialize(void) /* Initialization function. */* Initialize the simulation clock.仿真时间置为

13、0*/sim_time = 0.0;/* Initialize the state variables.最开始状态初始化 */server_status = IDLE;/ 服务空闲num_in_q= 0;队伍里无人排队time_last_event = 0.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.

14、0;恿的服务时间/添加的变量的初始化area_3_in_q = 0.0;/有3个顾客的时间abv_1= 0.0;/有顾客的时间area_num_in_h = 0.0;/顾客的总数total_of_server = 0.0;/所有顾客的所有的服务的时间abv_15= 0.0;/消耗15分钟以上的顾客数/* Initialize event list. 初始化事件列表 Since no customers are present, the departure(service completion) event is eliminated from consideration. 无 顾客存在和离开*

15、/time_next_event1 = sim_time + expon(mean_interarrival);/下 事件是来的时间time_next_event2 = 1.0e+30;/下一事件是离开的时间 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.接下来将要发生的事件的类型*

16、/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 ofthearriving cu

17、stomer at the (new) end of time_arrival. 队歹!J中仍有空间时,记录新到达的时间*/time_arrivalnum_in_q = sim_time;在这个时间的时候有这 么多的排队人数,用于计算3顾客的问题else 服务空闲的状况/* Server is idle, so arriving customer has a delay of zero.(Thefollowing two statements are for program clarity and do not affectthe results of the simulation.) */d

18、elay= 0.0;total_of_delays += delay;总的排队时间/* Increment the number of customers delayed, and make server busy. */+num_custs_delayed;已经模拟的顾客数加1server_status = BUSY;人到来,服务开始/* Schedule a departure (service completion).月艮务完成 */ time_next_event2 = sim_time + expon(mean_service);/这个人离开的时间为现在时间+服务时间/总的服务时间加

19、上当前服务时间,更新总的服务时间total_of_server += time_next_event2-sim_time;总的服务时间加一个服务时间为新的服务总时间总的服务时间大于15,必须在店内消耗15分钟以上的顾客数加一if(time_next_event2-sim_time)15)/ 如果这个人服务时间超过15分钟则耗费15分钟人数加1abv_15+;/void depart(void) /* Departure event function. 讨论离开事件 */int i;float delay;/* Check to see whether the queue is empty. 测

20、队歹U是否为空 */if (num_in_q = 0) /* The queue is empty so make the server idle and eliminate thedeparture (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 inqueue.有人离开,队列

21、人数减少*/-num_in_q;/* Compute the delay of the customer who is beginning service and updatethe total delay accumulator. */delay= sim_time - time_arrival1; 排队时间二当前时间-这个人来的时间total_of_delays += delay;/* Increment the number of customers delayed, and schedule departure已经月艮务人数+1 */+num_custs_delayed;月艮务人数加1

22、time_next_event2 = sim_time + expon(mean_service);/尚前接受服务的人的离开时间/总的服务时间加上当前服务时间,更新总的服务时间total_of_server += time_next_event2-sim_time;总的消耗时间大于15,必须在店内消耗15分钟以上的顾客数加一if(delay+time_next_event2-sim_time)15)abv_15+;/* Move each customer in queue (if any) up one place.有人离开,队列前移*/for (i = 1; i 0)/ abv_1 +=

23、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;/float expon(float mean) /* Exponential variate generation function. */* Return

24、 an exponential random variate with mean mean. */return -mean * log(lcgrand(10);/自己学号的后两位/* Prime modulus multiplicative linear congruential generatorZi = (630360016 * Zi-1) (mod(pow(2,31) - 1), based on Marse and Robertsportable FORTRAN random-number generator UNIRAN. Multiplestreams aresupported,

25、with seeds spaced 100,000 apart. Throughout, input argumentstream must be an int giving the desired stream number. The header filelcgrand.h must be included in the calling program (#include lcgrand.h)before using these functions.Usage: (Three functions)To obtain the next U(0,1) random number from st

26、ream stream, executeu = lcgrand(stream);where lcgrand is a float function. The float variable u will contain thenext random number.To set the seed for stream stream to a desired value zset, execute lcgrandst(zset, stream);where lcgrandst is a void function and zset must be a long set to thedesired s

27、eed, a number between 1 and 2147483646 (inclusive). Defaultseeds for all 100 streams are given in the code.To get the current (most recently used) integer in the sequence beinggenerated for stream stream into the long variable zget, execute zget = lcgrandgt(stream);where lcgrandgt is a long function

28、. */* Define the constants. */#define MODLUS 2147483647#define MULT1 24112#define MULT2 26143/* Set the default seeds for all 100 streams. */static long zrng=1,1973272912,281629770,20006270,1280689831,2096730329,1933576050,913566091,246780520,1363774876,604901985,1511192140,1259851944,824064364,1504

29、93284,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,1645973084,1997049139,922510944,2045512870,898585771,243649545,1004818771,773686062,4031

温馨提示

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

评论

0/150

提交评论