25
1 Outline Outline simulating GI/G/1 queues M/M/1 queues theoretical results of queueing systems an inventory system simulation program with an event calendar hand simulation

1 Outline simulating GI/G/1 queues M/M/1 queues theoretical results of queueing systems an inventory system simulation program with an event

Embed Size (px)

Citation preview

1

OutlineOutline

simulating GI/G/1 queues M/M/1 queues

theoretical results of queueing systems an inventory system simulation program with an event calendar hand simulation

2

To Simulate an To Simulate an GIGI//GG/1 Queue/1 Queue

definition of variables definition of events pseudo code flow chart of program

N K L

Ta Ts TNOW

TMAX distribution of inter-arrival times

distribution of service times

3

Flow Chart Flow Chart for Simulating an for Simulating an GIGI//GG/1 Queue/1 Queue

N = L = K = T = 0; Ta = random inter-arrival time; Ts = infinity

Yes

ouput L/Tnow and L/K

L = L + (Ts - Tnow)N; Tnow = Ts;N = N - 1

L = L + (Ta - Tnow)N; Tnow = Ta;N = N + 1; K = K +1;

Ta = Tnow + random inter-arrival time

Ts = Tnow + random service time

Tnow Tmax

No

next eventservice

N = 0

Ts = Tnow + random service time

No

Yes

Yes

Ts = infinity

arrival

N = 1No

4

To Simulate an To Simulate an GIGI//GG/1 Queue/1 Queue

definition of variables definition of events pseudo code flow chart of program Java program

5

Variations of Variations of GIGI//GG/1 Queues/1 Queues

M/M/1-based queue standard: Java program with queue limit: Java program

6

Terms Associated with a CustomerTerms Associated with a Customer

for customer i arrival time, tai

time to start service, tsi

time to leave system, tdi

time in queue, Di = tsi – tai

service time, Si = tdi – tsi

time in system, Wi = tdi – tai

other names of time in queue

= waiting time in queue = delay time

other names of time in system

= waiting time in system = total time in system

7

Machine(Server)

Queue (FIFO)

Theoretical Result: Conservation of TimeTheoretical Result: Conservation of Time

n n-1 n-2... ... n n-1... nn n-1 n-2 n-3...

for each customer, his time in system = time in queue + service time

ave. time in system = ave. time in queue + E(service time)

tag nth customer

8

Sample-Path Results Sample-Path Results of a Queueing Systemof a Queueing System

state: N(t), number of customers in system

N(t)

t6 10 13 17 23 260

0

4

3

2

1

