Simulation Simulation Modeling and Performance Analysis with - - PowerPoint PPT Presentation

simulation simulation
SMART_READER_LITE
LIVE PREVIEW

Simulation Simulation Modeling and Performance Analysis with - - PowerPoint PPT Presentation

Computer Science, Informatik 4 Communication and Distributed Systems Simulation Simulation Modeling and Performance Analysis with Discrete-Event Simulation g y Dr. Mesut Gne Computer Science, Informatik 4 Communication and Distributed


slide-1
SLIDE 1

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Simulation

Modeling and Performance Analysis with Discrete-Event Simulation g y

  • Dr. Mesut Güneş
slide-2
SLIDE 2

Computer Science, Informatik 4 Communication and Distributed Systems

Chapter 3

General Principles

slide-3
SLIDE 3

Computer Science, Informatik 4 Communication and Distributed Systems

Contents Contents Concepts of Discrete-Event Simulation Concepts of Discrete Event Simulation The Event Scheduling / Time Advance Algorithm World Views Manual Simulation using Event Scheduling Simulation in Java Object-oriented Simulation Framework in Java Modeling of Discrete-Event Simulations

  • Dr. Mesut Güneş

Chapter 3. General Principles 3

slide-4
SLIDE 4

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts of Discrete-Event Simulation Concepts of Discrete Event Simulation

  • Dr. Mesut Güneş

Chapter 3. General Principles 4

slide-5
SLIDE 5

Computer Science, Informatik 4 Communication and Distributed Systems

General Principles – Introduction General Principles – Introduction Framework for modeling systems by discrete-event simulation Framework for modeling systems by discrete event simulation

  • A system is modeled in terms of its state at each point in time
  • This is appropriate for systems where changes occur only at

discrete points in time

System state System state

  • Dr. Mesut Güneş

Chapter 3. General Principles 5

time

slide-6
SLIDE 6

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation

Concepts of dynamic, stochastic systems that change in a discrete manner

System A collection of entities that interact together over time to accomplish one or more goals, e.g., bank, network, production system. M d l A b i f ll i i l l i l Model An abstract representation of a system, usually containing structural, logical, or mathematical relationships that describe the system. System state A collection of variables that contain all the information necessary to describe the system at any time. syste at a y t e Entity An object in the system that requires explicit representation in the model, e.g., people, machines, nodes, packets, server, customer. Attributes The properties of a given entity, e.g. length of a packet, capacity of machine. p p g y g g p p y List, Set A collection of associated entities ordered in some logical fashion in a waiting line. Holds entities and event notices Entities on a list are always ordered by some rule, e.g. FIFO, LIFO, or ranked by some attribute, e.g. priority, due date Event An instantaneous occurrence that changes the state of a system. Event notice A record of an event to occur at the current or some future time, along with any

  • Dr. Mesut Güneş

Chapter 3. General Principles 6

associated data necessary to execute the event.

slide-7
SLIDE 7

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation

Event list A list of event notices for future events, ordered by time of occurrence; known as the future event list (FEL) or future event set (FES) future event list (FEL) or future event set (FES). Always ranked by the event time. Activity A duration of time of specified length, which is known when it begins. Represents a service time interarrival time or any other processing time whose Represents a service time, interarrival time, or any other processing time whose duration has been characterized by the modeler. The duration of an activity can be specified as:

  • Deterministic – Always 5 time units

St ti ti l R d d f {2 5 7}

  • Statistical – Random draw from {2, 5, 7}
  • A function depending on system variables and entities

The duration of an activity is computable when it begins The duration is not affected by other events The duration is not affected by other events To track activities, an event notice is created for the completion time, e.g., let clock=100 and service with duration 5 time units is starting

  • Schedule an “end of service”-event for clock + 5 = 105

Delay A duration of time of unspecified indefinite length, which is not known until it ends. Customer’s delay in waiting line depends on the number and service times of other customers. Typically a desired output of the simulation run

  • Dr. Mesut Güneş

Chapter 3. General Principles 7

Typically a desired output of the simulation run. Clock A variable representing the simulated time.

slide-8
SLIDE 8

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation Activity vs. Delay Activity vs. Delay Activity

  • Activity is known as unconditional wait
  • End of an activity is an event, for this an event notice is placed in

the future event list

  • This event is a primary event
  • This event is a primary event

Delay

  • Delay is known as conditional wait

Delay is known as conditional wait

  • Delays are managed by placing the entity on another list, e.g.,

representing a waiting line

  • Completion of delay is a secondary event, but they are not

placed in the future event list

  • Dr. Mesut Güneş

Chapter 3. General Principles 8

slide-9
SLIDE 9

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation Activity vs. Delay Activity vs. Delay

Delay Delay Delay Activity1 Activity2 t A1 A2 A3 D1 D2

  • Dr. Mesut Güneş

Chapter 3. General Principles 9

slide-10
SLIDE 10

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation – Example Concepts in Discrete-Event Simulation – Example

  • Consider Call Center Example from Chapter 2
  • System state at time t is given by [LQ(t), LA(t), LB(t)]
  • LQ(t) – Number of callers waiting to be served at time t
  • LA(t) – 0 or 1 to indicate Able as being idle or busy at time t

A( )

g y

  • LB(t) – 0 or 1 to indicate Baker as being idle or busy at time t
  • Entities
  • Neither callers nor the servers are explicitly represented

p y p

  • Events
  • Arrival event
  • Service completion by Able

Service completion by Able

  • Service completion by Baker
  • Activities
  • Interarrival time of callers

Interarrival time of callers

  • Service time by Able
  • Service time by Baker
  • Delay
  • Dr. Mesut Güneş

Chapter 3. General Principles

  • Delay
  • A caller‘s waiting time in queue until Able or Baker becomes free

10

slide-11
SLIDE 11

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation

  • A model consists of
  • static description of the model and
  • the dynamic relationships and interactions between the components
  • Some questions that need to be answered for the dynamic behavior
  • Some questions that need to be answered for the dynamic behavior
  • Events
  • How does each event affect system state, entity attributes, and set contents?
  • Activities
  • How are activities defined?
  • What event marks the beginning or end of each activity?
  • Can the activity begin regardless of system state, or is its beginning conditioned on the

system being in a certain state?

D l

  • Delays
  • Which events trigger the beginning (and end) of each delay?
  • Under what condition does a delay begin or end?
  • System state initialization
  • What is the system state at time 0?
  • What events should be generated at time 0 to “prime” the model – that is, to get the

simulation started?

  • Dr. Mesut Güneş

Chapter 3. General Principles 11

slide-12
SLIDE 12

Computer Science, Informatik 4 Communication and Distributed Systems

Concepts in Discrete-Event Simulation Concepts in Discrete-Event Simulation A discrete-event simulation proceeds by producing a p y p g sequence of system snapshots over time A snapshot of the system at a given time includes

