eecs 144/244: fundamental algorithms for system · pdf filegna l = > s upe r-ense me ......

118
Fundamental Algorithms Fundamental Algorithms for System Modeling, Analysis, and Optimization Stavros Tripakis, Edward A. Lee UC B kl UC Berkeley EECS 144/244 Fall 2013 Copyright © 2013 E A Lee J Roydhowdhury SA Seshia S Tripakis Copyright © 2013, E. A. Lee, J. Roydhowdhury, S. A. Seshia, S. Tripakis All rights reserved Discrete Event Simulation Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 1 / 66

Upload: vunhu

Post on 06-Feb-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Fundamental AlgorithmsFundamental Algorithms for System Modeling, Analysis, and Optimization

Stavros Tripakis, Edward A. LeeUC B k lUC BerkeleyEECS 144/244Fall 2013

Copyright © 2013 E A Lee J Roydhowdhury S A Seshia S TripakisCopyright © 2013, E. A. Lee, J. Roydhowdhury, S. A. Seshia, S. TripakisAll rights reserved

Discrete Event Simulation

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 1 / 66

Page 2: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Timed Systems

In embedded / cyber-physical systems, timing is key:

I proper timing = an issue of correctness

I the right values, at the right time (not too late, not too early).

C.f.: real-time controllers (automotive, robotic surgeon, ...).

Contrast this to personal computers: “best-effort” systems –timing an issue of performance.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 2 / 66

Page 3: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

(Timed) Discrete-Event (DE) Systemsvs. Continuous Control Systems

Continuous control systems:

I Coming from continuous system theory.

I Typically implemented by periodic sampling controllers (alsoevent-driven controllers): these are discrete, but try toapproximate the continuous ones.

Discrete-event systems:

I More “sparse” events (typically).

I Discrete control: e.g., mode switches.

I Typically higher level: e.g., supervisory control (DE) vs. cruisecontrol (continuous).

I Other application domains:I Queueing theory.I Circuits (VHDL, Verilog, SystemC).

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 3 / 66

Page 4: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: controller and monitor for an avionic electric power systemp y

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 3 / 66

Page 5: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: controller and monitor for an avionic electric power systemp y

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 3 / 66

Page 6: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: simple light controller modeled as a timedautomaton

off medium brighttouch

c := 0

touch

c < 2

touch

c ≥ 2

touch

Input event: “touch”.

Output: light (“off”, “medium”, “bright”).

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 6 / 66

Page 7: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: circuit timing modeled with timed automata

fi v�� � � � �vk� � �Ci �� �

fi v�� � � � �vk� � ��Ci �� �

vi � vi � �

fi v�� � � � �vk� � fi v�� � � � �vk� � �

vi � � �Ci � li

vi � �

vi �

vi � � �Ci � ui

vi � �Ci � ui

vi � �Ci � li

Fig� �� The two automata Ai and Ai associated with each equation

Sketch of Proof� By combining what claim � tells us about Ci and vi� whatclaim � tells us about their in�uence on vi� with the compositionality of ��claim � we obtain a characterization equivalent to de�nition � ut

Theorem� �Main Result�� Every k�wire circuit can be transformed into anequivalent timed automaton with �k variables and k clocks�

Proof� Given a system of delay inclusions� we create the corresponding systemof timed automata and compose them� obtaining

A �kO

i �

�Ai �Ai� � A � �V �V� C�R�O�

as described above� whose set of observable behaviors L�A��V� is exactly the setof solutions� utExample� Consider the simple circuit in �gure � We model x� as an oscillatorwith parameters l� and u�� Initially we obtain the four ��state automataA�� A��A� and A� whose R and O are written in table � After composing A� with A�

and A� with A� �and removing states and transitions whose R is false � theseindicate unstable states in which the automaton cannot stay for a non�zero

From [Maler and Pnueli(1995)].

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 7 / 66

Page 8: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: car wash

Taken from [Misra(1986)]:

I Source generates car arrivals at some arbitrary times.

I Attendant directs cars to car wash stations CW1 or CW2:

I if both CW1 and CW2 are free, then to CW1;I if only one is free, then to this one;I otherwise car waits until a station becomes free.I Cars are served by attendant in FIFO order.

I CW1 spends 8 mins to wash a car.

I CW2 spends 10 mins to wash a car.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 8 / 66

Page 9: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

This week: discrete-event systems

Fundamental models and algorithms:

I Discrete-event simulation.

I Model-checking (reachability) for timed automata: basicprinciples.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 9 / 66

Page 10: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Recap: different ways to look at systems

operational denotational

monolithic automata, machines,transition systems, ...

functions (on values,streams, signals, ...),equations

compositional products of automata,etc.

function composition,sets of equations,fixpoints

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 10 / 66

Page 11: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. Discrete Event Systems

I Continuous systems: functions on continuous signals.Continuous signal x = continuous function of dense time (R+)

x : R+ → V

x(t): value of x at time t; belongs to some set of values V (e.g., R)