average # of customers up to t = 26:26

)(260 dssN

9

Sample-Path Results Sample-Path Results of a Queueing Systemof a Queueing System

total length of rectangular boxes of the same color = waiting time of the corresponding customer in system

5

1

260 )(

iiWdssN

5

5

1260

5

1

26

5

2626

)(i

iWi

iWdssN

average # in system

= (arrival rate) (average waiting

time)

10

Theoretical Result: Little’s FormulaTheoretical Result: Little’s Formula

very general result for any system: L = w

L = average # of customers in system = arrival rate of customers w = average time in system

11

Theoretical Result: Little’s FormulaTheoretical Result: Little’s Formula

GI/G/1 queue the whole system

average # in system = (arrival rate) (average time in system)

the waiting queue as the system average # in queue = (arrival rate)

(average time in queue) the server as the system

utilization of server = (arrival rate) E(service time)

12

An Inventory SystemAn Inventory System

Day n

demand of the Day nDn ~ Geo(0.1)

at the beginning of

Day n: update inventory if

ordered quantity arrives

lost sales, no back order$0.1 per unit on

hand at the beginning of a day after receiving any outstanding order

(Q, s) policy: order Q items at the end of a day if inventory on

hand s

at most one outstanding order

leadtime of orders: equally likely to be 0

to 4 days (i.e., the ordered quantity can possibly arrive the

next day)

ordering cost: $20 per order

penalty: $1 per piece lost

13

Inventory SystemInventory System

inventory system definition of variables definition of events pseudo code flow chart Java program

14

Simulating Complex SystemsSimulating Complex Systems

simple system (up to now) chess piece, machine, GI/G/1 queue, inventory

system tailor-made programs for these problems

complex problems generic program structure event scheduled by an event calendar

15

Generic Program Structure Generic Program Structure for Complex Systemsfor Complex Systems

Initialization Event while (not stopping (e.g., TNOW < TTERM)) {

switch (Next Event Type) {case 1:

tasks of type 1 event;break;

.. .. .. .. case n:

tasks of type n event;break;

}}Termination Event

need to keep track of the

timing of events

16

Conceptual Structure Conceptual Structure of an Event Calendar of an Event Calendar

event: (time, type, tasks to do) event calendar: a link list with scheduled future

events in ascending order of time example

four events scheduled at epoch 0 event 1: (24.3, type = 4, tasks to do) event 2: (35.6, type = 1, tasks to do) event 3: (41.3, type = 2, tasks to do) event 4: (5000, type = END, tasks to do = end program)

17

Event Calendar Event Calendar of a Simulation Programof a Simulation Program

Event. Cal.

TNOW = 0:

1 24.3 type 4 tasks to do

2 35.6 type 1 tasks to do

3 41.3 type 2 tasks to do

4 5000 END End simulation

18

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

24.3 type 4 tasks to do

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

Event Calendar Event Calendar of a Simulation Programof a Simulation Program

Event. Cal.

move time to TNOW = 24.3

1

2

3

4

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

suppose that no new event is created by a type 4 event

execute first event and update event calendar

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

TNOW = 0:

19

24.3 type 4 tasks to do

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

Event Calendar Event Calendar of a Simulation Programof a Simulation Program

Event. Cal.

move time to TNOW = 24.3

1

2

3

4

suppose that a new event is created by an type 4 event at 39.1

execute first event and update event calendar

TNOW = 0:

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

39.1 type 4 tasks to do

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

39.1 type 4 tasks to do

35.6 type 1 tasks to do

41.3 type 2 tasks to do

5000 END End simulation

39.1 type 4 tasks to do

20

Operations of the Event CalendarOperations of the Event Calendar

delete an event that has (just) occurred after completing all tasks at TNOW, remove the first

event in the event calendar

insert a new event get the event time of the new event check where to insert the event move backward one rank for events occurring after the

new event insert the new event

Describe concept only; actual

implementation depends on the data

structure used

21

A Crude Pseudo-Code ofA Crude Pseudo-Code of GI GI//GG/1/1 Queue with Event Calendar Queue with Event Calendar

1 initialization set TNOW = 0; initialize variables; set termination event; set initial

events 2 get next event type 3 while { next event != termination } {

get next event time and next event details set TNOW to next event time update the Event Calendar execute next event, including updating variables and possibly adding

new events to Event Calendar get next event type }

4 execute the termination Event

22

An An GIGI//GG/1/1 Queue with Queue with the Event Calendar the Event Calendar

inter-arrival times ~ exp of mean 10 service times ~ exp of mean 5 Java Program

23

Simulation by HandSimulation by Hand

simulate the system for 20 time units to get total # of customers served (in the time horizon) average and maximum waiting time in queue time-average and maximum number in queue average and maximum total time in system utilization (proportion of busy time of station)

24

Input DataInput Data

Initially (time 0) empty and idle Part Number Arrival Time Interarrival Time

Service Time1 0.00 1.73 2.902 1.73 1.35 1.763 3.08 0.71 3.394 3.79 0.62 4.525 4.41 14.28 4.466 18.69 0.70 4.367 19.39 15.52 2.078 34.91 3.15 3.369 38.06 1.76 2.3710 39.82 1.00 5.3811 40.82 . .. . . .

Stop when 20 minutes of (simulated) time have passed

25

hand simulation