Timed Discrete Event Modelling and Simulation extend State Automata - - PowerPoint PPT Presentation

timed discrete event modelling and simulation
SMART_READER_LITE
LIVE PREVIEW

Timed Discrete Event Modelling and Simulation extend State Automata - - PowerPoint PPT Presentation

Timed Discrete Event Modelling and Simulation extend State Automata with time in state equivalent to Event Graphs time to transition schedule events Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete


slide-1
SLIDE 1

Timed Discrete Event Modelling and Simulation

  • extend State Automata with “time in state”
  • equivalent to Event Graphs “time to transition”

schedule events

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 1/54

slide-2
SLIDE 2

(timed) Discrete Event Models

red 50 green 100 yellow 15 δ δ δ to_red to_yellow to_green

schedule in 15 schedule in 50 schedule in 100

yellow red green to_red to_green to_yellow to_red

states events t 50 100 15

state trajectory Finite State Automaton Event (Scheduling) Graph red green yellow to_green to_yellow to_red

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 2/54

slide-3
SLIDE 3

Discrete Event Modelling and Simulation

  • Model : objects and relationships among objects
  • Object : characterized by attributes to which values can be assigned
  • Attributes:

– indicative – relational

  • Values: of a type

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 3/54

slide-4
SLIDE 4

Time and State Relationships

  • Indexing Attribute: enables state transitions

Time is most common.

  • Instant: value of System Time at which the value of at least one attribute
  • f an object can be assigned.
  • Interval: duration between two successive instants.
  • Span: contiguous succession of one or more intervals.
  • State of an object: enumeration of all attribute values at a particular

instant.

  • State of the system: all object states at a particular instant.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 4/54

slide-5
SLIDE 5

Single Server Queueing System

Physical View Queue Cashier Departure Arrival Departure Queue Abstract View Cashier [ST distribution] [IAT distribution] Arrival Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 5/54

slide-6
SLIDE 6

Queueing System State Trajectory

state= queue_length x cashier_state

queue_length T 1 2 10 20 30 40 50 cashier_state Busy Idle T 10 20 30 40 50 T Input Events Arrival 10 20 30 40 50

E1 E2

T Output Events Departure 10 20 30 40 50

E3 E4

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 6/54

slide-7
SLIDE 7

Time and State Relationships

  • Activity: state of an object over an interval
  • Event: change in object state, occurring at an instant.

Initiates an activity

– Determined: occurrence based on time (“time event”) – Contingent: based on system conditions (“state event”)

  • Object activity: state of object between two events for that object
  • Process: succession of states of object over a span

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 7/54

slide-8
SLIDE 8

Event/Object Activity/Process

Cust2 Process Cust1 Activity

Cust2 Arrival Cust2 Start Queueing Cust2 End pay cashier Cust2 Leave

t

Cust2 End Queueing Cust2 Start pay cashier

Cust2 Activity Event

Cust1 Arrival Cust1 Start pay cashier Cust1 End pay cashier Cust1 Leave

Cust1 Process Cust2 Activity queue pay cashier pay cashier

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 8/54

slide-9
SLIDE 9

Event Scheduling

  • Identify objects and their attributes
  • Identify system attributes (global)
  • Define what causes changes in attribute value as event
  • Write event routine for each event:

– modify state (attributes) – schedule event(s) at t

∆t

∆t

  • Priorities for tie-breaking
  • Event scheduling logic

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 9/54

slide-10
SLIDE 10

Cashier-queue Event Scheduling Model

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 10/54

slide-11
SLIDE 11

declare variables: t : Time queue_length : PosInt cashier_state : {Idle, Busy} declare events: start, arrival, departure, end define events: start event: /* scheduled first automatically by simulator */ /* initializations */ queue_length = 0 cashier_state = Idle /* schedule end of simulation */ schedule end absolute end_time

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 11/54

slide-12
SLIDE 12

/* schedule first arrival */ schedule arrival relative 0 arrival event: schedule arrival relative Random(IATmean, IATspread) if (queue_length == 0) if (cashier_state == Idle) cashier_state = Busy schedule departure relative Random(SERVmean, SERVspread) else queue_length++ else /* queue_length != 0 */ queue_length++ departure event: if (queue_length == 0) cashier_state = Idle else /* queue_length != 0 */ queue_length-- schedule departure relative Random(SERVmean, SERVspread)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 12/54

slide-13
SLIDE 13

end event: /* terminates simulation */ /* process/output performance metrics */ print time, queue_length /* current */ print average_queue_length

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 13/54

slide-14
SLIDE 14