I Timed Discrete Event Systems: deal with timed discrete-eventsignals.Timed discrete-event signal: sequence of timed events.

continuoussystem

time

e6 e7 e8

t6 t7 t8

· · ·

e1 e2 e3 e4 e5

t1 t2 t3 t4 t5 time

· · ·systemevent

discrete

timetime

· · ·

· · ·

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 11 / 66

Page 12: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Timed Events

Main notion: event

I something occurring at some point in time

I may also carry a value

I event = (timestamp, value)

I systems are viewed as consumers/producers of event streams

-

6 6 6 6 6 - --

6 6 6

e1 e2 e3 e4 e5

t1 t2 t3 t4 t5 time

· · · system

time

e6 e7 e8

t6 t7 t8

· · ·

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 12 / 66

Page 13: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

DIGRESSION:

EVENTS vs. STATES

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 13 / 66

Page 14: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From States to Events

If my formalism only has the notion of state, can I define events?

Event = change of state

Example: Lustre program

node UpwardEdge (X : bool) returns (E : bool);

let

E = false -> X and not pre X ;

tel

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 14 / 66

Page 15: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From States to Events

If my formalism only has the notion of state, can I define events?

Event = change of state

Example: Lustre program

node UpwardEdge (X : bool) returns (E : bool);

let

E = false -> X and not pre X ;

tel

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 14 / 66

Page 16: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From States to Events

If my formalism only has the notion of state, can I define events?

Event = change of state

Example: Lustre program

node UpwardEdge (X : bool) returns (E : bool);

let

E = false -> X and not pre X ;

tel

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 14 / 66

Page 17: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From Events to States

If my formalism only has events as primitives, can I define state?

State = history of events observed so farFormally:

I Σ: set of events

I Σ∗: set of finite event sequences = histories

I Every s ∈ Σ∗ can be seen as a state

C.f. a famous theorem:

Theorem (Myhill-Nerode theorem)A language L ⊆ Σ∗ is regular iff the equivalence relation over words

s ∼L s′ =̂ ∀s′′ ∈ Σ∗ : s · s′′ ∈ L⇔ s′ · s′′ ∈ L

has a finite set of equivalence classes. The number of equivalence classesof ∼L is the number of states in the smallest DFA recognizing L.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 15 / 66

Page 18: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From Events to States

If my formalism only has events as primitives, can I define state?

State = history of events observed so far

Formally:

I Σ: set of events

I Σ∗: set of finite event sequences = histories

I Every s ∈ Σ∗ can be seen as a state

C.f. a famous theorem:

Theorem (Myhill-Nerode theorem)A language L ⊆ Σ∗ is regular iff the equivalence relation over words

s ∼L s′ =̂ ∀s′′ ∈ Σ∗ : s · s′′ ∈ L⇔ s′ · s′′ ∈ L

has a finite set of equivalence classes. The number of equivalence classesof ∼L is the number of states in the smallest DFA recognizing L.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 15 / 66

Page 19: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From Events to States

If my formalism only has events as primitives, can I define state?

State = history of events observed so farFormally:

I Σ: set of events

I Σ∗: set of finite event sequences = histories

I Every s ∈ Σ∗ can be seen as a state

C.f. a famous theorem:

Theorem (Myhill-Nerode theorem)A language L ⊆ Σ∗ is regular iff the equivalence relation over words

s ∼L s′ =̂ ∀s′′ ∈ Σ∗ : s · s′′ ∈ L⇔ s′ · s′′ ∈ L

has a finite set of equivalence classes. The number of equivalence classesof ∼L is the number of states in the smallest DFA recognizing L.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 15 / 66

Page 20: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

From Events to States

If my formalism only has events as primitives, can I define state?

State = history of events observed so farFormally:

I Σ: set of events

I Σ∗: set of finite event sequences = histories

I Every s ∈ Σ∗ can be seen as a state

C.f. a famous theorem:

Theorem (Myhill-Nerode theorem)A language L ⊆ Σ∗ is regular iff the equivalence relation over words

s ∼L s′ =̂ ∀s′′ ∈ Σ∗ : s · s′′ ∈ L⇔ s′ · s′′ ∈ L

has a finite set of equivalence classes. The number of equivalence classesof ∼L is the number of states in the smallest DFA recognizing L.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 15 / 66

Page 21: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

END DIGRESSION

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 16 / 66

Page 22: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

MODELING CONSIDERATIONS

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 17 / 66

Page 23: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Tagged signals

Tagged signal model (TSM)[Lee and Sangiovanni-Vincentelli(1998)]:

signal s = a set of events with timestamps:

s ⊆ T × V

where:

I T : set of tags (= timestamps)

I V : set of values.

Time T could be:

I discrete/“logical” (N),

I continuous/dense (R+),

I or even “superdense” (R+ × N)

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 18 / 66

Page 24: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example Motivating the Need for Simultaneous E t Withi Si l > S D TiEvents Within a Signal => Super-Dense Time

