/* External definitions for single-server queueing system. */ #include #include #include #include using std::cout; using std::endl; #define Q_LIMIT 100 /* Limit on queue length. */ #define BUSY 1 /* 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_arrival[Q_LIMIT + 1], time_last_event, time_next_event[3], total_of_delays; FILE *infile, *outfile; 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); float lcgrand(int stream); void lcgrandst(long zset, int stream); long lcgrandgt(int stream); main() /* Main function. */ { /* Specify the number of events for the timing function. */ num_events = 2; // instead of reading input parameters, these were inlined mean_interarrival=1.0; cout <<"mean_interarrivsl "< 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_arrival[num_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_event[2] = sim_time + expon(mean_service); } } 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_event[2] = 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_arrival[1]; total_of_delays += delay; /* Increment the number of customers delayed, and schedule departure. */ ++num_custs_delayed; time_next_event[2] = sim_time + expon(mean_service); /* Move each customer in queue (if any) up one place. */ for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; } } void report(void) /* Report generator function. */ { /* Compute and write estimates of desired measures of performance. */ cout <<"average delay " <> 16) * MULT1 + (lowprd >> 16); zi = ((lowprd & 65535) - MODLUS) + ((hi31 & 32767) << 16) + (hi31 >> 15); if (zi < 0) zi += MODLUS; lowprd = (zi & 65535) * MULT2; hi31 = (zi >> 16) * MULT2 + (lowprd >> 16); zi = ((lowprd & 65535) - MODLUS) + ((hi31 & 32767) << 16) + (hi31 >> 15); if (zi < 0) zi += MODLUS; zrng[stream] = zi; return (zi >> 7 | 1) / 16777216.0; } void lcgrandst (long zset, int stream) /* Set the current zrng for stream "stream" to zset. */ { zrng[stream] = zset; } long lcgrandgt (int stream) /* Return the current zrng for stream "stream". */ { return zrng[stream]; }