S stem state

  • System state
  • Status of all entities
  • Status of all sets
  • Sets are used to collect required information for calculating

performance metrics

  • Future event list (FEL)

( )

  • Statistics

Clock System state Entities and Set 1 Set 2 Future event list (FEL) Statistics Clock System state Entities and attributes Set 1 Set 2 ... Future event list (FEL) Statistics t (x, y, z, ...) (3,t1) – Type 3 event to occur at t1

  • Dr. Mesut Güneş

Chapter 3. General Principles 12

... ... ... ... ... ... ... ...

slide-13
SLIDE 13

Computer Science, Informatik 4 Communication and Distributed Systems

The Event Scheduling / Time Advance Algorithm The Event Scheduling / Time Advance Algorithm

  • Dr. Mesut Güneş

Chapter 3. General Principles 13

slide-14
SLIDE 14

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm Future event list (FEL) Future event list (FEL)

  • All event notices are chronologically ordered in the FEL
  • At current time t, the FEL contains all scheduled events
  • The event times satisfy: t < t1 ≤ t2 ≤ t3 ≤ ... ≤ tn
  • The event associated with t1 is the imminent event, i.e., the next

event to occur event to occur

  • Scheduling of an event
  • At the beginning of an activity the duration is computed and an end-
  • f-activity event is placed on the future event list
  • The content of the FEL is changing during simulation run
  • Efficient management of the FEL has a major impact on the

Efficient management of the FEL has a major impact on the performance of a simulation run

  • Data structures and algorithms

– Array List Tree Heap etc

  • Dr. Mesut Güneş

Chapter 3. General Principles 14

– Array, List, Tree, Heap etc.

slide-15
SLIDE 15

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm

Clock State Future event list

Old system snapshot at time t

Clock State … Future event list

t (5,1,6) (3,t1) – Type 3 event to occur at t1 (1,t2) – Type 1 event to occur at t2 (1 t3) – Type 1 event to occur at t3

Event-scheduling/Time-advance algorithm Step 1: Remove the event notice for the imminent event from FEL

(1,t3) Type 1 event to occur at t3 ... (2,tn) – Type 2 event to occur at tn

imminent event from FEL

  • event (3, t1) in the example

Step 2: Advance Clock to imminent event time

  • Set clock = t

New system snapshot at time t

  • Set clock = t1

Step 3: Execute imminent event

  • update system state
  • change entity attributes

Clock State … Future event list

t1 (5,1,5) (1,t2) – Type 1 event to occur at t2 (4 t*) T 4 t t t t*

New system snapshot at time t1

g y

  • set membership as needed

Step 4: Generate future events and place their event notices on FEL

(4,t*) – Type 4 event to occur at t* (1,t3) – Type 1 event to occur at t3 ...

Event (4, t*) Step 5: Update statistics and counters

  • Dr. Mesut Güneş

Chapter 3. General Principles 15

(2,tn) – Type 2 event to occur at tn

slide-16
SLIDE 16

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm System snapshot at time 0 System snapshot at time 0

  • Initial conditions
  • Generation of exogenous events
  • Exogenous event, is an event which happens outside the system,

but impinges on the system, e.g., arrival of a customer.

System

  • Dr. Mesut Güneş

Chapter 3. General Principles 16

slide-17
SLIDE 17

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm Generation of events Generation of events

  • Arrival of a customer
  • At t=0 first arrival is generated and scheduled
  • When the clock is advanced to the time of the

first arrival, a second arrival is generated

  • Generate an interarrival time a*

Bootstrapping

  • Calculate t* = clock + a*
  • Place event notice at t* on the FEL
  • Dr. Mesut Güneş

Chapter 3. General Principles 17

slide-18
SLIDE 18

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm Generation of events Generation of events

  • Service completion of a customer
  • A customer completes service at t
  • If the next customer is present a new service time s* is generated
  • Calculate t* = clock + s*
  • Schedule next service completion at t*

p

  • Additionally: Service completion event will be scheduled at the

arrival time, when there is an idle server

  • Service time is an activity
  • Service time is an activity
  • Beginning service is a conditional event

– Conditions: Customer is present and server is idle

  • Service completion is a primary event
  • Dr. Mesut Güneş

Chapter 3. General Principles 18

slide-19
SLIDE 19

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm Generation of events Generation of events

  • Alternate generation of runtimes and downtimes
  • At time 0, the first runtime will be generated and an end-of-runtime

t ill b h d l d event will be scheduled

  • Whenever an end-of-runtime (eor) event occurs, a downtime will be

generated, and an end-of-downtime (eod) event will be scheduled

  • At the end-of-downtime event, a runtime is generated and an end-
  • f-runtime event is scheduled
  • Runtimes and downtimes are activities
  • end-of-runtime and end-of-downtime are primary events

Time runtime downtime runtime

  • Dr. Mesut Güneş

Chapter 3. General Principles 19

Time Time 0 eor eor eod

slide-20
SLIDE 20

Computer Science, Informatik 4 Communication and Distributed Systems

Event-scheduling/Time-advance algorithm Event-scheduling/Time-advance algorithm

  • Stopping a simulation

Stopping a simulation

  • 1. At time 0, schedule a stop simulation event at a specified future

time TE Simulation will run over [0, TE]

  • 2. Run length TE is determined by the simulation itself.
  • TE is not known ahead

TE is not known ahead.

  • Example 1: TE = When FEL is empty
  • Example 2: TE = When k-th customer leaves the system
  • Dr. Mesut Güneş

Chapter 3. General Principles 20

slide-21
SLIDE 21

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

  • Dr. Mesut Güneş

Chapter 3. General Principles 21

slide-22
SLIDE 22

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

World view World view

  • A world view is an
  • rientation for the model

d l developer

  • Simulation packages

typically support some

Discrete Simulation

yp y pp world views

  • Here, only world views for

discrete simulations

Event-scheduling Process-interaction Activity-scanning

discrete simulations

  • Dr. Mesut Güneş

Chapter 3. General Principles 22

slide-23
SLIDE 23

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

  • Event-scheduling

Start

g

  • Focus on events
  • Identify the entities and their

attributes

Initialization Select next event

attributes

  • Identify the attributes of the

system D fi h t h

  • Define what causes a change

in system state

  • Write a routine to execute for

Event routine 1 Event routine 2 Event routine n

each event

  • Variable time advance

Terminate?

No

Output

Yes

  • Dr. Mesut Güneş

Chapter 3. General Principles 23

End

slide-24
SLIDE 24

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

  • Process-interaction

M d l thi k i t f

  • Modeler thinks in terms of processes
  • A process is the lifecycle of one entity, which consists of various events and activities
  • Simulation model is defined in terms of entities or objects and their life cycle as they flow