Newton’s Cradle:Newton s Cradle:Steel balls on strings.

Collisions are events.

Momentum of the middle ball has three values atMomentum of the middle ball has three values at the time of collision.

Other examples: Batch arrivals at a queue. Software sequences abstracted as instantaneous. Transient states.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 18 / 66

Page 25: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Super-Dense Timep

Lexicographic orderLexicographic order

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 18 / 66

Page 26: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Intuition:

Discrete: only finite number of events can happen in a finiteamount of time.

Continuous: not discrete.

Let’s try to formalize this intuition.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 21 / 66

Page 27: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Intuition:

Discrete: only finite number of events can happen in a finiteamount of time.

Continuous: not discrete.

Let’s try to formalize this intuition.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 21 / 66

Page 28: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Intuition:

Discrete: only finite number of events can happen in a finiteamount of time.

Continuous: not discrete.

Let’s try to formalize this intuition.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 21 / 66

Page 29: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Let T = R+, the set of non-negative reals.

Lets ⊆ R+ × V

be a signal.

Let t(s) be the set of all tags of signal s:

t(s) = {t | ∃(t, v) ∈ s}

I s is discrete if t(s) is order-isomorphic to a subset of N, whereN = {0, 1, 2, ...} is the set of natural numbers.

I Otherwise, s is continuous.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 22 / 66

Page 30: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Let T = R+, the set of non-negative reals.

Lets ⊆ R+ × V

be a signal.

Let t(s) be the set of all tags of signal s:

t(s) = {t | ∃(t, v) ∈ s}

I s is discrete if t(s) is order-isomorphic to a subset of N, whereN = {0, 1, 2, ...} is the set of natural numbers.

I Otherwise, s is continuous.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 22 / 66

Page 31: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Order-isomorphisms

A order-isomorphic B means there is an order-preserving bijectionf : A→ B.

In our case the order is the usual < on R+ and N. So:

I f must be a bijection: (1) f(a) must be defined for all a ∈ A,(2) for all b ∈ B there must exist a ∈ A such that f(a) = b,and (3) a 6= a′ ⇒ f(a) 6= f(a′).

I f must be order-preserving: a < a′ ⇒ f(a) < f(a′).

Is N× N (with lexicographic order) order-isomorphic to N ?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 23 / 66

Page 32: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Order-isomorphisms

A order-isomorphic B means there is an order-preserving bijectionf : A→ B.

In our case the order is the usual < on R+ and N. So:

I f must be a bijection: (1) f(a) must be defined for all a ∈ A,(2) for all b ∈ B there must exist a ∈ A such that f(a) = b,and (3) a 6= a′ ⇒ f(a) 6= f(a′).

I f must be order-preserving: a < a′ ⇒ f(a) < f(a′).

Is N× N (with lexicographic order) order-isomorphic to N ?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 23 / 66

Page 33: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}?

Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 34: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 35: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }?

Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 36: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 37: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}?

Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 38: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 39: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}?

Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 40: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 41: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}?

Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 42: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 43: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}?

Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 44: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 45: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}?

Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 46: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continous and discrete signals

Are the signals below discrete or continuous?

s1 = {(t, t) | t ∈ R+}? Continuous.

s2 = {(n, v) | n ∈ N, v ∈ V }? Discrete.

s3 = {(0, 0), (1, 1, ), (2, 2)}? Discrete.

s4 = {(0.3, 0), (1.27, 1, ), (2π, 2)}? Discrete.

s5 = {}? Discrete.

s6 = {(t, t) | t ∈ [0, 1]}? Continuous.

s7 = {(t, btc) | t ∈ R+}? Continuous, according to ourdefinition. Could also be considered discrete since it’s piecewiseconstant. This is how discrete signals are modeled in Simulink.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 24 / 66

Page 47: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Continuous vs. discrete signals

Lets ⊆ R+ × V

be a signal.

Let t(s) be the set of all tags of signal s:

t(s) = {t | ∃(t, v) ∈ s}

I s is discrete if t(s) is order-isomorphic to a subset of N,where N = {0, 1, 2, ...} is the set of natural numbers.

I Otherwise, s is continuous.

