360 likes | 588 Views
Single Station Queuing System - The M/M/1 System-. Q36954485 王俊彥 http://myweb.ncku.edu.tw/~q3695448/article.htm. Outline. Kendall’s notation 5:00 Introduction M/M/1 system 10:00 Introduction Parameters setting Performance measures
E N D
Single Station Queuing System -The M/M/1 System- Q36954485 王俊彥 http://myweb.ncku.edu.tw/~q3695448/article.htm
Outline • Kendall’s notation 5:00 • Introduction • M/M/1 system 10:00 • Introduction • Parameters setting • Performance measures • Simulation modeling 15:00 • Intuitive explanation • C/C++ code • Result • References 5:00
Kendall’s notation (A/B/m/K – Z) servers Queueing discipline 1 Arrival process Departing jobs … m queue
Examples of Kendall’s notation • M / M / m / K -FCFS • This would describe a queueing system with an exponential distribution for the interarrival times of customers and the service times of customers, m servers, a maximum of K customers in the queueing system at once, and First-come-first-served for queueing discipline. • To practice : M/G/5/K-LCFS
Performance measure • A queueing model represents a dynamic system, the performance measures vary with time. • Normally, however, we are content with results in steady-state (statistical equilibrium). • All transient behavior has ended • The system has settled down • The values of the performance measures are independent of time
Performance measure (cont.) SYSTEM QUEUE SERVICE servers 1 Arrival process Departing jobs … m queue
M/M/1 performance measure • Recall that in this case, the arrival process is Poisson, the service times are exponentially distributed, and there is a single server. • The system can be modeled as a birth-death process with birth rate (arrival rate) λ and death rate (service rate) μ. • The birth-death process is in the CH.3 (eq. 3.12)
M/M/1 performance measure (cont.) p214 ρ=(1/2),把它看成進入率與輸出率都相同,卻有2個servers。所以有jobs在佇列的機會不高。 server比較閒, 在整個系統 排隊的人就少。 server比較忙, 在整個系統 排隊的人就多。
Our simulation • For expository convenience, we assume that interarrival and service time of customers are below : • A1=0.4 , A2=1.2 , A3=0.5 , A4=1.7 , A5=0.2 , A6=1.6 , A7=0.2 , A8=1.4 , A9=1.9 , …. • S1=2.0 , S2=0.7 , S3=0.2 , S4=1.1 , S5=3.7 , S6=0.6 , …. • Unit-less 0.4 1.2 0.5 1.7 0.2 1.6 Time (unit) 0 0.4 1.6 2.1 3.8 4.0 5.6
Exponential random variable int main( ) // Example in C { double u=0, r=0; int mean=2; srand(time(NULL)); u=(double)(1+rand()%100)/(double)100; r=-mean*log(u); printf("r=%2.2f\n", r); return 0; }
Q(t) and B(t) Q(t) 3 2 1 arrivals 0 0.4 1.6 2.1 2.4 3.1 3.3 3.8 4.0 4.9 5.6 5.8 7.2 8.6 departures 0 0.4 1.6 2.12.43.1 3.33.8 4.04.95.6 5.8 7.28.6 B(t) 1 0
Depart state Arrive state
System state Initialization Time=0 0 A D 0.4 ∞ 0 0 0 clock Event list 0 0 0 0 Server status Number in queue Time Of last event Time Of arrival Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=0 • t=0 : initialization • Our modeling assumption was initially the system is empty of customs and the server is idle (idle=0 & busy=1). And number of customs in queue is 0. • The event list give the times of next occurrence in A and departure time in D.
System state Initialization Time=0.4 0.4 A D 1.6 2.4 1 0 0.4 clock Event list 1 0 0 0 Server status Number in queue Time Of last event Time Of arrival Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=0.4 0.4 • Number delayed • Server status • Event list • □ • ○
System state Initialization Time=1.6 1.6 A D 2.1 1.6 2.4 0.4 1 1 1.6 clock Event list 1 0 0 1.2 Server status Number in queue Time Of last event Time Of arrival Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=1.6 1.6 • Area under B(t) • Number in queue • Time of arrival
System state Initialization Time=2.1 2.1 A D 3.8 1.6 2.4 2.1 0.4 1 2 2.1 clock Event list 1.6 1 0 0.5 1.7 Server status Number in queue Time Of last event Time Of arrival 2.1 Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=2.1 • Area under Q(t)
System state Initialization Time=2.4 2.4 A D 3.8 2.1 3.1 1 1 2.4 clock Event list 2 0.8 1.1 2.0 Server status Number in queue Time Of last event Time Of arrival Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=2.4 1.6 2.1 • Number delayed • Total delay
System state System state Initialization Time=3.1 Initialization Time=3.3 3.3 3.1 A D A D 0.4 3.8 ∞ 3.3 0 1 0 0 3.3 3.1 clock clock Event list Event list 3 3 1.8 1.8 1.8 1.8 2.7 2.9 Server status Server status Number in queue Number in queue Time Of last event Time Of last event Time Of arrival Time Of arrival Number delayed Number delayed Total delay Total delay Area Under Q(t) Area Under Q(t) Area Under B(t) Area Under B(t) Intuitive explanation : t=3.1 & t=3.3 2.1
System state System state Initialization Time=3.8 Initialization Time=4.0 3.8 4.0 A D A D 5.6 4.0 4.0 4.9 4.9 1 1 0 1 3.8 4.0 clock clock Event list Event list 4 4 1.8 1.8 1.8 1.8 3.1 2.9 Server status Server status Number in queue Number in queue Time Of last event Time Of last event Time Of arrival Time Of arrival Number delayed Number delayed Total delay Total delay Area Under Q(t) Area Under Q(t) Area Under B(t) Area Under B(t) Intuitive explanation : t=3.8 & t=4.0 3.8 3.8 4.0
System state System state Initialization Time=4.9 Initialization Time=5.6 4.9 5.6 A D A D 5.8 5.6 5.6 8.6 8.6 1 1 0 1 4.9 5.6 clock clock Event list Event list 5 5 2.7 2.7 2.7 2.7 4.7 4.0 Server status Server status Number in queue Number in queue Time Of last event Time Of last event Time Of arrival Time Of arrival Number delayed Number delayed Total delay Total delay Area Under Q(t) Area Under Q(t) Area Under B(t) Area Under B(t) Intuitive explanation : t=4.9 & t=5.6 4.0 4.0 5.6
System state System state Initialization Time=5.8 Initialization Time=7.2 7.2 5.8 A D A D 9.1 7.2 5.6 5.6 8.6 8.6 5.8 5.8 1 1 2 3 7.2 5.8 clock clock Event list Event list 7.2 5 5 2.7 2.7 2.9 5.7 6.3 4.9 Server status Server status Number in queue Number in queue Time Of last event Time Of last event Time Of arrival Time Of arrival Number delayed Number delayed Total delay Total delay Area Under Q(t) Area Under Q(t) Area Under B(t) Area Under B(t) Intuitive explanation : t=5.8 & t=7.2 4.0 5.6 5.8 4.0 5.6 5.8 7.2
System state Initialization Time=8.6 8.6 A D 9.1 5.8 9.2 7.2 1 2 8.6 clock Event list 6 5.7 9.9 7.7 Server status Number in queue Time Of last event Time Of arrival Number delayed Total delay Area Under Q(t) Area Under B(t) Intuitive explanation : t=8.6 5.6 5.8 7.2
C/C++ code – include & parameters #include <stdio.h> #include <math.h> #include "lcgrand.h" /* Header file for random-number generator. */ #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);
C/C++ code – main function main() /* Main function. */ { infile = fopen("mm1.in", "r"); outfile = fopen("mm1.out", "w"); num_events = 2; initialize( ); while (num_custs_delayed < num_delays_required) { timing( ); update_time_avg_stats( ); switch (next_event_type) { case 1: arrive( ); break; case 2: depart( ); break; } } report( ); fclose(infile); fclose(outfile); return 0; }
C/C++ code – initialize function void initialize(void) /* Initialization function. */ { sim_time = 0.0; 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_event[1] = sim_time + expon(mean_interarrival); time_next_event[2] = 1.0e+30; }
C/C++ code – timing function voidtiming(void) /* Timing function. */ { int i; float min_time_next_event = 1.0e+29; next_event_type = 0; for (i = 1; i <= num_events; ++i) if (time_next_event[i] < min_time_next_event) { min_time_next_event = time_next_event[i]; next_event_type = i; } if (next_event_type == 0) { fprintf(outfile, "\nEvent list empty at time %f", sim_time); exit(1); } sim_time = min_time_next_event; }
C/C++ code – arrive function void arrive(void) /* Arrival event function. */ { float delay; time_next_event[1] = sim_time + expon(mean_interarrival); if (server_status == BUSY) { ++num_in_q; if (num_in_q > Q_LIMIT) { fprintf(outfile, "\nOverflow of the array time_arrival at"); fprintf(outfile, " time %f", sim_time); exit(2); } time_arrival[num_in_q] = sim_time; } else { delay = 0.0; total_of_delays += delay; ++num_custs_delayed; server_status = BUSY; time_next_event[2] = sim_time + expon(mean_service); } }
C/C++ code – depart function void depart(void) /* Departure event function. */ { int i; float delay; if (num_in_q == 0) { server_status = IDLE; time_next_event[2] = 1.0e+30; } else { --num_in_q; delay = sim_time - time_arrival[1]; total_of_delays += delay; ++num_custs_delayed; time_next_event[2] = sim_time + expon(mean_service); for (i = 1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i + 1]; } }
Depart state Arrive state
C/C++ code –update_time_avg_state & expon function void update_time_avg_stats(void) { float time_since_last_event; time_since_last_event = sim_time - time_last_event; time_last_event = sim_time; area_num_in_q += num_in_q * time_since_last_event; area_server_status += server_status * time_since_last_event; } float expon(float mean) /* Exponential variate generation function. */ { /* Return an exponential random variate with mean "mean". */ float u; u=rand (1); return -mean * log(u); }
References • Java • http://www.nirarebakun.com/queue/emati.html • C/C++ & FORTRAN • http://www.mhhe.com/engcs/industrial/lawkelton/index.mhtml
Q&A http://myweb.ncku.edu.tw/~q3695448/article.htm