Event Scheduling Kernel

start initializations (schedule "start" event) time flow mechanism: select next event from event list event routine 1 event routine "end"

  • utput

performance metrics; cleanup; ...

end event routine k event routine k+1 ... ... Event List: [(ev1,t1),(ev2,t2), ...] state variables; performance variables time

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 14/54

slide-15
SLIDE 15

Input Generation

A “model” of input (sequence of Inter Arrival Times):

  • Trace driven
  • Auto generating (bootstrapping)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 15/54

slide-16
SLIDE 16

Cashier-queue Event List

ARR 10 Current_event State set: queue_size x cashier_status time Event List ( 0 , Idle) ( 0 , Busy) 10 20 ( 1 , Busy) 30 ( 0 , Busy) Initialized to: empty queue idle cashier arrival pre-scheduled at time 10 Process current event: set time to current event time update state: cashier busy schedule next arrival at t+IAT() schedule departure at t+ST() remove current event from list Process current event: set time to current event time update state: cashier remains busy queue length increases schedule next arrival at t+IAT() remove current event from list Process current event: set time to current event time generate departure output update state: cashier remains busy (customer from queue) queue length decreases schedule departure at t+ST() remove current event from list DEP 50 ARR 100 Current_event DEP 30 ARR 100 Current_event ARR 20 DEP 30 Current_event

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 16/54

slide-17
SLIDE 17

Queueing System State Trajectory

state= queue_length x cashier_state

queue_length T 1 2 10 20 30 40 50 cashier_state Busy Idle T 10 20 30 40 50 T Input Events Arrival 10 20 30 40 50

E1 E2

T Output Events Departure 10 20 30 40 50

E3 E4

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 17/54

slide-18
SLIDE 18

Termination Conditions

  • Empty Event List

Need to stop generating arrivals after tend when auto-generating arrivals

  • Schedule Termination Event

– process statistics – cleanup – stop – caveat: process all final events !

use reserved priority

re-schedule

  • Similarly: schedule initialization/setup

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 18/54

slide-19
SLIDE 19

Event Scheduling (dis)advantages

  • advantage: run-time efficient
  • disadvantage: hard to understand model

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 19/54

slide-20
SLIDE 20

Activity Scanning (rule-based)

Activity:

  • condition: must be satisfied for activity to take place.

Becomes true only at event times.

  • actions: operations performed when condition becomes true

Time-advance mechanism:

  • fixed time-step

Also known as Two Phase Approach

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 20/54

slide-21
SLIDE 21

Cashier-queue Activity Scanning Model

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 21/54

slide-22
SLIDE 22

declare (and initialize) variables: t : Time queue_length : PosInt = 0 cashier_state : {Idle, Busy} = Idle t_arrival : Time = 0 t_depart : Time = plusInf declare activities: queue_pay, depart, end queue_pay activity condition: t >= t_arrival actions: if (queue_length == 0) if (cashier_state == Idle) keep queue_length == 0 cashier_state = Busy t_depart = t + Random(SERVmean, SERVspread) /* service time */ else queue_length++

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 22/54

slide-23
SLIDE 23

else /* queue_length != 0 */ queue_length++, keep cashier_state == Busy t_arrival = t + Random(IATmean, IATspread) /* inter arrival time */ depart activity condition: t >= t_departure actions: if (queue_length == 0) cashier_state = Idle else /* queue_length != 0 */ queue_length--, keep cashier_state == Busy t_depart = t + Random(SERVmean, SERVspread) /* service time */ end activity condition: t >= t_end actions: print t, queue_length /* current */ print avg_queue_length /* performance metric */

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 23/54

slide-24
SLIDE 24

Activity Scanning

start initializations time flow mechanism: discrete time step activity 1 activity "end" end activity k activity k+1 ... ... state variables; performance variables

condition actions condition actions condition actions condition

activity scan

phase 1 phase 2

  • utput

performance metrics; cleanup; ...

discrete time variable

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 24/54

slide-25
SLIDE 25

Activity Scanning (dis)advantages

  • advantage: declarative model
  • disadvantages:

– inaccurate if changes occur in between time-steps – run-time inefficient (fixed time-step)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 25/54

slide-26
SLIDE 26

Three Phase Approach

  • Bound to occur activities: unconditional state changes. Pre-scheduled.
  • Conditional activites

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 26/54

slide-27
SLIDE 27

Three Phase Approach

start initializations time flow mechanism: select earliest time on EL activity C"end" end state variables; performance variables

condition actions

A phase