Does the above definition capture our original intuition? (discrete⇒ finite # events in a finite amount of time

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 25 / 66

Page 48: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: bouncing ball

Jie Liu and Edward A. Lee

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 25 / 66

Page 49: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: bouncing ball Zeno system: infinite # of discrete events in a finite amount of time => time blocked.

Jie Liu and Edward A. Lee

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 25 / 66

Page 50: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Zeno

Zeno’s “Achilles and the tortoise” paradox:

I Achilles and the tortoise enter a race. Achilles runs of coursemuch faster. He graciously allows the tortoise a head start of1 meter. Who will win?

“In a race, the quickest runner can never overtake the slowest,since the pursuer must first reach the point whence thepursued started, so that the slower must always hold a lead.”

(from wikipedia)

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 28 / 66

Page 51: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Zeno

Zeno’s “Achilles and the tortoise” paradox:

I Achilles and the tortoise enter a race. Achilles runs of coursemuch faster. He graciously allows the tortoise a head start of1 meter. Who will win?

“In a race, the quickest runner can never overtake the slowest,since the pursuer must first reach the point whence thepursued started, so that the slower must always hold a lead.”

(from wikipedia)

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 28 / 66

Page 52: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Zeno DE systems

A DE system is zeno if it generates an infinite number of events in a finiteamount of time:

��7

Lee 12: 19

Zeno Signals

Eventually, execution stops advancing time. Why?

Note that if the Ramp is set to produce integer outputs, then eventually the output will overflow and become negative, which will cause an exception.

Lee 12: 20

Taking Stock

�� The discrete-event model of computation is useful for modeling and design of time-based systems.

�� In DE models, signals are time-stamped events, and events are processed in chronological order.

�� Simultaneous events and Zeno conditions create subtleties that the semantics will have to deal with.

Zeno systems are sometimes useful (c.f., bouncing ball) but often an error of

modeling. We will see how to avoid it in DE simulation, to avoid blocking time

globally.Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 29 / 66

Page 53: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete vs. dense time

Can we model time using “untimed” models (e.g., statemachines)? How?

A: using counters.

Example: a watchdog that checks that an event happens within adeadline

node Watchdog (X : bool, D : int) returns (W : bool);

let

counter = 0 -> (pre counter) + 1;

seenX = X or (false -> pre seenX);

W = (not seenX) and (counter > D);

tel

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 30 / 66

Page 54: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete vs. dense time

Can we model time using “untimed” models (e.g., statemachines)? How?A: using counters.

Example: a watchdog that checks that an event happens within adeadline

node Watchdog (X : bool, D : int) returns (W : bool);

let

counter = 0 -> (pre counter) + 1;

seenX = X or (false -> pre seenX);

W = (not seenX) and (counter > D);

tel

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 30 / 66

Page 55: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete vs. dense time

Why then not use N as our time axis?

I Expressiveness: some things (we will see next) cannot bemodeled in discrete time.

I Symbolic reasoning: reason with arbitrary delays rather thancount one step at a time.

I more efficient for simulationI still not proven better for exhaustive verification.

However, the discrete vs. dense-time debate is not over yet ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 31 / 66

Page 56: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?I For the same reason Turing machines are a useful abstraction

of reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 57: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?I For the same reason Turing machines are a useful abstraction

of reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 58: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?I For the same reason Turing machines are a useful abstraction

of reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 59: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?

I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?I For the same reason Turing machines are a useful abstraction

of reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 60: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?

I For the same reason Turing machines are a useful abstractionof reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 61: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dense-Time Delay

- - 6 6 66

--

6 6 66Delay: 1

e1 e2 e4e3

R+

· · ·

2 2.9 3.5 5.1

e1 e2 e4

1 1.9 4.1

e3

· · ·

R+2.5

I Can this system be modeled in discrete time?

I No: must choose some ∆t as time step, but input eventscould arrive closer.

I Is the Delay a realistic component?I Most physical systems can handle only limited burstiness.I If too many events arrive in too short time, some will be

discarded or delayed more than a constant delay.

I Why then use Delay?I For the same reason Turing machines are a useful abstraction

of reality.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 32 / 66

Page 62: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Delay vs. Server

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 33 / 66

Page 63: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Delay vs. Server

Are CW1, CW2 delays or servers?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 34 / 66

Page 64: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Models (DE)

Networks of timed actors, such as Delay, Server, sources, sinks, ...

model 1 (drawing) model 2 (ptolemy)

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 35 / 66

Page 65: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Analysis of DE Models

model 1 (drawing) model 2 (ptolemy)

I We will look at simulation of DE models.

I Exhaustive verification (model-checking): open researchproblem!Recent work: [Stergiou et al. 2013].

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 36 / 66

Page 66: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Analysis of DE Models

model 1 (drawing) model 2 (ptolemy)

Note: in HW industry simulation and verification mean something else:

I “simulation”: generate a behavior and allow user to observe it

I “verification”: generate one or more behaviors (e.g., randomly) andcheck that each satisfies a property

I “formal verification”: exhaustive or bounded model-checking

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 37 / 66

Page 67: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

DISCRETE-EVENT SIMULATION

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 38 / 66

Page 68: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation: Basic Idea

Standard DE simulation scheme:

1: t := 0; // initialize simulation time to 02: initialize global event queue Q with a set of initial events;

// events in Q ordered by timestamp3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te; // advance global time6: execute event e: update system state, generate possible

future events, and add them to Q, ordered by timestamps;7: end while

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 39 / 66

Page 69: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: Clock and Delay

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e;7: end while

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 40 / 66

Clock period: 0.6ci: events generated by Clockdi: events generated by Delay

Page 70: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Example: Clock and Delay

point in algo t Q current event eafter initialization (step 2) 0 [(c0, 0), (c1, 0.6), (c2, 1.2), ...]

after step 4 [(c1, 0.6), (c2, 1.2), ...] (c0, 0)after step 5 [(c1, 0.6), (d0, 1.0), (c2, 1.2), ...]after step 6 0after step 4 [(d0, 1.0), (c2, 1.2), ...] (c1, 0.6)after step 5 [(d0, 1.0), (c2, 1.2), (d1, 1.6), ...]after step 6 0.6after step 4 [(c2, 1.2), (d1, 1.6), ...] (d0, 1.0)after step 5 Q does not change, but

something gets printedafter step 6 1.0· · ·

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 41 / 66

Clock period: 0.6ci: events generated by Clockdi: events generated by Delay

Page 71: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation: Issues

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e: update system state, generate possible future

events, and add them to Q, ordered by timestamps;7: end while

I Appears intuitive, but details are left unspecified (steps 2, 6).

I Scheme is not modular: step 6 appears to work on the entire systemstate, not on individual actors.

I How to make such a scheme completely modular is an active topic(we will come back to this).

Let’s try to flesh out the details.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 42 / 66

Page 72: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation: Issues

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e: update system state, generate possible future

events, and add them to Q, ordered by timestamps;7: end while

I Appears intuitive, but details are left unspecified (steps 2, 6).

I Scheme is not modular: step 6 appears to work on the entire systemstate, not on individual actors.

I How to make such a scheme completely modular is an active topic(we will come back to this).

Let’s try to flesh out the details.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 42 / 66

Page 73: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Modeling Source Actors

Source actor = an actor with no inputs.

Clock is a source:

I Option 1 – sources generate all their events at initialization.I Simulation time is finite, so presumably only finite number of

events.I But it may be very large.

I Option 2 – model sources using feedback loops with initial events:

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 43 / 66

Page 74: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Modeling Source Actors

Source actor = an actor with no inputs.

Clock is a source:

I Option 1 – sources generate all their events at initialization.I Simulation time is finite, so presumably only finite number of

events.I But it may be very large.

I Option 2 – model sources using feedback loops with initial events:

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 43 / 66

Page 75: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Modeling Source Actors

Source actor = an actor with no inputs.

Clock is a source:

I Option 1 – sources generate all their events at initialization.I Simulation time is finite, so presumably only finite number of

events.I But it may be very large.

I Option 2 – model sources using feedback loops with initial events:

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 43 / 66

Page 76: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Feedback loops are necessary in general

Example: car wash (taken from [Misra(1986)]):

I Source generates car arrivals at some arbitrary times (e.g., at times 3, 8,9, 14, 16, 22)

I Attendant directs cars to car wash stations CW1 or CW2:

I if both CW1 and CW2 are free, then to CW1I if only one is free, then to this oneI otherwise car waits until a station becomes freeI cars are served by attendant in FIFO order

I CW1 (a server actor) spends 8 mins to wash a car

I CW2 (a server actor) spends 10 mins to wash a car

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 44 / 66

Page 77: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

But feedback loops can also be dangerous ...

��7

Lee 12: 19

Zeno Signals

Eventually, execution stops advancing time. Why?

Note that if the Ramp is set to produce integer outputs, then eventually the output will overflow and become negative, which will cause an exception.

Lee 12: 20

Taking Stock

�� The discrete-event model of computation is useful for modeling and design of time-based systems.

�� In DE models, signals are time-stamped events, and events are processed in chronological order.

�� Simultaneous events and Zeno conditions create subtleties that the semantics will have to deal with.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 45 / 66

Page 78: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Avoiding Zeno Systems

Suppose we add a (constant, or at least bounded from below)non-zero delay in every feedback loop:

Is it sufficient to avoid zenoness?

Yes. Exercise: prove it.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 46 / 66

Page 79: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Avoiding Zeno Systems

Suppose we add a (constant, or at least bounded from below)non-zero delay in every feedback loop:

Is it sufficient to avoid zenoness?

Yes. Exercise: prove it.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 46 / 66

Page 80: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Handling Feedback Loops

I Option 1 – avoid zero-delay loops as above (this also ensuresnon-zenoness).

I Option 2 – use a fixpoint semantics (e.g., see [Lee(1999)] orEECS 219D)

We will not discuss the fixpoint semantics for DE.We assume Option 1.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 47 / 66

Page 81: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Handling Feedback Loops

I Option 1 – avoid zero-delay loops as above (this also ensuresnon-zenoness).

I Option 2 – use a fixpoint semantics (e.g., see [Lee(1999)] orEECS 219D)

We will not discuss the fixpoint semantics for DE.We assume Option 1.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 47 / 66

Page 82: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Example: Alarm

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t.

I How does the DE simulation algorithm handle this example?

I It appears that Alarm should post an initial event with time t

... but this event may then have to be canceled duringsimulation if something arrives at the input before t.

I Canceling events = removing them from the event queue.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 48 / 66

Page 83: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Example: Alarm

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t.

I How does the DE simulation algorithm handle this example?

I It appears that Alarm should post an initial event with time t

... but this event may then have to be canceled duringsimulation if something arrives at the input before t.

I Canceling events = removing them from the event queue.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 48 / 66

Page 84: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Example: Alarm

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t.

I How does the DE simulation algorithm handle this example?

I It appears that Alarm should post an initial event with time t

... but this event may then have to be canceled duringsimulation if something arrives at the input before t.

I Canceling events = removing them from the event queue.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 48 / 66

Page 85: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Example: Alarm

Some complex model Alarm Sinkcancel alarm

Note:

I Whether an event will be generated before t is not always easyto determine.

I DE algorithm must work independently of how Alarm isconnected.

I That’s what modular means.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 49 / 66

Page 86: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation – version 2

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e: update system state, generate possible

future events, and add them to Q, ordered by timestamps;possibly remove events from Q;

7: end while

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 50 / 66

Page 87: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Issue: Simultaneous Events

The AddSubtract actor is supposed to behave as follows:

I If it receives two simultaneous events, it adds/subtracts their valuesand produces a single event at its output with the resulting value.

I If it receives an event in just one of the two inputs, it simplyforwards it.

Suppose the two SingleEvent actors produce two simultaneous events.

What should the output be?

An event with value x− x = 0.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 51 / 66

Page 88: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Issue: Simultaneous Events

The AddSubtract actor is supposed to behave as follows:

I If it receives two simultaneous events, it adds/subtracts their valuesand produces a single event at its output with the resulting value.

I If it receives an event in just one of the two inputs, it simplyforwards it.

Suppose the two SingleEvent actors produce two simultaneous events.

What should the output be? An event with value x− x = 0.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 51 / 66

Page 89: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Another Issue: Simultaneous Events

How to achieve the desired behavior with the DE simulationalgorithm?

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e: update system state, generate possible future events,

and add them to Q, ordered by timestamps; possibly remove eventsfrom Q;

7: end while

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 52 / 66

Page 90: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation – version 3

It appears that the DE simulation algorithm must execute sets ofsimultaneous events, instead of one event at a time:

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) set E of all (?) simultaneous

