2 - Queuing Theory

download 2 - Queuing Theory

of 42

description

A description of Queuing Theory from a Comp Sci/Systems Engineering perspective.

Transcript of 2 - Queuing Theory

  • Department of Systems Engineering and Engineering ManagementCharles V. Schaefer Jr. School of EngineeringStevens Institute of TechnologyHoboken, New Jersey 07030

    Queuing

  • Example of Queuing Systems

    SYSTEM CUSTOMERS SERVER(S)

    Reception Desk People ReceptionistRepair Facility Machines RepairpersonGarage Trucks MechanicTool Crib Mechanics Tool Crib ClerkHospital Patients NursesWarehouse Pallets CraneAirport Airplanes RunwayProduction Line Cases Case PackerRoad Network Cars Traffic LightMarket Shoppers Checkout CounterLaundry Dirty Linen Washing Machines/DryersJob Shop Jobs Machines/WorkersLumberyard Trucks Overhead CraneSaw Mill Logs SawsComputer Jobs CPU/Disk/TapesTelephone Calls ExchangeTicket Office Football Fans ClerkMass Transit Riders Buses/Trains

  • Definitions

    Queue waiting line

    Queuing Systems system involving a queue

    Queuing Theory techniques to describe the

    behavior of a queuing systems

    Calling Units members of the the queue

    Service Facility the source of the goods or

    services for which the calling units wait

    Single Channel only one server

    Multi Channel more than one server

    performing the same service

  • CALLINGPOPULATION QUEUE

    SERVICEFACILITY

    SERVEDCALLING

    UNITS

    -SIZE -LENGTH -STRUCTURE-ARRIVAL PATTERN -DISTRIBUTION-ATTITUDE -DISCIPLINE

    Queuing System

  • Queuing Terms and Statistics

    Lq = mean number of calling units in the queue

    L or Ls = mean number of calling units in the system

    Wq = mean time spent in the queue

    W or Ws = mean time spent in the system

    The subscript q means

    queue whereas the s means

    the system or the queue plus

    the server

  • Queuing Terms and Statistics

    = Mean arrival rate (#units/unit time)

    1/ = Interarrival time (time between units)

    = Mean service rate (#units served/unit time)

    1/ = Mean service time (time/unit)

    Mu and Lambda are always

    rates the inverse of a rate

    is a time for example

    customers/min is the rate

    and the time would be

    minutes/cust

  • Queuing Terms and Statistics

    S = Number of equivalent servers in the

    service facility

    U = Server utilization (% of time server

    expected to be busy)

    P(n) = Probability of having n units in the system

    M = Maximum number of calling units in

    the system (finite or limited source

    problems)

  • Simple Stream

    Stationary Mean is the same for any interval of measurement

    No Aftereffects Number of occurrences in an interval is independent of number of occurrences in any other interval

    (Markovian Property)

    Orderliness Probability of more than 1 event approaches zero a interval approaches zero (i.e. for very small h)

    Theorem:

    A Simple Stream (Stream with above properties) will result in an arrival pattern that follows the Poisson Distribution)

  • Poisson Arrival Times Distribution

    Poisson Arrival (probability) distribution:

    Let x be a random variable of the number of arrivals

    Let p(x) = probability of x arrivals in time t and let denote the

    average arrival rate in time t

    If the arrival distribution is Poisson then:

    ( ) ( ) / !n t

    tP x n t e n

    0,1, 2, ....n

    Where = # of arrivals in interval of time t = Average arrival rate in interval t( )

    tP x n is probability of exactly n arrivals over interval t

    0( 0) ( ) / 0 !

    t t

    tP x t e e

    ( 0) 1

    t

    tP x e

    n

  • Queuing Formulas

    Basic Single ServerM/M/1 : Poisson Arrivals, Exponential service times, 1 Server

    0

    2

    1 /

    ( ) (0)( / )

    / ( )

    / ( )

    / ( )

    1 / ( )

    /

    n

    q

    P

    P n P

    Lq

    Ls

    W

    Ws

  • Arrival Distribution

    Arrivals Rate - Poisson

    0

    1000

    2000

    3000

    4000

    5000

    6000

    1 2 3 4 5 6 7 8 9 10 11 12 13 14

    Arrivals Per Day

    Fre

    qu

    en

    cy

    Series1

    = 4 Arrivals/day

  • Interarrival Time Distribution

    Interarrival Distribution IA

    0

    5000

    10000

    15000

    20000

    25000

    30000

    0 2 4 6 8 10 12 14 16 18 20

    Interarrival Time

    Fre

    qu

    en

    cy

    Series1

    Minutes x 100

    Avg. IAT = = .25 days = 360 Minutes1 /

  • Basic Single Server

    Poisson Arrival Process

    Exponential Service Times

    Single Server

    FCFS Server Discipline

    Infinite Source

    Infinite Queue

    Basic Multiserver

    Same as Basic Single Server Except

    Multiple Servers

    Types of Models and Assumptions

    Our main focus in this

    class will be the basic

    single server

  • Types of Models and Assumptions

    Single Server with Arbitrary Service TimesPoisson Arrival ProcessService Time Distribution is Unknown(has a mean and variance)Single ServerFCFS Server DisciplineInfinite Source, Infinite Queue

    Single Server Model with Arbitrary Service Times and aPriority Queue DisciplinePoisson Arrival ProcessService Time for Each Priority Class is UnknownSingle ServerQueue Discipline Divided Into Classes; Service is FCFS Within Each Priority Class Infinite Source, Infinite Queue

  • Server Utilization

    s

    non

    linear

    Single Server

    Multi Servers

    Server utilization is important when looking at the

    efficiency of a system

  • Queuing Results

    All Queuing Statistics in our closed form analytical models

    are STEADY STATE statistics

    Steady State: Steady State conditions exist when a

    systems behavior is not a function of time.Transient: Startup Phase

    Time

    f(x)

    Steady State

    Startup

  • A Queuing Problem Solving

    Methodology

    Read the Problem!!! Picture/Sketch the system components Identify the underlying assumptions for each component Identify the model based on the assumptions Identify , , s (ensure its a RATE, time units the same) Determine WHAT statistic(s) you have to solve for Crunch

  • Class Problem 2-1

    New Jersey Transit (NJT) operates a single train wash as

    part of its Hoboken facility. The service time of this

    machine is 30 minutes per train. The arrival time of trains

    at the cleaning facility can be approximated as a Poisson

    process with an arrival rate of 1.4 trains per hour. The

    washing center operates 24 hours a day.

    a. State the queuing model most appropriate for this

    situation (assume that NJT owns and operates a lot of

    trains).

    b. How many trains on average are waiting to use the

    facility?

    c. How much time will each train spend at the facility (in

    line and being washed)?

    d. What is the utilization rate of the washing facility?

    e. Do we need to investigate in building another washing

    facility or purchasing more efficient equipment?

    Quantitatively justify your answer!

  • Problem 2.1

    A. Basic Single Server (trains always running i.e assume infinite pop)

    B. How many trains on average are waiting to use the facility?

    C. How much time will each train spend at the facility (in line and washed)?

    D. What is the utilization rate of the washing facility?

    E. Do we need to investigate another washing facility or purchase more efficient equipment?

    Utilization rate would drop to 35% (not efficient). More efficient equipment is probably the way to go.

    1.4 trains per hour

    2 trains per hour

    1 /( ) 1 / .6 1.67Ws Hours

    / 1.4 / 2 .7 70%

    2/ ( ) 1.96 / 2(.6) 1.63

    qL trains

  • Class Problem 2-3

    As a newly assigned manger of Home Depot, you have received complaints about

    the checkout time at the lawn and garden center. You are currently operating one

    cash register. You decide to do a queuing analysis on the center and assume the

    following:

    - The calling population is infinite

    - The pattern of arrivals is Poisson distributed

    - The customers are patient and will not balk or renege

    - The queue length is unlimited (customers will join the system no

    matter how long the line is or how crowded the store is).

    - The service times by the cashier are exponentially distributed

    - The service discipline is first come, first served (no cutting in line by

    senior ranks)

    Your cash register information tells you the average number of customers at the

    checkout counter are 24 customers per hour. The service rate by the checkout

    worker averages 30 customers per hour. You are trying to justify whether to hire

    another sales associate to corporate headquarters.

  • Problem 2.3 (Continued)

    You need to determine the following statistics for

    one and two cashiers:

    1. The expected number of customers in the queue

    2. The expected number of customers in the system

    3. The expected time waiting in line at the register

    4. The expected time waiting in line plus the time being served

    5. The mean service time for a customer

    6. The probability of having 5 customers in the system

    7. The proportion of time the one cashier can be expected to be busy

  • Problem 2.3

    2 21. / ( ) (24) / 30(30 24) 3.2

    2. /( ) 24 /(30 24) 4

    3. /( ( )) 24 /(30(30 24)) 24 / 180 .133 . 8m inutes.

    4. 1 /( ) 1 / 6 .167 . 10

    5.1 / 1 / 30 / .033 /

    q

    s

    q

    L Customers

    L Customers

    W hrs

    W s hrs m inutes

    customers hr hrs c

    5 5

    2 /

    6. (0) 1 / 1 1 (24 / 30) .2, (5) (0) .2(.8) .066

    7. / 24 / 30 .8 exp

    usstomer m inutes customer

    P P P

    proportion of time cashier ected to be busy

  • Problem 2.3 (Continued)

    For 2 Cashiers (S=2)

    * See attached excel spreadsheet for P(0), P(5) Calculations

    *2

    2 2

    1. (0)( / ) / !(1 ) , (0) .4286

    (.4286)(24 / 30) (24 / 2 * 30) / 2 !(1 24 / 2 * 30) .152

    2. ( / ) .152 (24 / 30) .952

    3. / .152 / 24 / .0063

    s

    q

    q

    s q

    q q

    L P s P from mltiserver table

    L customers

    L L Customers

    W L customers customers hour

    5 ( 5 2 )

    3 .381

    4. (1 / ) .381 m in/ 2 m in/ 2.381 m in/

    5.1 / ( )

    6. (5) (24 / 30) / 2 !2 * .4286, (0) .4286

    7. / 24 / 2 * 30 .40

    q

    hrs m inutes

    W s W customer customer customer

    mean service time for a customer

    P P

    s

    Using Formulas on Page 2-15 Appendix 2B

    P(5) =.008777

  • Some Insights Into Single Server Analysis

    What is a best measure of how well a system a

    system is working?

    = server utilization

    Ws = time in system

    Wq = time waiting in line

    To me, from a customer service perspective, Wq is

    the most important measure!

  • Homework Problem 2.4

    Hoboken police have 10 patrol cars. A patrol car breaks down and requires service once every 15 days. The police department has 2 repair workers each of whom takes an average of 3 days to repair a car. Breakdown and service times are EXPONENTIALLY distributed.

    Limited Source (k=10), s=2, = 1/15 = .0667 cars/day, =.333 cars/day, N = calling population =10

    1. Determine avg. number of cars in good condition

    number of good cars = N Ls so we need to find Ls (limited source and s=2)

    P(1)=.2404, P(2)= .2163, P(3) = .1731, P(4)=.1211, P(5)=.0727, P(6)=.0363, P(7)=.0145

    P(8)=.0044, P(9)=.0009, P(10)=.0001 Ls=2.4037, N-Ls=7.5963 Cars expected to be good!

    2. Determine the average downtime for a police car that needs repairs.

    3. Determine the fraction of time at least one worker is idle.

    1. P(0)+P(1)=.1202+.2404=.3606

    # 1 (1) 2 (2) ..... 10 (10)s

    L Expected inSystem P P P

    ( ) .0667(7.5963) .5064 /

    / 2.4037 / .5064 4.7465 sin

    k s

    s s k

    See finit source eq table

    N L cars day

    W L day system

    =.1202

    for n s PN

    N n nfor s n N P

    N

    N n s s

    n

    n s

    n

    0 0 0

    ( )

    !

    ( ) ! !( )

    !

    ( ) ! !

    1

    0 2

    (0) 1 /[ !( / ) /( ) ! ! !( / ) /( ) ! ! ]n s

    s N

    n n

    n n

    P N N n n N N n s s

    See Formulas in Table 2.3 on Page 2-7

  • Problem 2.4 Spreadsheet

    Lambda Mu S N K RHO

    0.06666667 0.333333333 2 10 10 0.2

    X Y X+Y P(0)

    3 5.320431 8.320431 0.1202

    P(0) 0.1202

    P(1) 0.2404

    P(2) 0.2164

    P(3) 0.1731

    P(4) 0.1212

    P(5) 0.0727

    P(6) 0.0363

    P(7) 0.0145

    P(8) 0.0044

    P(9) 0.0003

    P(10) 0.0001

    0.999592

    Lets look at the Excel Spreadsheet

  • GPSS model of Problem 2.4

    Repair Storage 2

    XPDIS Function RN1,C24

    0,0/.1,.104/.2,.222/.3,.355/.4,.509/.5,.69/.6,.915/.7,1.2/.75,1.38

    .8,1.6/.84,1.83/.88,2.12/.9,2.3/.92,2.52/.94,2.81/.95,2.99/.96,3.2

    .97,3.5/.98,3.9/.99,4.6/.995,5.3/.998,6.2/.999,7/.9998,8

    Generate 360,FN$XPDIS,,10 ; 15 days X 24 Hours per day

    Advance 0

    Queue1 Queue Broken

    Queue Repair

    Enter Repair

    Depart Repair

    Advance 72,FN$XPDIS ; 3 days X 24 Hours Per Day

    Leave Repair

    Depart Broken

    Queue Good

    Advance 360,FN$XPDIS ; 15 days X 24 Hours Per day

    Depart Good

    Transfer ,Queue1

    Generate 24 ; 1 Day X 24 Hours Per Dy

    Terminate 1

  • GPSS Model of Problem 2.4 Results

    QUEUE MAX CONT. ENTRY ENTRY(0) AVE.CONT. AVE.TIME AVE.(-0) R

    REPAIR 8 0 505566 224900 0.879 41.728 75.165 0

    BROKEN 10 2 505566 0 2.396 113.734 113.734 0

    GOOD 10 8 505564 0 7.603 360.951 360.951 0

    STORAGE CAP. REM. MIN. MAX. ENTRIES AVL. AVE.C. UTIL. RETRY DELAY

    REPAIR 2 0 0 2 505566 1 1.517 0.758 0 0

  • Summary

    One lecture overview of queuing some universities teach whole classes in queuing

    Understanding of queuing necessary for simulation

    These are closed form math solutions Modeling queues with simulations is a better technique than closed form if the data is available

  • Questions?

  • Process Generators

    Continuous Process Generators

    In many simulations, it is more

    realistic and practical to use

    continuous random variables

    - Computational it is more efficient

    - More representative of the

    real world

    Discrete Process Generators

    Easier to explain and

    understand

  • Another DPG Example

    Suppose a random variable can take on the values 2, 5, 8, 9, 12 with corresponding relative frequencies .15, .20, .25, .22, and .18.

    DPG:

    Value of Relative Cumulative r1 < r

  • Corresponding GPSS Function

    CLASS FUNCTION RN4,D5

    .15,2/.35,5/.6,8/.82,9/1,12

    Note: GPSS RN4 can result in a 0 but not 1.0 so not quite table in

    previous slide but not much of a concern.

  • Discrete Process Generators

    0

    2

    4

    6

    8

    10

    12

    Frequency

    b. Histogram

    0 0.5 1.0 0.25 0

    0.25

    0.50

    0.75

    1

    a. Sorted Observations

    12

    9

    3

    6

    TimeBetween

    TruckArrivals,Hours

    0

    0.4

    0.8

    1.0

    CumulativeProbability

    c. Cumulative Distribution Function

    0 0.5 1.0 0.25

    0.75

    0.75

    0.2

    0.6

    Uniform Time Between Random Truck ArrivalsVariable (hours)

    0 < r < 0.40 0.250.40 < r < 0.70 0.500.70 < r < 0.80 0.750.80 < r < 1.00 1.00

    d. Process Generator

    Time Between Truck Arrivals, Hours

    12/30

    21/3024/30

    30/30

    Time Between Truck Arrivals, Hours

    10 20 30

  • Role of Statistics in Modeling and

    Simulation

    Frequency tables or histograms suppress much detail

    Idealized mathematical representations are needed

    real world is not discrete

    mathematically efficient

    The curve describing the shape of the distribution is called

    a frequency curve

    0

    0.1

    0.2

    0.3

    0.4

    5 6 7 8 9

    Interarrival Time, Students/Hour

    f(x)

    Area Under

    Curve Must Be

    Equal to 1

  • GPSS Basic Single Server Model

    Lets RUN a GPSS model of a Basic Single Server augmented to obtain histograms of inter arrival time distribution, number of

    arrivals per unit time distribution, and waiting time distribution.

    Lets look at EXCEL plots of the distribution

    Are you convinced that math and simulation model agree?

  • Basic Single Server w/ Histograms

    XPDIS Function RN1,C24

    0,0/.1,.104/.2,.222/.3,.355/.4,.509/.5,.69/.6,.915/.7,1.2/.75,1.38

    .8,1.6/.84,1.83/.88,2.12/.9,2.3/.92,2.52/.94,2.81/.95,2.99/.96,3.2

    .97,3.5/.98,3.9/.99,4.6/.995,5.3/.998,6.2/.999,7/.9998,8

    IAV Variable C1-X1

    ARR Variable X2

    HSTIA TABLE V$IAV,0,100,20

    ARRT TABLE V$ARR,0,1,20

    INQUE QTABLE 1,0,100,30

    Generate 360,FN$XPDIS

    PATH Tabulate HSTIA

    Savevalue 1,C1

    Savevalue 2+,1

    Queue 1

    Seize 1

    Advance 240,FN$XPDIS

    Release 1

    Depart 1

    Terminate 1

    Generate 1440

    Tabulate ARRT

    Savevalue 2,0

    Terminate

    Plots the Arrival and Wait Time Distributions (What arrival

    distribution do you think we will get?)

    Exponential Inter Arrival and Service Times

  • Interarrival Time Distribution

    Interarrival Distribution IA

    0

    5000

    10000

    15000

    20000

    25000

    30000

    0 2 4 6 8 10 12 14 16 18 20

    Interarrival Time

    Fre

    qu

    en

    cy

    Series1

    Minutes x 100

  • Arrival Distribution

    Arrivals Rate - Poisson

    0

    1000

    2000

    3000

    4000

    5000

    6000

    1 2 3 4 5 6 7 8 9 10 11 12 13 14

    Arrivals Per Day

    Fre

    qu

    en

    cy

    Series1

  • Time Spent in Queue Distribution

    Time in Queue Distribution

    0

    2000

    4000

    6000

    8000

    10000

    12000

    14000

    0 10 20 30

    Minutes x 100

    Fre

    qu

    en

    cy

    Series1

  • Generating Exponential IAs Using EXCEL

    Need to Convert Uniform Random Numbers (RAND()) to values of the Random Variable with desired Exponential Distribution

    We could approximate using a Discrete Process Generator but better to use a Continuous Process Generator when dealing with continuous

    distributions such as the exponential.

    We will learn a method called the Inverse Transform Method to derive a formula which can yield the desired distribution. For the exponential

    that will be:

    (1 / ) ln( )

    0 1

    x r

    where r

    arrival rate

    (1 / ) * ln( ())X RAND

    Lets Checkout using Excel!

  • Next Week

    Read Chapter 4

    Examples of Simulation

    Class Problems 4. 2, 4.3, 4.7(Ginos)*

    Role of Probability & Statistics

    Continuous Process Generators

    *see attached word doc for CORRECT Ch 4 problems to do!!!!