through the system, demanding resources and queueing to wait for resources

  • Some activities might require the use of one or more resources whose capacities are limited
  • Some activities might require the use of one or more resources whose capacities are limited
  • Processes interact, e.g., one process has to wait in a queue because the resource it needs is

busy with another process

  • A process is a time-sequenced list of events, activities and delays, including demands for

resource, that define the life cycle of one entity as it moves through a system

  • Variable time advance
  • Dr. Mesut Güneş

Chapter 3. General Principles 24

slide-25
SLIDE 25

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

  • Activity-scanning

Start

y g

  • Modeler concentrates on activities
  • f a model and those conditions

that allow an activity to begin

Initialization Ph 2 A ti it S Phase 1: Time Scan

  • At each clock advance, the

conditions for each activity are checked, and, if the conditions are true then the corresponding

Phase 2: Activity Scan

Activity 1 Condition Activity 2 Condition Activity n Condition

true, then the corresponding activity begins

  • Fix time advance
  • Disadvantage: The repeated

Actions Other condition Actions Actions

Yes Disadvantage: The repeated scanning to discover whether an activity can begin results in slow runtime

satisfied?

No No Improvement: Three-phase approach

  • Combination of event scheduling

with activity scanning Output Terminate?

Yes No

  • Dr. Mesut Güneş

Chapter 3. General Principles 25

with activity scanning p End

slide-26
SLIDE 26

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

  • Three-phase approach

Start I iti li ti

  • Events are activities of duration

zero time units

  • Two types of activities
  • B activities: activities bound to

Initialization Phase A: Time Scan Phase B: Execute B activities due now

  • ccur; all primary events and

unconditional activities

  • C activities: activities or events

that are conditional upon certain conditions being true Phase C: Scan all C activities Phase B: Execute B activities due now co d o s be g ue

  • The B-type activites can be

scheduled ahead of time, just as in the event-scheduling approach

  • Variable time advance

Activity 1 Condition Actions Activity 2 Condition Actions Activity n Condition Actions

  • FEL contains only B-type events
  • Scanning to learn whether any C-

type activities can begin or C-type events occur happen only at the

Other condition satisfied?

Yes No pp y end of each time advance, after all B-type events have completed

Terminate?

Yes No No

  • Dr. Mesut Güneş

Chapter 3. General Principles 26

Output End

slide-27
SLIDE 27

Computer Science, Informatik 4 Communication and Distributed Systems

World Views World Views

E3 E4 P2

3 4

A3 A4 E7 E8 A A P4 E1 E2 P1 E5 E6 A5 A6 P3 A7 A8 Time E1 E2 A1 A2

5 6

  • Dr. Mesut Güneş

Chapter 3. General Principles 27

slide-28
SLIDE 28

Computer Science, Informatik 4 Communication and Distributed Systems

Examples

EXAMPLE 1

Examples

  • Dr. Mesut Güneş

Chapter 3. General Principles 28

slide-29
SLIDE 29

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

  • Reconsider grocery example from Chapter 2

I Ch t 2 W d d h th d t i l t th

  • In Chapter 2: We used an ad hoc method to simulate the grocery
  • System state at time t is given by [ LQ(t), LS(t) ]
  • LQ(t) = Number of customers in the waiting line at t
  • LS(t) = Number of customers being served at t (0 or 1)
  • Entities
  • Server and customers are not explicitly modeled
  • Events
  • Arrival (A)

( )

  • Departure (D)
  • Stopping event (E)
  • Event notices
  • (A t) arrival event at future time t

(A, t) arrival event at future time t

  • (D, t) departure event at future time t
  • (E, t) simulation stop at future time t
  • Activities
  • Interarrival time
  • Interarrival time
  • Service time
  • Delay
  • Customer time spent in waiting line
  • Dr. Mesut Güneş

Chapter 3. General Principles 29

Server Waiting line Calling population

slide-30
SLIDE 30

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

  • System state = [ LQ(t), LS(t) ] is affected by the events
  • Arrival
  • Departure
  • Dr. Mesut Güneş

Chapter 3. General Principles 30

slide-31
SLIDE 31

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

Server Busy time Maximum Queue Length

Initial conditions First customer arrives at t=0 and gets service An arrival and a departure event is on FEL event is on FEL Server was busy for 21 of 23 time units Maximum queue length Maximum queue length was 2

  • Dr. Mesut Güneş

Chapter 3. General Principles 31

slide-32
SLIDE 32

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

When event scheduling is implemented, consider When event scheduling is implemented, consider

  • Only one snapshot is kept in the computer memory
  • A new snapshot can be derived only from the previous snapshot
  • Past snapshots are ignored for advancing the clock
  • The current snapshot must contain all information necessary to

continue the simulation! continue the simulation!

In the example In the example

  • No information about particular customer
  • If needed, the model has to be extended
  • Dr. Mesut Güneş

Chapter 3. General Principles 32

slide-33
SLIDE 33

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

  • Analyst wants estimates per customer basis
  • Mean response time (system time)
  • Mean proportion of customers who spend more than 5 time units
  • Extend the model to represent customers explicitly
  • Entities: Customer entities denoted as C1, C2, C3, …
  • (Ci, t) customer Ci arrived at t
  • Event notices

(A t Ci) i l f t Ci t t

  • (A, t, Ci) arrival of customer Ci at t
  • (D, t, Cj) departure of customer Cj at t
  • Set
  • “Checkout Line” set of customers currently at the checkout counter ordered

Checkout Line set of customers currently at the checkout counter ordered by time of arrival

  • Statistics (updated when a departure event occurs)
  • S: sum of customer response times for all customers who have departed by

the current time the current time

  • F: total number of customers who spend ≥ 5 time units
  • ND: number of departures up to the current simulation time
  • Dr. Mesut Güneş

Chapter 3. General Principles 33

slide-34
SLIDE 34

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Grocery Manual Simulation Using Event Scheduling – Grocery

System State Statistics Extended version of the simulation table from Slide 31 System State Statistics Clock LQ(t) LS(t) Checkout Line Future Event List S ND F

1 (C1,0) (A,1,C2) (D,4,C1)(E,60) 1 1 1 (C1,0)(C2,1) (A,2,C3)(D,4,C1)(E,60) 2 2 1 (C1,0)(C2,1)(C3,2) (D,4,C1)(A,8,C4)(E,60) 4 1 1 (C2,1)(C3,2) (D,6,C2)(A,8,C4)(E,60) 4 1 6 1 (C3,2) (A,8,C4)(D,11,C3)(E,60) 9 2 1 8 1 1 (C3,2)(C4,8) (D,11,C3)(A,11,C5)(E,60) 9 2 1 11 1 1 (C4,8)(C5,11) (D,15,C4)(A,18,C6)(E,60) 18 3 2 15 1 (C5,11) (D,16,C4)(A,18,C6)(E,60) 25 4 3 16 (A,18,C6)(E,60) 30 5 4 18 1 (C6,18) (D,23,C6)(A,23,C7)(E,60) 30 5 4