earliest events from Q;5: t := te;6: execute event e set of events E: update system state, generate

possible future events, and add them to Q, ordered by timestamps;possibly remove events from Q;

7: end while

Not as simple ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 53 / 66

Page 91: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation – version 3

It appears that the DE simulation algorithm must execute sets ofsimultaneous events, instead of one event at a time:

1: t := 0;2: initialize global event queue Q with a set of initial events;3: while Q is not empty do4: remove earliest event e = (ve, te) set E of all (?) simultaneous

earliest events from Q;5: t := te;6: execute event e set of events E: update system state, generate

possible future events, and add them to Q, ordered by timestamps;possibly remove events from Q;

7: end while

Not as simple ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 53 / 66

Page 92: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneousevents.Should these be processed together by the algorithm?

No: AddSubtract needs to wait for the output of Scale.

Processing a set of simultaneous events E may result in newsimultaneous events not in E ...

We need some systematic way to do this ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 54 / 66

Page 93: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneousevents.Should these be processed together by the algorithm?

No: AddSubtract needs to wait for the output of Scale.

Processing a set of simultaneous events E may result in newsimultaneous events not in E ...

We need some systematic way to do this ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 54 / 66

Page 94: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneousevents.Should these be processed together by the algorithm?

No: AddSubtract needs to wait for the output of Scale.

