q36954485 王俊彥 myweb.ncku.tw/~q3695448/article.htm

34
1 Single Station Queuing Single Station Queuing System System -The M/M/1 System- Q36954485 王王王 http://myweb.ncku.edu.tw/~q3695448/article.htm

Upload: verena

Post on 12-Jan-2016

57 views

Category:

Documents


7 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

1

Single Station Queuing Single Station Queuing SystemSystem

-The M/M/1 System-

Q36954485 王俊彥http://myweb.ncku.edu.tw/~q3695448/article.htm

Page 2: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

2

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

Page 3: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

3

Kendall’s notation (A/B/m/K – Z)A / B / m / k – Z

A Arrival Process

B Service Process

m Number of Servers

k maximum # of customers in the system

Z Queueing Discipline

Explanation

M Exponential Distribution (memoryless)

EkErlang Distribution with k phases

HkHyperExponential with k phases

D Deterministic Distribution (constant)

G General Distribution

1

m

Arrival process

queue

servers

Departingjobs

Queueingdiscipline

Queueing Discipline

FCFS First-come-first-serviced

LCFS Last-come-first-served

RR Round-robin

PS Processor sharing

… Page 211 in textbook

Page 4: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

4

Examples of Kendall’s notation

M / M / m / K -FCFS This would describe a queueing system with an exponential distri

bution 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

Page 5: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

5

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 tim

e

Page 6: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

6

Performance measure (cont.)

m

m)equilibriu lstatisticain system queueing afor rate

arrival the toequal is rate departure the(Since Throughput 3.

processed. becan that jobs ofnumber than theless bemust

timeofunit ain arrive that jobs ofnumber theaverageon

1 : isstability for condition The

,mrate service

rate arrival

timealinterarrivmean

timeservicemean

on Utilizati2.

], system in the jobsk are thereP[

system in the jobs ofnumber ofy probabilit 1.

k

k

Page 7: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

7

Performance measure (cont.)

WQ

TK

: theoremsLittle'

kKmean the

K : system in the jobs ofNumber 7.

queue. in the jobs ofnumber the: Qlength Queue 6.

1WT : mean view

timeserviceWT

queueW time Waiting5.

system T mesojourn ti timeResponse 4.

1kk

的時間停留在的時間停留在

1

m

…Arrival process

queue

servers

Departingjobs

QUEUE SERVICE

SYSTEM

Page 8: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

8

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)

Page 9: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

9

M/M/1 performance measure (cont.) p214

. -1

Q

, -1

W

, -1

1T

: timeresponsemean for theget we, theorem"sLittle'" With

)-(1 and (B)-------

-1K

have weso ,R.V" Geometric" of kind same is This

(A)------- )()-(1)()-(1

2

22k

kkk

ρ=(1/2),把它看成進入率與輸出率都相同,卻有 2個 servers。所以有 jobs在佇列的機會不高。

server比較忙,在整個系統

排隊的人就多。

server比較閒,在整個系統排隊的人就少。

Page 10: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

10

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

Time (unit)

0.4 1.2 0.5 1.7 0.2 1.6

0 0.4 1.6 2.1 3.8 4.0 5.6

Page 11: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

11

Exponential random variable

ln U - )mean (with expon.

. mean with R.V. lexponentiaan show willthan we

mean),by multiply &it of log natural the(takeation transformof kind some perform

otherwise 0

1x0 if 1f(x)

: pdf has and U(0,1)as toreferred be on willdistributi The

on.distributi lexponentiaan from R.V. generate toneed wemodel thissimulate To

al.interarriv lexponentiath network wi queueserver -single M/M/1 The

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;

}

Page 12: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

12

Q(t) and B(t)

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.6arrivals

departures 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

1

2

3

Q(t)

B(t)

1

0

Page 13: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

13

Three quantities

T(n)

td B(t)(n)u

(n)userver theofn utilizatio expected the(3)

T(n)

td Q(t)(n)q

(n)qQ queue in the customers of average (2)n

D(n)dW

(n)dW queuein delay average (1)

T(n)

0

T(n)

0

n

1ii

服務的人忙不忙中文翻譯:

人要坐冷板凳平均單位時間內有多少中文翻譯:

平均等了多久中文翻譯:你在佇列中

Page 14: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

14

Depart stateArrive state

Page 15: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

15

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.

InitializationTime=0

0 0 0

0

0 0 0 0

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

0.4∞

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

Page 16: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

16

Intuitive explanation : t=0.4

Number delayed Server status Event list □ ○

InitializationTime=0.4

1 0 0.4

0.4

1 0 0 0

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

1.62.4

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

0.4

Page 17: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

17

Intuitive explanation : t=1.6

Area under B(t) Number in queue Time of arrival

InitializationTime=1.6

1 1

1.6

1.6

1.6

1 0 0 1.2

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

2.12.4

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

0.4

1.6

Page 18: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

18

Intuitive explanation : t=2.1

Area under Q(t)

0.4

InitializationTime=2.1

1 2

1.62.1

2.1

2.1

1 0 0.5 1.7

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

3.82.4

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

1.6

2.1

Page 19: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

19

Intuitive explanation : t=2.4

Number delayed Total delay

InitializationTime=2.4

1 1

2.1

2.4

2.4

2 0.8 1.1 2.0

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

3.83.1

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

1.6

2.1

Page 20: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

20

Intuitive explanation : t=3.1 & t=3.3InitializationTime=3.1

1 0 3.1

3.1

3 1.8 1.8 2.7

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

3.83.3

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

InitializationTime=3.3

0 0 3.3

3.3

3 1.8 1.8 2.9

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

0.4∞

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

2.1

Page 21: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

21

Intuitive explanation : t=3.8 & t=4.0InitializationTime=3.8

1 0 3.8

3.8

4 1.8 1.8 2.9

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

4.04.9

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

InitializationTime=4.0

1 1

4.0

4.0

4.0

4 1.8 1.8 3.1

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

5.64.9

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

3.8

3.8

4.0

Page 22: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

22

Intuitive explanation : t=4.9 & t=5.6InitializationTime=4.9

1 0 4.9

4.9

5 2.7 2.7 4.0

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

5.68.6

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

InitializationTime=5.6

1 1

5.6

5.6

5.6

5 2.7 2.7 4.7

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

5.88.6

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

4.0

4.0

5.6

Page 23: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

23

Intuitive explanation : t=5.8 & t=7.2InitializationTime=5.8

1 2

5.65.8

5.8

5.8

5 2.7 2.9 4.9

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

7.28.6

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

InitializationTime=7.2

1 3

5.65.87.2 7.2

7.2

5 2.7 5.7 6.3

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

9.18.6

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

4.0

5.6

5.8

4.0

5.6

5.8

7.2

Page 24: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

24

Intuitive explanation : t=8.6InitializationTime=8.6

1 2

5.87.2

8.6

8.6

6 5.7 9.9 7.7

System state

Serverstatus

Numberin

queueTimeOf

arrival

TimeOf lastevent

9.19.2

clock Event list

Numberdelayed

Totaldelay

AreaUnder Q

(t)

AreaUnder B(t)

A

D

5.6

5.8

7.2

0.907.7/8.6u(6)n utilizatio 3.

1.159.9/8.6q(6) queuein customers ofnumber average 2.

0.955.7/6d(6) queuein delay average 1.

: measures eperformanc

Page 25: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

25

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);

Page 26: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

26

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;}

Page 27: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

27

C/C++ code – initialize functionvoid 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;}

Page 28: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

28

C/C++ code – timing function

void timing(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;}

Page 29: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

29

C/C++ code – arrive functionvoid 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); }}

Page 30: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

30

C/C++ code – depart functionvoid 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]; }}

Page 31: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

31

Depart stateArrive state

Page 32: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

32

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);}

Page 33: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

33

References

Java http://www.nirarebakun.com/queue/emati.html

C/C++ & FORTRAN http://www.mhhe.com/engcs/industrial/lawkelton/index.mhtml

Page 34: Q36954485  王俊彥 myweb.ncku.tw/~q3695448/article.htm

34

Q&AQ&A

http://myweb.ncku.edu.tw/~q3695448/article.htm