83 . 5 35 time response = = = S

( , ) ( , , )( , , )( , ) 23 1 (C7,23) (A,25,C8)(D,27,C7)(E,60) 35 6 5

83 . 5

5

= = =

F N

  • Dr. Mesut Güneş

Chapter 3. General Principles 34

83 . 5 6 time response

D

N 83 . 6

5 ≥ D

N N

slide-35
SLIDE 35

Computer Science, Informatik 4 Communication and Distributed Systems

Examples

EXAMPLE 2

Examples

  • Dr. Mesut Güneş

Chapter 3. General Principles 35

slide-36
SLIDE 36

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Dump Truck Manual Simulation Using Event Scheduling – Dump Truck

  • The DumpTruck Problem

p

  • Six dump trucks are used to haul coal from the entrace of a small mine

to the railroad

  • Each truck is loaded by one of two loaders
  • Each truck is loaded by one of two loaders
  • After loading, the truck immediately moves to the scale, to be weighed
  • Loader and Scale have a first-come-first-serve (FCFS) queue
  • The travel time from loader to scale is negligible
  • After being weighed, a truck begins a travel time, afterwards unloads

the coal and returns to the loader queue

  • Purpose of the study: Estimation of the loader and scale utilizations.
  • Dr. Mesut Güneş

Chapter 3. General Principles 36

slide-37
SLIDE 37

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Dump Truck Manual Simulation Using Event Scheduling – Dump Truck

  • System state [ LQ(t), L(t), WQ(t), W(t) ]

Loading Time Distribution Loading Time PDF CDF

  • LQ(t) = number of trucks in the loader queue ∈{0,1,2,...}
  • L(t) = number of trucks being loaded ∈{0,1,2}
  • WQ(t) = number of trucks in weigh queue ∈{0,1,2,...}
  • W(t) = number of trucks being weighed ∈{0,1}

Loading Time PDF CDF 5 0.30 0.30 10 0.50 0.80

  • Event notices
  • (ALQ, t, DTi) dump truck i arrives at loader queue (ALQ) at time t
  • (EL, t, DTi) dump truck i ends loading (EL) at time t
  • (EW, t, DTi) dump truck i ends weighing (EW) at time t

15 0.20 1.00 Weighing Time Distribution W i hi Ti PDF CDF

( , , ) du p uc e ds e g g ( ) a e

  • Entities
  • The six dump trucks DT1, DT2, ..., DT6
  • Lists

L d T k iti t b i l di FCFS

Weighing Time PDF CDF 12 0.70 0.70 16 0.30 1.00

  • Loader queue – Trucks waiting to begin loading, FCFS
  • Weigh queue – Truck waiting to be weighed, FCFS
  • Activities
  • Loading – Loading time

Travel Time Distribution Travel Time PDF CDF

  • Weighing – Weighing time
  • Travel – Travel time
  • Delays
  • Delay at loader queue

40 0.40 0.40 60 0.30 0.70 80 0 20 0 90

  • Dr. Mesut Güneş

Chapter 3. General Principles 37

y q

  • Delay at scale

80 0.20 0.90 100 0.10 1.00

slide-38
SLIDE 38

Computer Science, Informatik 4 Communication and Distributed Systems

Manual Simulation Using Event Scheduling – Dump Truck Manual Simulation Using Event Scheduling – Dump Truck

  • Initialization

It i d th t fi t k t th l d d i t th l t ti

  • It is assumed that five trucks are at the loader and one is at the scale at time 0
  • Activity times
  • Loading time: 10, 5, 5, 10, 15, 10, 10
  • Weighing time: 12, 12, 12, 16, 12, 16
  • Travel time: 60, 100, 40, 40 80
  • Statistics
  • BL – Total busy time of both loaders
  • BS – Total busy time of the scale

Both loaders are busy! y

System State Lists Statistics Clock LQ(t) L(t) WQ(t) W(t) Loader Queue Weigh Queue Future Event List BL BS

3 2 1 DT4, DT5, DT6 (EL,5,DT3) (EL,10,DT2) (EW,12,DT1) 5 2 2 1 1 DT5, DT6 DT3 (EL,10,DT2) (EL,5+5,DT4) (EW,12,DT1) 10 5 10 1 2 2 1 DT6 DT3, DT2 (EL,10,DT4) (EW,12,DT1) (EL,10+10,DT5) 20 10 10 2 3 1 DT3, DT2, DT4 (EW,12,DT1) (EL,20,DT5) (EL,10+15,DT6) 20 10 12 2 2 1 DT2, DT4 (EL,20,DT5) (EW,12+12,DT3) (EL,25,DT6) (ALQ,12+60,DT1) 24 12

  • Dr. Mesut Güneş

Chapter 3. General Principles 38

20 1 3 1 DT2, DT4, DT5 (EW,24,DT3) (EL,25,DT6) (ALQ,72,DT1) 40 20 24 1 2 1 DT4, DT5 (EL,25,DT6) (EW,24+12,DT2) (ALQ,72,DT1) (ALQ,24+100,DT3) 44 24

slide-39
SLIDE 39

Computer Science, Informatik 4 Communication and Distributed Systems

Implementation of Simulations

SIMULATION IN JAVA

Implementation of Simulations

  • Dr. Mesut Güneş

Chapter 3. General Principles

slide-40
SLIDE 40

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java Simulation in Java

  • Java is a general purpose
  • Again the grocery example

g p p programming language

  • Object-oriented

First simple specific simulation g g y p

  • Single server queue
  • Run for 1000 customers

I t i l ti

  • First simple specific simulation

implementation

  • Later, object-oriented
  • Interarrival times are

exponentially distributed with mean 4.5 S i ti l

framework for discrete event simulation

  • Service times are also

exponentially distributed with mean 3.2

  • Known as: M/M/1 queueing

system

Calling population

ti ti+1

Arrivals

  • Dr. Mesut Güneş

Chapter 3. General Principles 40

Server Waiting line

Arrivals

slide-41
SLIDE 41

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java Simulation in Java

  • System state
  • Simulation variables

l k

y

  • queueLength
  • numberInService
  • Entity attributes
  • clock
  • lastEventTime
  • totalBusy
  • maxQueueLength

R Ti

Entity attributes

  • customers
  • Future event list

f t E tLi t

  • sumResponseTime
  • Statistics
  • rho = BusyTime/Clock
  • avgr = Average response time
  • futureEventList
  • Activity durations
  • meanInterArrivalTime
  • pc4 = Number of customers who spent