Processing a set of simultaneous events E may result in newsimultaneous events not in E ...

We need some systematic way to do this ...

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 54 / 66

Page 95: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Back to the Alarm Example

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t

I What if Source produces an event also at time t?

I According to the semantics of Alarm, it should not raise analarm event.

I Does the DE simulation algorithm guarantee this?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 55 / 66

Page 96: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Back to the Alarm Example

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t

I What if Source produces an event also at time t?

I According to the semantics of Alarm, it should not raise analarm event.

I Does the DE simulation algorithm guarantee this?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 55 / 66

Page 97: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Back to the Alarm Example

Source Alarm Sinkcancel alarm

I Alarm actor: produces event at given time t, unless it receivesinput at time t′ ≤ t

I What if Source produces an event also at time t?

I According to the semantics of Alarm, it should not raise analarm event.

I Does the DE simulation algorithm guarantee this?

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 55 / 66

Page 98: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Back to the Alarm Example

Source Alarm Sinkcancel alarm

1: t := 0;2: initialize global event queue Q with {(alarm, t), (cancel, t)};3: while Q is not empty do4: remove earliest event e = (ve, te) from Q;5: t := te;6: execute event e: update system state, generate possible future

events, and add them to Q, ordered by timestamps; possiblyremove events from Q;

7: end while

I Non-determinism!I Different results depending on which of the two instantaneous

events (alarm, t) and (cancel, t) is first removed from Q.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 56 / 66