Event List (EL): [(activityB1,t1),(activityB2,t2), ...] execute all B activities

  • n EL due now

B phase

activity B"end" ...

actions

  • utput

performance metrics; cleanup; ...

time activity C1 activity Ck activity C(k+1) ... ...

condition actions condition actions condition actions

activity scan

C phase

activity B1 activity Bk activity B(k+1) ... ...

actions actions actions

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 27/54

slide-28
SLIDE 28

Three Phase Approach (dis)advantages

  • advantage: performance added to Activity Scanning
  • disadvantage: mixing two views

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 28/54

slide-29
SLIDE 29

Process Interaction Simulation Kernel

  • Thomas J. Schriber. Simulation Using GPSS “The Red Book”. Wiley,

1974.

  • Thomas J. Schriber. Simulation Using GPSS/H. Wiley, 1990.
  • http://isgwww.cs.uni-magdeburg.de/˜pelo/s1e/sa5/sa52.shtml
  • GPSS World http://www.minutemansoftware.com/
  • AToM3 modelling GUI http://atom3.cs.mcgill.ca/

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 29/54

slide-30
SLIDE 30

GPSS Process Interaction Simulation Kernel

Data Structures: chains. A transactions is on exactly one chain at a time !

  • (1) Current Events Chain (CEC):

Transactions, waiting for a condition, at current time.

  • (1) Future Events Chain (FEC):

Transactions waiting for a known future time.

  • (0 . . . n) User Chain (UC):

Transactions waiting to be UNLINKed by a user transaction.

  • (0 . . . m) Interrupt Chain (IC):

Transactions waiting for the end of an interrupt.

  • (0 . . . p) Match Chain (MC):

Transactions waiting for a (Match, Assemble, Gather) rendezvous.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 30/54

slide-31
SLIDE 31

Transaction Life

  • A transaction moves through GPSS blocks (as far as possible).
  • Internally, its structure is on exactly one of the chains.
  • Structure of a transaction:

unique Xact ID, current block, next block (attempt), move time, priority, . . .

  • Ordering:

– On CEC: decreasing priority. – On FEC: increasing move time, FIFO(FCFS) irrespective of priority.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 31/54

slide-32
SLIDE 32

Process Interaction: Transaction Life

Transaction Creation Transaction Destruction

IAT=0 CEL FEL

ADVANCE move time = clock time TERMINATE Y N Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 32/54

slide-33
SLIDE 33

GPSS Process Interaction Simulation Procedure

Initializations

  • utput

performance metrics; cleanup; ...

FEL: [xact1,x1ct2, ...] CEL xact1’ xact2’ xact3’ . . .

increasing move-time increasing priority

start end Clock Update Phase Scan Phase

more xacts to move ? terminate simulation ?

current time = move time of first xact on Future Events List (FEL) transfer all xacts with move-time = current time to the Current Events List;

  • rder by priority

move next object on CEL through as far as possible through its process description Process Interaction model (e.g., GPSS block diagram)

GENERATE 10, 5 QUEUE wait SEIZE cashier DEPART wait ADVANCE 5, 3 RELEASE cashier TERMINATE 1

5,3 Q

Q

Y N Y N

10,5

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 33/54

slide-34
SLIDE 34

Operational Semantics of Process-oriented Simulation Languages: πDemos

  • Simula-style
  • Operational semantics (Plotkin)
  • Scheduling of Events, Synchronisation
  • Birtwistle and Tofts (SCS Transactions, 10(4), 1994, 299-333)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 34/54

slide-35
SLIDE 35

Cashier-Queue: GPSS Process Interaction View

GENERATE 10, 5 QUEUE wait SEIZE cashier DEPART wait ADVANCE 5, 3 RELEASE cashier TERMINATE 1

10,5 5,3

Q Q

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 35/54

slide-36
SLIDE 36

Process Interaction (dis)advantages

  • advantage: declarative model, high-level “process view”
  • disadvantage: rather inefficient

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 36/54

slide-37
SLIDE 37

General disadvantages

  • (here) not formally defined, is possible
  • non-modular, is possible

DEVS formalism

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 37/54

slide-38
SLIDE 38

World Views: Classification

‘‘Discrete’’ Formalisms Discrete Event Formalisms Statecharts DEVS Event Scheduling Activity Scanning Process Interaction Discrete Time Formalisms Finite State Automata Difference Equations Three Phase Approach

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 38/54

slide-39
SLIDE 39

(Pseudo-) Random-number Generators

  • SYS model is deterministic + random constructs
  • randomness

not enough detail known or don’t care

  • randomness: characterized by distribution
  • In SYS: draw from distribution and