more than 4 minutes

  • Help functions
  • exponential(mu)

M th d

  • meanServiceTime
  • Input parameters
  • meanInterarrivalTime
  • Methods
  • initialization
  • processArrival
  • processDeparture
  • meanServiceTime
  • totalCustomers
  • reportGeneration
  • Dr. Mesut Güneş

Chapter 3. General Principles 41

slide-42
SLIDE 42

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java Simulation in Java

Overall structure of an event-scheduling simulation program Overall structure of the Java program simulation program

  • Dr. Mesut Güneş

Chapter 3. General Principles 42

slide-43
SLIDE 43

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Class Event Simulation in Java – Class Event

A very simple realization of an event y p

  • Only two attributes: type and time

class Event { class Event { public double time; public double time; private int type; private int type; public Event(int _type, double _time) { public Event(int _type, double _time) { type = type = _type; _type; time = time = _time; _time; } public int getType() { public int getType() { return type; return type; } public double getTime() { public double getTime() { return time; return time; }

  • Dr. Mesut Güneş

Chapter 3. General Principles 43

} }

slide-44
SLIDE 44

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Sim Class Simulation in Java – Sim Class

class Sim { class Sim { // Class Sim variables // Class Sim variables // Class Sim variables // Class Sim variables public static double clock, public static double clock, meanInterArrivalTime, meanInterArrivalTime, meanServiceTime, meanServiceTime, lastEventTime lastEventTime lastEventTime lastEventTime, totalBusy, totalBusy, maxQueueLength, maxQueueLength, sumResponseTime; sumResponseTime; public static long numberOfCustomers, public static long numberOfCustomers, queueLength, queueLength, numberInService, numberInService, totalCustomers, totalCustomers, numberOfDepartures, numberOfDepartures, longService; longService; public final static int arrival = 1; public final static int arrival = 1; // Event type for an arrival // Event type for an arrival public final static int departure = 2; public final static int departure = 2; // Event type for a departure // Event type for a departure public final static int departure = 2; public final static int departure = 2; // Event type for a departure // Event type for a departure public static EventList futureEventList; public static EventList futureEventList; // We use these data structures as // We use these data structures as public static Queue customers; public static Queue customers; // given by the system. // given by the system. public static Random stream; public static Random stream; // A random number generator // A random number generator

  • Dr. Mesut Güneş

Chapter 3. General Principles 44

public static Random stream; public static Random stream; // A random number generator // A random number generator

slide-45
SLIDE 45

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Main program Simulation in Java – Main program

public static void main(String argv[]) { public static void main(String argv[]) { meanInterArrivalTime = meanInterArrivalTime = 4 5; 5; meanInterArrivalTime = meanInterArrivalTime = 4.5; 5; meanServiceTime meanServiceTime = 3.2; = 3.2; totalCustomers totalCustomers = 1000; = 1000; long long seed = Long.parseLong(argv[0]); seed = Long.parseLong(argv[0]); t R R d ( d) d) // I // I iti iti li li RNG RNG t stream ream = new new R Ran andom

  • m(see

seed) d); // I // Initi itiali lize ze RNG RNG stream ream futureEventList futureEventList = new EventList(); = new EventList(); // Initialize the FEL // Initialize the FEL customers = customers = new new Queue(); Queue(); // Set which holds the customers // Set which holds the customers initialization(); initialization(); // Loop until first “totalCustomers" // Loop until first “totalCustomers" have departed have departed while( numberOfDepartures < totalCustomers ) while( numberOfDepartures < totalCustomers ) { Event event = (Event)futureEventList.getMin(); Event event = (Event)futureEventList.getMin(); // Get imminent event // Get imminent event futureEventList futureEventList dequeue(); dequeue(); // Be rid of it // Be rid of it futureEventList futureEventList.dequeue(); dequeue(); // Be rid of it // Be rid of it clock = event.getTime(); clock = event.getTime(); // Advance simulation time // Advance simulation time if( event.getType() if( event.getType() == arrival == arrival ) { ) { processArrival(event); processArrival(event); } l { l { else se { { processDeparture(event); processDeparture(event); } }

  • Dr. Mesut Güneş

Chapter 3. General Principles 45

reportGeneration(); reportGeneration(); }

slide-46
SLIDE 46

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Initialization Simulation in Java – Initialization

// Seed the event list with TotalCustomers arrivals // Seed the event list with TotalCustomers arrivals public static void initialization() public static void initialization() { { public static void initialization() public static void initialization() { { clock = clock = 0.0; 0.0; queueLength = queueLength = 0; 0; numberInService = numberInService = 0; 0; lastEventTime = lastEventTime = 0.0; 0.0; t t l t t lB totalB lBusy usy = 0 0 ; maxQueueLength = maxQueueLength = 0; 0; sumResponseTime = sumResponseTime = 0; 0; numberOfDepartures = numberOfDepartures = 0; 0; lon longService = Service = 0; 0; g // Create first arrival event // Create first arrival event double eventTime = double eventTime = exponential(stream, MeanInterArrivalTime); exponential(stream, MeanInterArrivalTime); Event event = new Event(arrival, eventTime); Event event = new Event(arrival, eventTime); futureEventList futureEventList enqueue(event); enqueue(event); futureEventList futureEventList.enqueue(event); enqueue(event); }