Page 99: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dealing with Simultaneous Events

Source Alarm Sinkcancel alarm

I Chronological ordering (= ordering by timestamps) of eventsin the queue is not enough.

I Must also respect dependencies between simultaneous eventsI Alarm’s output event at time t depends on Source’s output

event at time t

I How to define event dependencies?

I First let’s formalize actor dependencies.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 57 / 66

Page 100: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dealing with Simultaneous Events

Source Alarm Sinkcancel alarm

I Chronological ordering (= ordering by timestamps) of eventsin the queue is not enough.

I Must also respect dependencies between simultaneous eventsI Alarm’s output event at time t depends on Source’s output

event at time t

I How to define event dependencies?

I First let’s formalize actor dependencies.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 57 / 66

Page 101: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dependency Relation among Actors

Let A1, A2 be two actors.

Define the precedence relation A1 → A2 (A2 depends on A1) asfollows:

A1 → A2 =̂ A1 is zero-delay and there is a connection from anoutput of A1 to an input of A2 in the model.

Claim: → is acyclic.

Why? Because every loop is assumed to have a non-zero-delayactor.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 58 / 66

Page 102: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dependency Relation among Actors

Let A1, A2 be two actors.

Define the precedence relation A1 → A2 (A2 depends on A1) asfollows:

A1 → A2 =̂ A1 is zero-delay and there is a connection from anoutput of A1 to an input of A2 in the model.

Claim: → is acyclic.

Why?

Because every loop is assumed to have a non-zero-delayactor.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 58 / 66

Page 103: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Dependency Relation among Actors

Let A1, A2 be two actors.

Define the precedence relation A1 → A2 (A2 depends on A1) asfollows:

A1 → A2 =̂ A1 is zero-delay and there is a connection from anoutput of A1 to an input of A2 in the model.

Claim: → is acyclic.

Why? Because every loop is assumed to have a non-zero-delayactor.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 58 / 66

Page 104: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Actor Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink.

We will not need Source → Alarm.

Scale → AddSubtract → TimedPlotter.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 59 / 66

Page 105: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Actor Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink.

We will not need Source → Alarm.

Scale → AddSubtract → TimedPlotter.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 59 / 66

Page 106: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Precedence Relation on Events

Let e1 = (v1, t1) and e2 = (v2, t2) be two events.

Let A1 and A2 be the recipient actors of e1 and e2:

I This information can be encoded in v1, v2.I We assume a unique recipient per event.

I No loss of generality: can view fan-out junctions as zero-delayactors which copy every input event to all their outputs.

We define precedence of events e1, e2:

e1 ≺ e2 =̂ t1 < t2 or(t1 = t2 and A1 →∗ A2 and A1 6= A2

)where →∗ is the transitive closure of →.

Claim: ≺ is acyclic.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 60 / 66

Page 107: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Precedence Relation on Events

Let e1 = (v1, t1) and e2 = (v2, t2) be two events.

Let A1 and A2 be the recipient actors of e1 and e2:

I This information can be encoded in v1, v2.I We assume a unique recipient per event.

I No loss of generality: can view fan-out junctions as zero-delayactors which copy every input event to all their outputs.

We define precedence of events e1, e2:

e1 ≺ e2 =̂ t1 < t2 or(t1 = t2 and A1 →∗ A2 and A1 6= A2

)where →∗ is the transitive closure of →.

Claim: ≺ is acyclic.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 60 / 66

Page 108: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Precedence Relation on Events

Let e1 = (v1, t1) and e2 = (v2, t2) be two events.

Let A1 and A2 be the recipient actors of e1 and e2:

I This information can be encoded in v1, v2.I We assume a unique recipient per event.

I No loss of generality: can view fan-out junctions as zero-delayactors which copy every input event to all their outputs.

We define precedence of events e1, e2:

e1 ≺ e2 =̂ t1 < t2 or(t1 = t2 and A1 →∗ A2 and A1 6= A2

)where →∗ is the transitive closure of →.

Claim: ≺ is acyclic.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 60 / 66

Page 109: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Event Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink, therefore cancel ≺ alarm.

Suppose there are 3 events, e1, e2, e3, pending at the input port ofScale and the two input ports of AddSubtract, respectively. Then:

e1 ≺ e2 and e1 ≺ e3.

e2 and e3 are independent.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 61 / 66

Page 110: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Event Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink, therefore cancel ≺ alarm.

Suppose there are 3 events, e1, e2, e3, pending at the input port ofScale and the two input ports of AddSubtract, respectively. Then:

e1 ≺ e2 and e1 ≺ e3.

e2 and e3 are independent.Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 61 / 66

Page 111: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation – final version

1: t := 0;2: initialize global event queue Q with a set of initial events;

// Q is always implicitly ordered w.r.t. timestamps// and among events with same timestamp// w.r.t. event dependencies

3: while Q is not empty do4: remove set E of all minimal events w.r.t. ≺ from Q;

