1、修理店仿真报告修理店仿真报告一、实验内容和目的1、应用排队系统流程图,用C语言编制仿真程序,求解以下问题。 修理店只有一个修理工,来修理的顾客到达次数服从泊松分布,平均4人/h;修理时间服从指数分布,平均需6min。试求(随机数发生器采用float lcgrand(int stream) ,种子stream 为自己学号的最后两位。): 修理店空闲的概率; 店内有三个顾客的概率; 店内至少有一个顾客的概率; 在店内顾客的平均数; 顾客在店内的平均逗留时间; 顾客必须在店内消耗15分钟以上的概率。2、 将到达时间间隔和平均修理时间按如下要求修改后运行程序,给出运行结果。(1)平均到达时间间隔 10
2、学号的最后一位(2)平均修理时间 INT(平均到达时间间隔/3)二、程序清单/* 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 length. */#define BUSY 1 /* Mnemonics for servers being busy */#define IDLE 0 /*
3、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;float a19, total_of_server, are
4、a_3_in_q, abv_1,area_num_in_h;FILE *infile, *outfile;/* The following 3 declarations are for use of the random-number generator lcgrand and the associated functions lcgrandst and lcgrandgt for seed management. This file (named lcgrand.h) should be included in any program using these functions by exe
5、cuting #include lcgrand.h before referencing the functions. */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 me
6、an);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_
7、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, n
8、um_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(); /* Inv
9、oke 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;void initialize(void) /* Initialization function. */ /* Initialize the simul
10、ation 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;area_3_in_q = 0.0;abv_1 = 0.0;area_nu
11、m_in_h = 0.0;total_of_server = 0.0;a19 = 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;void timing(void) /* Timing functio
12、n. */ 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
13、 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 st
14、atements 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_eve
15、nt2 = sim_time + expon(mean_service); total_of_server += time_next_event2-sim_time;if(time_next_event2-sim_time)19)a19+; 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 idl
16、e 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 t
17、otal 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); total_of_server += time_next_event2-sim_time;if(delay+time_next_event
18、2-sim_time)19)a19+; /* Move each customer in queue (if any) up one place. */ for (i = 1; i 0) abv_1 += 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
19、) /* Exponential variate generation function. */ /* Return an exponential random variate with mean mean. */ return -mean * log(lcgrand(29);/* Prime modulus multiplicative linear congruential generator Zi = (630360016 * Zi-1) (mod(pow(2,31) - 1), based on Marse and Roberts portable FORTRAN random-num
20、ber generator UNIRAN. Multiple (100) streams are supported, with seeds spaced 100,000 apart. Throughout, input argument stream must be an int giving the desired stream number. The header file lcgrand.h must be included in the calling program (#include lcgrand.h) before using these functions. Usage:
21、(Three functions) 1. To obtain the next U(0,1) random number from stream stream, execute u = lcgrand(stream); where lcgrand is a float function. The float variable u will contain the next random number. 2. To set the seed for stream stream to a desired value zset, execute lcgrandst(zset, stream); wh
22、ere lcgrandst is a void function and zset must be a long set to the desired seed, a number between 1 and 2147483646 (inclusive). Default seeds for all 100 streams are given in the code. 3. To get the current (most recently used) integer in the sequence being generated for stream stream into the long variable zget, execute zget = lcgrandgt(stream); where lcgrandgt is a long function. */* Define the constants. */#define MODLUS 2147483647#define MULT1 24112#define MULT2 26143/* Set the def
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1