  • Dr. Mesut Güneş

Chapter 3. General Principles 46

slide-47
SLIDE 47

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Event Arrival Simulation in Java – Event Arrival

public static void processArrival(Event public static void processArrival(Event event) { event) { customers customers enqueue(event); enqueue(event); customers customers.enqueue(event); enqueue(event); queueLength++; queueLength++; // If the server is idle, fetch the event, do statistics and put into service // If the server is idle, fetch the event, do statistics and put into service if( numberInService == 0 if( numberInService == 0 ) ) { scheduleDeparture(); scheduleDeparture(); } else { else { totalBusy += totalBusy += (clock (clock - lastEventTime); lastEventTime); // server is busy // server is busy } // Adjust max queue length statistics // Adjust max queue length statistics if(maxQueueLength < if(maxQueueLength < queueLength) queueLength) { maxQueueLength = maxQueueLength = queueLength; queueLength; } // Schedule the next arrival // Schedule the next arrival Double eventTime = Double eventTime = clock + clock + exponential(stream, exponential(stream, meanInterArrivalTime); meanInterArrivalTime); Event nextArrival = Event nextArrival = new Event(arrival, eventTime); new Event(arrival, eventTime); futureEventList.enqueue( nextArrival futureEventList.enqueue( nextArrival ); ); l t l tE tTi l k l k las astE tEven ventTi tTime me = cloc

  • ck;

}

  • Dr. Mesut Güneş

Chapter 3. General Principles 47

slide-48
SLIDE 48

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Event Departure Simulation in Java – Event Departure

public static void scheduleDeparture() public static void scheduleDeparture() { double serviceTime = double serviceTime = exponential(stream exponential(stream meanServiceTime); meanServiceTime); double serviceTime = double serviceTime = exponential(stream exponential(stream, meanServiceTime); meanServiceTime); Event depart = new Event(departure, Event depart = new Event(departure, clock + serviceTime); clock + serviceTime); futureEventList.enqueue(depart); futureEventList.enqueue(depart); numberInService = numberInService = 1; 1; queueLength--; queueLength--; } public static void processDeparture(Event public static void processDeparture(Event e) { e) { // Get the customer description // Get the customer description Event finished = (Event) customers.de Event finished = (Event) customers.dequeue(); ueue(); q // If there are customers in the queue then schedule the departure of the next one // If there are customers in the queue then schedule the departure of the next one if( queueLength > if( queueLength > 0 0 ) { ) { scheduleDeparture(); scheduleDeparture(); } else { else { else { else { numberInService = numberInService = 0; 0; } // Measure the // Measure the response time and response time and update cumulative statistics update cumulative statistics double response = double response = clock - clock - finished.getTime(); finished.getTime(); R T R Ti + + sum sumResponse esponseTi Time me + += response; response; if( response > 4.0 ) if( response > 4.0 ) longService++; longService++; // record long service // record long service totalBusy += totalBusy += (clock (clock - lastEventTime); lastEventTime); numberOfDepartures++; numberOfDepartures++;

  • Dr. Mesut Güneş

Chapter 3. General Principles 48

lastEventTime = lastEventTime = clock; clock; }

slide-49
SLIDE 49

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java – Report Generator Simulation in Java – Report Generator

public public static void static void reportGe reportGene nera ration() { { d bl h l h t t l t t lB / l k dou

  • ubl

ble rho = t totalB lBusy usy/cloc

  • ck;

double avgr double avgr = = sumRespon sumResponseTime/totalCustomers; double double pc4 pc4 = = ((double) ((double)longService)/totalCustomers; System System out println( "SINGLE SERVER QUEUE SIMULATI SINGLE SERVER QUEUE SIMULATION ON - GROCERY GROCERY STORE CHECKOUT STORE CHECKOUT COUNTER COUNTER "); ); System System.ou

  • ut.println( SINGLE SERVER QUEUE SIMULATI

SINGLE SERVER QUEUE SIMULATION ON GROCERY GROCERY STORE CHECKOUT STORE CHECKOUT COUNTER COUNTER ); ); System. System.out.println( "\tMEAN "\tMEAN INTERARR INTERARRIVAL TIME TIME " " + + meanInter meanInterAr ArrivalTime ); ); System. System.out.println( "\tMEAN "\tMEAN SERVICE SERVICE TIME TIME " " + + meanServi meanService ceTime ); ); System. System.out.println( "\tNUMBER "\tNUMBER OF OF CUSTOMER CUSTOMERS S SERVED SERVED " " + + totalCust totalCustom

  • mers );

); System. stem.out.pri rint ntln ln(); (); y p y p System. System.out.println( "\tSERVER "\tSERVER UTILIZA UTILIZATI TION ON " " + + rho rho ); ); System. System.out.println( "\tMAXIMU "\tMAXIMUM M LINE LINE LENGTH LENGTH " " + + maxQueueL maxQueueLen ength ); ); System. System.out.println( "\tAVERAG "\tAVERAGE E RESPONSE RESPONSE TIME TIME " " + + avgr avgr + + " " Time Time Units"); Units"); System. System.out.println( "\tPROPOR "\tPROPORTI TION WHO WHO SPEND SPEND FOUR FOUR "); "); System. System.out.println( "\t "\t MINUTES MINUTES OR MORE OR MORE IN IN SYSTEM SYSTEM " + " + pc4 pc4 ); ); System. System.out.println( "\tSIMULA "\tSIMULATI TION RUNLENGTH RUNLENGTH " + " + clock clock + " Time + " Time Units"); Units"); System. System.out.println( "\tNUMBER "\tNUMBER OF OF DEPARTUR DEPARTURES ES " " + + totalCust totalCustom

  • mers );

); }

  • Dr. Mesut Güneş

Chapter 3. General Principles 49

slide-50
SLIDE 50

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation in Java - Output Simulation in Java - Output

SINGLE SERVER QUEUE SIMULATION - SINGLE SERVER QUEUE SIMULATION - GROCERY STORE CHECKOUT COUNTER GROCERY STORE CHECKOUT COUNTER MEAN INTERARRIVAL MEAN INTERARRIVAL TIME TIME 4.5 4.5 MEAN SERVICE TIME MEAN SERVICE TIME 3.2 3.2 NUMBER OF CUSTOMERS NUMBER OF CUSTOMERS SERVED SERVED 1000 1000 SERVER UTILIZATION SERVER UTILIZATION 0.718 0.718 MAXIMUM MAXIMUM LINE LENGTH LINE LENGTH 13.0 13.0 AVERAGE AVERAGE RESPONSE TIME RESPONSE TIME 9.563 9.563 PROPORTION WHO SPEND FOUR PROPORTION WHO SPEND FOUR MINUTES MINUTES OR MORE IN SYSTEM OR MORE IN SYSTEM 0.713 0.713 SIMULATION SIMULATION RUNLENGTH RUNLENGTH 4485.635 4485.635 NUMBER OF DEPARTURES NUMBER OF DEPARTURES 1000 1000

  • Dr. Mesut Güneş

Chapter 3. General Principles 50

slide-51
SLIDE 51

Computer Science, Informatik 4 Communication and Distributed Systems

Implementation of Simulations

OBJECT-ORIENTED

Implementation of Simulations

DISCRETE-EVENT SIMULATION FRAMEWORK

  • Dr. Mesut Güneş

Chapter 3. General Principles

SIMULATION FRAMEWORK

slide-52
SLIDE 52

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework Object-Oriented Simulation Framework

Package core Package rng

  • Dr. Mesut Güneş

Chapter 3. General Principles 52

slide-53
SLIDE 53

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework Object-Oriented Simulation Framework OO Discrete-Event Simulation Framework consists of OO Discrete Event Simulation Framework consists of

  • Two packages

Package core

  • SimEvent
  • SimEntity
  • SimQueue
  • SimControl
  • SimControl

Package rng g g

  • RNG
  • Dr. Mesut Güneş

Chapter 3. General Principles 53

slide-54
SLIDE 54

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – SimEvent Object-Oriented Simulation Framework – SimEvent