// these are earliest and simultaneous events,// which depend on no other events

5: t := te;6: execute set of events E: update system state, generate possible

future events, and add them to Q, ordered by timestamps;possibly remove events from Q;

7: end while

Claim: any new event e produced in step 5 is guaranteed to be greaterthan all events in set E w.r.t. ≺. That is, either e has greater timestampthan all events in E, or it depends on some event in E.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 62 / 66

Page 112: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Discrete-Event Simulation – final version

1: t := 0;2: initialize global event queue Q with a set of initial events;

// Q is always implicitly ordered w.r.t. timestamps// and among events with same timestamp// w.r.t. event dependencies

3: while Q is not empty do4: remove set E of all minimal events w.r.t. ≺ from Q;

// these are earliest and simultaneous events,// which depend on no other events

5: t := te;6: execute set of events E: update system state, generate possible

future events, and add them to Q, ordered by timestamps;possibly remove events from Q;

7: end while

Claim: any new event e produced in step 5 is guaranteed to be greaterthan all events in set E w.r.t. ≺. That is, either e has greater timestampthan all events in E, or it depends on some event in E.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 62 / 66

Page 113: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

DE Simulation and HDLs

I HDLs: Hardware Description Languages

I Verilog, VHDL, SystemC, ...

I Real-world languages

I EDA (Electronics Design Automation) industry: billions of $$$

I Simulation tools: based on DE simulationI But note: many variants, details, ...

I E.g., SystemC specification1 is > 600 pages long.I Description of the simulation algorithm (in English) is 16

pages long.

1IEEE Standard 1666 - 2011, freely available onlineStavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 63 / 66

Page 114: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

SystemC

I Set of C++ libraries.I Simulation algorithm: variant of DE simulation

I kernel (scheduler) manipulates queue of runnable processes

I Main phases of the algorithm:I Elaboration phase (= initialization):

I instantiate processes and signals for inter-processcommunication (processes & signals are C++ objects)

I connect processes to signals (port binding)I select runnable processesI start simulation

I Simulation phase:I choose a process P among the set of runnable processesI run/resume P until P completes or calls wait (or something

similar)I repeat until no more runnable processesI advance time (may make new processes runnable) and repeat

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 64 / 66

Page 115: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

SystemC

I Set of C++ libraries.I Simulation algorithm: variant of DE simulation

I kernel (scheduler) manipulates queue of runnable processes

I Main phases of the algorithm:I Elaboration phase (= initialization):

I instantiate processes and signals for inter-processcommunication (processes & signals are C++ objects)

I connect processes to signals (port binding)I select runnable processesI start simulation

I Simulation phase:I choose a process P among the set of runnable processesI run/resume P until P completes or calls wait (or something

similar)I repeat until no more runnable processesI advance time (may make new processes runnable) and repeat

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 64 / 66

Page 116: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

SystemC

Remarks:

I Co-operative multitasking: processes must release controlback to the kernel/scheduler

I Process executes forever ⇒ zeno system!

I Processes may generate instantaneous events and the sameprocess may become runnable multiple times without timeadvancing – immediate and delta steps

I “The order in which process instances are selected from theset of runnable processes is implementation-defined.”

I Execution apparently not ordered w.r.t. dependencies.⇒ non-determinism!

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 65 / 66

Page 117: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

SystemC

Remarks:

I Co-operative multitasking: processes must release controlback to the kernel/scheduler

I Process executes forever ⇒ zeno system!

I Processes may generate instantaneous events and the sameprocess may become runnable multiple times without timeadvancing – immediate and delta steps

I “The order in which process instances are selected from theset of runnable processes is implementation-defined.”

I Execution apparently not ordered w.r.t. dependencies.⇒ non-determinism!

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 65 / 66

Page 118: EECS 144/244: Fundamental Algorithms for System · PDF filegna l = > S upe r-ense me ... EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization - Timed

Bibliography

M. Broy and K. Stølen.

Specification and development of interactive systems: focus on streams, interfaces, and refinement.Springer, 2001.

E. Lee and A. Sangiovanni-Vincentelli.

A unified framework for comparing models of computation.IEEE Trans. on Computer Aided Design of Integrated Circuits and Systems, 17(12):1217–1229, December1998.

E. A. Lee.

Modeling concurrent real-time processes using discrete events.Annals of Software Engineering, 7:25–45, 1999.

O. Maler and A. Pnueli.

Timing analysis of asynchronous circuits using timed automata.In CHARME’95, LNCS 987, 1995.

J. Misra.

Distributed discrete-event simulation.ACM Comput. Surv., 18(1):39–65, March 1986.

C. Stergiou, S. Tripakis, E. Matsikoudis, and E. A. Lee.

On the Verification of Timed Discrete-Event Models.In 11th International Conference on Formal Modeling and Analysis of Timed Systems – FORMATS 2013.Springer, 2013.

Stavros Tripakis: EECS 144/244 – Fall 2013 Discrete Event Simulation 66 / 66