Monte-Carlo run multiple deterministic simulations.

  • Alternatives:

– Transform to deterministic. – Markov Chains (analytical).

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 39/54

slide-40
SLIDE 40

Probability Distributions

  • Continuous vs. discrete
  • Probability Density Function ( f

x

)

  • Cumulative Probability Function (F

X

)

  • see probability course: Poisson, Erlang, . . .

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 40/54

slide-41
SLIDE 41

Pseudo-random

  • Sample from distribution (U
✞ ✄

1

)

  • Reproducability/comparison of experiments !

– science needs reproducable results – makes debugging easier – identical random numbers to compare different systems

  • Quality of generator:

– appear uniformly distributed – non-correlated – fast and doesn’t need much storage – long period, dense (full) coverage – provision for streams (subsegments)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 41/54

slide-42
SLIDE 42

Linear Congruential Generators

Zi

✠ ✞

aZi

1

c

mod m m is modulus a is multiplier c is increment Z0 is seed c

0 is called multiplicative LCG

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 42/54

slide-43
SLIDE 43

Generators ctd.

  • Composite Generators
  • Tausworthe generators (operate on bits)
  • L

’Ecuyer, Devroye (non-uniform)

  • Testing RNG: empirical vs. theoretical
  • References: Knuth, Law & Kelton

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 43/54

slide-44
SLIDE 44

Marse and Roberts’ portable RNG

Z

i

☞ ✠ ✞

630360016

Z

i

1

☞ ✟

mod

231

1

  • Prime modulus multiplicative linear congruential generator.
  • Based on Fortran UNIRAN code.
  • Multiple (100) streams are supported with seeds spaced 100,000 apart.
  • Include file: rand.h
  • C file: rand.c
  • Example use: randtest.c

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 44/54

slide-45
SLIDE 45

Non-uniform continuously distributed RNG

Inverse Transformation Method

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 45/54

slide-46
SLIDE 46

Gathering Statistics (report generation)

  • 1. counters
  • 2. summary measures
  • 3. utilization
  • 4. occupancy
  • 5. distributions and transit times

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 46/54

slide-47
SLIDE 47

Counters

In all previous examples: keep/update counters (as state vars) !

  • numbers of entities of different types in the system
  • number of times a particular event occurred
  • basis for statistics (performance metrics)

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 47/54

slide-48
SLIDE 48

Summary Measures

  • minima and maxima:

compare new values to current min and max, update when necessary

  • mean of a set of N observations xi

i

1

2

✄✎✍ ✍ ✍ ✄

N m

1 N

N

i

1

xi

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 48/54

slide-49
SLIDE 49

Summary Measures (ctd.)

  • standard deviation (from mean)

s

1 N

1

N

i

1

m

xi

2

– need to calculate m first

need to keep all observations

– sum of squares may grow very large (accuracy

)

N

i

1

m

xi

2

N

i

1

x2

i

Nm2

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 49/54

slide-50
SLIDE 50

Utilization

The fraction (or %) of time each individual entity is engaged

idle busy t_b t_e t_start t_end t_b t_e 1 2 i N time

U

1 tend

tstart

N

i

1

te

tb

i

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 50/54

slide-51
SLIDE 51

Average Use and Occupancy

for groups and classes of entities

t_i t_i+1 t_start t_end t_b t_e time 2 4 6 n MAX i n_i

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 51/54

slide-52
SLIDE 52

Average Use and Occupancy (ctd.)

  • Average use over time (ti are times of change)

A

1 tend

tstart

N

i

1

ni

ti

1

ti

Example use: average queue length.

  • Occupancy: average number in use with respect to MAX

O

A MAX

No bookkeeping of individual entity information required, only total use (ni) and when change occurs. This, as opposed to for example average transit time computation where individual times must be kept.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 52/54

slide-53
SLIDE 53

Distributions and Transit Times

underflow zone

  • verflow

zone N intervals L L+∆ L+2∆ L+(N-1)∆ ∆

...

Lower Limit Upper Limit

Number of intervals N, Uniform interval size ∆, Lower tabulation limit L. Implementation: table of interval counters. Global accumulation: number of entries, sum of entries, sum of squares.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 53/54

slide-54
SLIDE 54

Distributions and Transit Times (ctd.)

  • Transit times: use clock as time stamp, enter in table at end of transit.
  • Distribution of number of entitities: measure at uniform intervals of time.

Hans Vangheluwe hv@cs.mcgill.ca Modelling and Simulation: Discrete Event WorldViews 54/54