public class SimEvent { public class SimEvent { double time; double time; double time; double time; int type; int type; SimEntity src; SimEntity src; SimEntity dst; SimEntity dst; public long id; public long id; public SimEvent(SimEntity _dst) { public SimEvent(SimEntity _dst) { type = 0; type = 0; time = 0; time = 0; src = null; src = null; dst = _dst; dst = _dst; } public SimEvent(double _time, SimEntity _dst) { public SimEvent(double _time, SimEntity _dst) { type type = 0; 0; type type 0; 0; time = _time; time = _time; src = null; src = null; dst = _dst; dst = _dst; } public SimEvent(double public SimEvent(double _time, SimEntity _src, SimEntity _dst) { _time, SimEntity _src, SimEntity _dst) { type = 0; type = 0; time = _time; time = _time; src = _src; src = _src;

  • Dr. Mesut Güneş

Chapter 3. General Principles 54

dst = _dst; dst = _dst; }

slide-55
SLIDE 55

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – SimEntity Object-Oriented Simulation Framework – SimEntity

public abstract class SimEntity { public abstract class SimEntity { protected SimControl protected SimControl simControl; simControl; protected SimControl protected SimControl simControl; simControl; /** /** * An entity has to know the current instance of the simulator. * An entity has to know the current instance of the simulator. * @param * @param _simControl _simControl * @ * @ Si Si C t l * @ * @see see Si SimCon

  • ntro

rol */ */ public SimEntity(SimControl public SimEntity(SimControl _simControl) { _simControl) { simControl = simControl = _simControl; _simControl; } /** /** * This method handles the events destined to this entity. * This method handles the events destined to this entity. * @param * @param event event * @see SimEvent @see SimEvent @see SimEvent @see SimEvent */ */ abstract public void abstract public void handleEvent(SimEvent handleEvent(SimEvent event); event); }

  • Dr. Mesut Güneş

Chapter 3. General Principles 55

slide-56
SLIDE 56

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – SimQueue Object-Oriented Simulation Framework – SimQueue

public abstract class SimQueue { public abstract class SimQueue { /** /** * Schedule the given event according to the event time. * Schedule the given event according to the event time. * @param * @param event event * @see SimEvent * @see SimEvent */ */ */ */ abstract public void abstract public void schedule(SimEvent event); schedule(SimEvent event); /** /** * Return the next event in the * Return the next event in the queue. ueue. q * @return imminent event in queue. * @return imminent event in queue. * @see SimEvent * @see SimEvent */ */ abstract public SimEvent getNextEvent(); abstract public SimEvent getNextEvent(); /** /** * This method dumps the content of the queue. * This method dumps the content of the queue. * It is for debugging * It is for debugging purposes. purposes. */ */ b t t bli t bli id id d () abstrac ract t pu publi blic vo void d id dump ump() (); abstract public boolean isEmpty(); abstract public boolean isEmpty(); }

  • Dr. Mesut Güneş

Chapter 3. General Principles 56

slide-57
SLIDE 57

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – SimControl Object-Oriented Simulation Framework – SimControl

public class SimControl { public class SimControl { private SimQueue queue; private SimQueue queue; private double time; private double time; private double endTime; private double endTime; public SimControl(SimQueue _queue) { public SimControl(SimQueue _queue) { queue = queue = _queue; _queue; } public void run() { public void run() { SimEvent event; SimEvent event; while( queue.isEmpty() while( queue.isEmpty() == false ) { == false ) { // If there is an event in FEL and the sim-end is not reached ... // If there is an event in FEL and the sim-end is not reached ... event = queue.getNextEvent(); event = queue.getNextEvent(); time = event.getTime(); time = event.getTime(); if( event.getTime() if( event.getTime() <= endTime ) <= endTime ) dispatch(event); dispatch(event); // ... call the destination object of this event // ... call the destination object of this event else else break; break; } }

  • Dr. Mesut Güneş

Chapter 3. General Principles 57

private void dispatch(SimEvent private void dispatch(SimEvent event) { event) { event.getDestination().handleEvent(event); event.getDestination().handleEvent(event); }

slide-58
SLIDE 58

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – SimControl Object-Oriented Simulation Framework – SimControl

... public class SimControl ... ... public class SimControl ... public void setRunTime(double _runTime) { public void setRunTime(double _runTime) { endTime = _runTime; endTime = _runTime; } bli bli id h id h d l (Si (Si E t t) t) { pu publi blic vo void id sc schedule(Si (SimEven vent t even event) { t) { queue.schedule(event); queue.schedule(event); } public void schedule(SimEvent ublic void schedule(SimEvent event, double event, double _delta) { delta) { p _ p _ event.setTime(time event.setTime(time +_delta); +_delta); schedule(event); schedule(event); }

  • Dr. Mesut Güneş

Chapter 3. General Principles 58

slide-59
SLIDE 59

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework – RNG Object-Oriented Simulation Framework – RNG

public abstract class RNG public abstract class RNG { abstract public double getNext(); abstract public double getNext(); abstract public double getNext(); abstract public double getNext(); } bli bli l E E ti l t d RNG { RNG { pu publi blic class ass E Exponen xponenti tial l ex exten ends RNG { RNG { double lambda; double lambda; Random uniform; Random uniform; public Ex ublic Exponential(double

  • nential(double _lambda) {

lambda) { p p p p _ lambda = _lambda; lambda = _lambda; uniform = uniform = new Random(System. new Random(System.currentTimeMillis currentTimeMillis()); ()); } /* / / * @see rng.RNG#getNext() * @see rng.RNG#getNext() */ */ public double getNext() { public double getNext() { return -Math. return -Math.log log(uniform.nextDouble())/lambda; (uniform.nextDouble())/lambda; } }

  • Dr. Mesut Güneş

Chapter 3. General Principles 59

slide-60
SLIDE 60

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework Object-Oriented Simulation Framework Again our Grocery Again our Grocery example

  • Use of the object-

i t d i l ti

  • riented simulation

framework

MM1Generator MM1Generator

  • Generates new

customer

MM1Server

  • Serves customer
  • Dr. Mesut Güneş

Chapter 3. General Principles 60

slide-61
SLIDE 61

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework Object-Oriented Simulation Framework

  • Dr. Mesut Güneş

Chapter 3. General Principles 61

slide-62
SLIDE 62

Computer Science, Informatik 4 Communication and Distributed Systems

Object-Oriented Simulation Framework Object-Oriented Simulation Framework

8 9 Simulation Theory 8 9 Simulation Theory 4 5 6 7 ystem Time 4 5 6 7 Queueing Time

System Time Queueing Time

1 2 3 4 Sy 1 2 3 Q

System Time Queueing Time

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 rho 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 rho 0.9 Simulation 0 5 0.6 0.7 0.8 y System Simulation Theory

p0 – Probability that a customer finds the system idle p0

0.2 0.3 0.4 0.5 Probability of Empt

  • Dr. Mesut Güneş

Chapter 3. General Principles 62

0.1 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 rho

slide-63
SLIDE 63

Computer Science, Informatik 4 Communication and Distributed Systems

How to model discrete-event simulations?

SIMULATION GRAPHS

How to model discrete event simulations?

  • Dr. Mesut Güneş

Chapter 3. General Principles 63

slide-64
SLIDE 64

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs Simulation Graphs Modeling of Discrete-Event Simulations is difficult Modeling of Discrete Event Simulations is difficult

  • There are no standardized modeling method
  • Modeling is something like an art ;-(

Simulation Graphs were introduced by Schruben (1983) as E t G h d l t d Event Graphs and later renamed Simulation Graphs are the only graphical paradigm that Simulation Graphs are the only graphical paradigm that directly models the Future Event List logic for a discrete-event model

  • Dr. Mesut Güneş

Chapter 3. General Principles 64

slide-65
SLIDE 65

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs Simulation Graphs A Simulation Graph consists of nodes and edges A Simulation Graph consists of nodes and edges

  • Nodes – Event or state transition
  • Edges – Scheduling of other events. Can have
  • Boolean condition
  • Time delay

Basic Simulation Graph Basic Simulation Graph

  • Event A causes event B to be scheduled after a time delay t,

providing condition (i) is true

  • If no time delay exists, t is omitted
  • If event B is always scheduled following the occurrence of event

A condition is omitted unconditional edge A, condition is omitted unconditional edge

A B

(i)

  • Dr. Mesut Güneş

Chapter 3. General Principles 65

A B

t

slide-66
SLIDE 66

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 1 – Poisson Process Simulation Graphs – Example 1 – Poisson Process A poisson process counts the number of events in a time A poisson process counts the number of events in a time interval

  • N denotes the cumulative number of arrivals
  • tA is exponentially distributed

Arrival

tA

{N++}

  • Dr. Mesut Güneş

Chapter 3. General Principles 66

tA1 tA2 tA3 tA4 tA5

slide-67
SLIDE 67

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 – Simple Queueing Simulation Graphs – Example 2 – Simple Queueing Simple Queueing Model G/G/MaxB Simple Queueing Model G/G/MaxB

  • tA Interarrival time of customer
  • Q Number of customers in queue
  • B Number of busy servers
  • tS Service time

tS Arrival Start service tA (B<MaxB) End service

S

{Q++} (Q>0) {B--} {Q--, B++}

  • Dr. Mesut Güneş

Chapter 3. General Principles 67

slide-68
SLIDE 68

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 – Simple Queueing Simulation Graphs – Example 2 – Simple Queueing Example yet not complete Example yet not complete How to start simulation run? Initialization is open. Initialization consists of:

  • Setting of all parameters
  • Setting of initial values of state variables
  • Placing initial event notices

How to determine initial events? With Sim lation Graphs With Simulation Graphs

  • Every event that has only incoming or self-scheduling edges

must be scheduled at the beginning of the run. g g

  • As convention a special event is placed in the future event list:

Run

  • Dr. Mesut Güneş

Chapter 3. General Principles 68

slide-69
SLIDE 69

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 – Simple Queueing Simulation Graphs – Example 2 – Simple Queueing

Arrival Start tA (B<MaxB) End tS Arrival service service {Q++} (Q>0) {B--} {Q--, B++} Run tA {Set value of MaxB, Q=0, B=0}

Special event used as convention to place initial events in FEL events in FEL.

  • Dr. Mesut Güneş

Chapter 3. General Principles 69

slide-70
SLIDE 70

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Passing Attributes on Edges Simulation Graphs – Passing Attributes on Edges Enhancement to pass attributes on edges Enhancement to pass attributes on edges

  • Event A causes event B to be scheduled after a time delay t,

providing condition (i) is true. The parameter j is set to k.

  • Passed parameter k can be a list of parameters.

A B(j)

(i)

k

A B(j)

t k

  • Dr. Mesut Güneş

Chapter 3. General Principles 70

slide-71
SLIDE 71

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 Simulation Graphs – Example 2 Serie of queues consisting of N separate queues Serie of queues consisting of N separate queues

  • Production line
  • Chain of devices

Calling population

Service Group 1 Service Group 2 Service Group N

  • Dr. Mesut Güneş

Chapter 3. General Principles 71

slide-72
SLIDE 72

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 Simulation Graphs – Example 2 Approach 1 Approach 1

  • Chain several representations of a queue

Arrival Start tA (B1<MaxB1) End tS1 Arrival 1 service 1 service 1 {Q1++} (Q1>0) {B1--} {Q1--, B1++} (Q1>0) tS2 Arrival 2 Start service 2 (B2<MaxB2) End service 2

S2

  • Dr. Mesut Güneş

Chapter 3. General Principles 72

{Q2++} (Q2>0) {B2--} {Q2--, B2++}

slide-73
SLIDE 73

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Example 2 Simulation Graphs – Example 2 Approach 2 Approach 2

  • Use edge attributes
  • The simulation code of each service station is the same

t (j)

1

(j=1) Arrival (j) Start service (j) tA (B(j)<MaxB(j)) End service (j) tS(j) j j (j) (j) {Q(j)++} (Q(j)>0) {B(j)--} {Q(j)--, B(j)++} j j+1 (j<N)

  • Dr. Mesut Güneş

Chapter 3. General Principles 73

(j<N)

slide-74
SLIDE 74

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Canceling Edges Simulation Graphs – Canceling Edges Enhancement to cancel event notices from FEL Enhancement to cancel event notices from FEL

  • When event A occurs and condition (i) is true, the next
  • ccurrence of event B is removed from the event list
  • If no event notice for B is on the event list, nothing happens.

A B

(i)

A B

  • Dr. Mesut Güneş

Chapter 3. General Principles 74

slide-75
SLIDE 75

Computer Science, Informatik 4 Communication and Distributed Systems

Simulation Graphs – Summary Simulation Graphs – Summary Simulation Graphs Simulation Graphs

  • Simple approach to model discrete-event system
  • Allows identification of required events of simulation system
  • Graphical representation of the relationship of events
  • Enhancements allow construction of more complex models from

simple ones simple ones

  • Provides optimization of simulation graphs (not discussed)
  • Disadvantage:
  • Focus is on events, modeler has to abstract from

entities

  • Dr. Mesut Güneş

Chapter 3. General Principles 75

slide-76
SLIDE 76

Computer Science, Informatik 4 Communication and Distributed Systems

Summary Summary Introduced a general framework for discrete-event simulations Introduced a general framework for discrete event simulations Event-scheduling and time-advance algorithm Generation of events World views for discrete simulations Introduced manual discrete event simulation Introduced simulation in Java Object-oriented simulation framework in Java Introduced Simulation Graphs as a tool to model discrete- event simulations

  • Dr. Mesut Güneş

Chapter 3. General Principles 76