+ All Categories
Home > Documents > EE 144/244: Fundamental Algorithms for System Modeling ...

EE 144/244: Fundamental Algorithms for System Modeling ...

Date post: 13-Nov-2021
Category:
Upload: others
View: 6 times
Download: 0 times
Share this document with a friend
99
EE 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization Fall 2016 Discrete Event Simulation Stavros Tripakis University of California, Berkeley Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 1 / 53
Transcript
Page 1: EE 144/244: Fundamental Algorithms for System Modeling ...

EE 144/244: Fundamental Algorithms for SystemModeling, Analysis, and Optimization

Fall 2016

Discrete Event Simulation

Stavros TripakisUniversity of California, Berkeley

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 1 / 53

Page 2: EE 144/244: Fundamental Algorithms for System Modeling ...

Timed Systems

In circuits, as well as in embedded / cyber-physical systems, timing is key:

proper timing = an issue of correctness

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

c.f. real-time control.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 2 / 53

Page 3: EE 144/244: Fundamental Algorithms for System Modeling ...

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

Continuous control systems:

Coming from continuous system theory.

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

Discrete-event systems:

More “sparse” events (typically).

Discrete control: e.g., mode switches.

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

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 3 / 53

Page 4: EE 144/244: Fundamental Algorithms for System Modeling ...

(Timed) Discrete Events

Event:

something occurring at some point in time

may also carry a value

event = (timestamp, value)

discrete-event systems: 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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 4 / 53

Page 5: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. Discrete Event Systems

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)

Timed Discrete Event Systems: deal with timed discrete-event signals.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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 5 / 53

Page 6: EE 144/244: Fundamental Algorithms for System Modeling ...

DIGRESSION:

CONTINUOUS vs. DISCRETE SIGNALS

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 6 / 53

Page 7: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Intuition:

Discrete: only finite number of events can happen in a finite amount oftime.

Continuous: not discrete.

Let’s try to formalize this intuition.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 7 / 53

Page 8: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Intuition:

Discrete: only finite number of events can happen in a finite amount oftime.

Continuous: not discrete.

Let’s try to formalize this intuition.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 7 / 53

Page 9: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Let R+ be the set of non-negative reals, modeling time.

Let V be a set of values.

A signal can be defined as a set of events:

s ⊆ R+ × V

(this is the tagged signal model [Lee and Sangiovanni-Vincentelli(1998)]).

Let T (s) be the set of all timestamps in signal s:

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

Then we can define:

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

Otherwise, s is continuous.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 8 / 53

Page 10: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Let R+ be the set of non-negative reals, modeling time.

Let V be a set of values.

A signal can be defined as a set of events:

s ⊆ R+ × V

(this is the tagged signal model [Lee and Sangiovanni-Vincentelli(1998)]).

Let T (s) be the set of all timestamps in signal s:

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

Then we can define:

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

Otherwise, s is continuous.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 8 / 53

Page 11: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Let R+ be the set of non-negative reals, modeling time.

Let V be a set of values.

A signal can be defined as a set of events:

s ⊆ R+ × V

(this is the tagged signal model [Lee and Sangiovanni-Vincentelli(1998)]).

Let T (s) be the set of all timestamps in signal s:

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

Then we can define:

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

Otherwise, s is continuous.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 8 / 53

Page 12: EE 144/244: Fundamental Algorithms for System Modeling ...

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:

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

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

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 9 / 53

Page 13: EE 144/244: Fundamental Algorithms for System Modeling ...

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:

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

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

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 9 / 53

Page 14: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 15: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 16: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 17: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 18: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 19: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 20: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 21: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 22: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 23: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 24: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 25: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 26: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 27: EE 144/244: Fundamental Algorithms for System Modeling ...

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 our definition. But itis also piecewise constant, and could therefore be considered asessentially discrete. This is how discrete signals are modeled in Simulink.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 10 / 53

Page 28: EE 144/244: Fundamental Algorithms for System Modeling ...

Continuous vs. discrete signals

Our definition of discrete vs. continuous signals:

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

Otherwise, s is continuous.

Recall our intuition:

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

Continuous: not discrete.

Does the definition capture our original intuition?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 11 / 53

Page 29: EE 144/244: Fundamental Algorithms for System Modeling ...

Example: bouncing ball

Jie Liu and Edward A. Lee

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 11 / 53

Page 30: EE 144/244: Fundamental Algorithms for System Modeling ...

Example: bouncing ball

Jie Liu and Edward A. Lee

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 11 / 53

Page 31: EE 144/244: Fundamental Algorithms for System Modeling ...

Zeno

Zeno’s “Achilles and the tortoise” paradox:

Achilles and the tortoise enter a race. Achilles runs of course muchfaster. He graciously allows the tortoise a head start of 1 meter. Whowill win?

“In a race, the quickest runner can never overtake the slowest, sincethe pursuer must first reach the point whence the pursued started, sothat the slower must always hold a lead.”

(from wikipedia)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 14 / 53

Page 32: EE 144/244: Fundamental Algorithms for System Modeling ...

Zeno

Zeno’s “Achilles and the tortoise” paradox:

Achilles and the tortoise enter a race. Achilles runs of course muchfaster. He graciously allows the tortoise a head start of 1 meter. Whowill win?

“In a race, the quickest runner can never overtake the slowest, sincethe pursuer must first reach the point whence the pursued started, sothat the slower must always hold a lead.”

(from wikipedia)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 14 / 53

Page 33: EE 144/244: Fundamental Algorithms for System Modeling ...

Zeno DE systemsA DE system is zeno if it generates an infinite number of events in a finite amount oftime:

��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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 15 / 53

Page 34: EE 144/244: Fundamental Algorithms for System Modeling ...

END DIGRESSION

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 16 / 53

Page 35: EE 144/244: Fundamental Algorithms for System Modeling ...

Example Discrete-Event System: 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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 17 / 53

Page 36: EE 144/244: Fundamental Algorithms for System Modeling ...

Delay vs. Server

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 18 / 53

Page 37: EE 144/244: Fundamental Algorithms for System Modeling ...

DIGRESSION:

EVENTS vs. STATES

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 19 / 53

Page 38: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 20 / 53

Page 39: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 20 / 53

Page 40: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 20 / 53

Page 41: EE 144/244: Fundamental Algorithms for System Modeling ...

From Events to States

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

State = history of events observed so farFormally:

Σ: set of events

Σ∗: set of finite event sequences = histories

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 classes of ∼L isthe number of states in the smallest DFA recognizing L.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 21 / 53

Page 42: EE 144/244: Fundamental Algorithms for System Modeling ...

From Events to States

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

State = history of events observed so far

Formally:

Σ: set of events

Σ∗: set of finite event sequences = histories

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 classes of ∼L isthe number of states in the smallest DFA recognizing L.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 21 / 53

Page 43: EE 144/244: Fundamental Algorithms for System Modeling ...

From Events to States

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

State = history of events observed so farFormally:

Σ: set of events

Σ∗: set of finite event sequences = histories

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 classes of ∼L isthe number of states in the smallest DFA recognizing L.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 21 / 53

Page 44: EE 144/244: Fundamental Algorithms for System Modeling ...

From Events to States

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

State = history of events observed so farFormally:

Σ: set of events

Σ∗: set of finite event sequences = histories

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 classes of ∼L isthe number of states in the smallest DFA recognizing L.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 21 / 53

Page 45: EE 144/244: Fundamental Algorithms for System Modeling ...

END DIGRESSION

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 22 / 53

Page 46: EE 144/244: Fundamental Algorithms for System Modeling ...

Discrete-Event Models (DE)

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

model 1 (drawing) model 2 (ptolemy)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 23 / 53

Page 47: EE 144/244: Fundamental Algorithms for System Modeling ...

Example: car washTaken from [Misra(1986)]:

Source generates car arrivals at some arbitrary times.

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 free one;I otherwise car waits until a station becomes free.I Cars are served by attendant in FIFO order.

CW1 spends 8 mins to wash a car.

CW2 spends 10 mins to wash a car.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 24 / 53

Page 48: EE 144/244: Fundamental Algorithms for System Modeling ...

Delay vs. Server

Are CW1, CW2 delays or servers?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 25 / 53

Page 49: EE 144/244: Fundamental Algorithms for System Modeling ...

Analysis of DE Models

model 1 (drawing) model 2 (ptolemy)

We will look at simulation of DE models.

Exhaustive verification (model-checking) of DE models: not wellstudied (see [Stergiou et al. 2013])

Well studied problem: exhaustive verification of another type of DEsystem: timed automata [Alur and Dill(1994)]

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 26 / 53

Page 50: EE 144/244: Fundamental Algorithms for System Modeling ...

Analysis of DE Models

model 1 (drawing) model 2 (ptolemy)

We will look at simulation of DE models.

Exhaustive verification (model-checking) of DE models: not wellstudied (see [Stergiou et al. 2013])

Well studied problem: exhaustive verification of another type of DEsystem: timed automata [Alur and Dill(1994)]

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 26 / 53

Page 51: EE 144/244: Fundamental Algorithms for System Modeling ...

DISCRETE-EVENT SIMULATION

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 27 / 53

Page 52: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 28 / 53

Page 53: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 29 / 53

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

Page 54: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 30 / 53

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

Page 55: EE 144/244: Fundamental Algorithms for System Modeling ...

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

Appears intuitive, but details are left unspecified: steps 2, 6.

Not modular : step 6 appears to work on the entire system state, not onindividual actors.

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

Let’s try to flesh out the details of steps 2 and 6.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 31 / 53

Page 56: EE 144/244: Fundamental Algorithms for System Modeling ...

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

Appears intuitive, but details are left unspecified: steps 2, 6.

Not modular : step 6 appears to work on the entire system state, not onindividual actors.

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

Let’s try to flesh out the details of steps 2 and 6.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 31 / 53

Page 57: EE 144/244: Fundamental Algorithms for System Modeling ...

Modeling Source ActorsSource actor = an actor with no inputs.

Clock is a source:

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.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 32 / 53

Page 58: EE 144/244: Fundamental Algorithms for System Modeling ...

Modeling Source ActorsSource actor = an actor with no inputs.

Clock is a source:

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.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 32 / 53

Page 59: EE 144/244: Fundamental Algorithms for System Modeling ...

Modeling Source ActorsSource actor = an actor with no inputs.

Clock is a source:

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.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 32 / 53

Page 60: EE 144/244: Fundamental Algorithms for System Modeling ...

Feedback loops are necessary in generalExample: car wash (taken from [Misra(1986)]):

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

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 free oneI otherwise car waits until a station becomes freeI cars are served by attendant in FIFO order

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

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 33 / 53

Page 61: EE 144/244: Fundamental Algorithms for System Modeling ...

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 34 / 53

Page 62: EE 144/244: Fundamental Algorithms for System Modeling ...

Avoiding Zeno Systems

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

Is it sufficient to avoid zenoness?

Yes. Exercise: prove it.

From now on we assume a constant non-zero delay in every feedback loop.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 35 / 53

Page 63: EE 144/244: Fundamental Algorithms for System Modeling ...

Avoiding Zeno Systems

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

Is it sufficient to avoid zenoness?

Yes. Exercise: prove it.

From now on we assume a constant non-zero delay in every feedback loop.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 35 / 53

Page 64: EE 144/244: Fundamental Algorithms for System Modeling ...

Avoiding Zeno Systems

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

Is it sufficient to avoid zenoness?

Yes. Exercise: prove it.

From now on we assume a constant non-zero delay in every feedback loop.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 35 / 53

Page 65: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Example: Alarm

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ t.

How does the DE simulation algorithm handle this example?

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

... but this event may then have to be canceled during simulation ifsomething arrives at the input before t.

Canceling events = removing them from the event queue.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 36 / 53

Page 66: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Example: Alarm

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ t.How does the DE simulation algorithm handle this example?

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

... but this event may then have to be canceled during simulation ifsomething arrives at the input before t.

Canceling events = removing them from the event queue.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 36 / 53

Page 67: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Example: Alarm

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ t.How does the DE simulation algorithm handle this example?

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

... but this event may then have to be canceled during simulation ifsomething arrives at the input before t.

Canceling events = removing them from the event queue.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 36 / 53

Page 68: EE 144/244: Fundamental Algorithms for System Modeling ...

Why insert events only to cancel them later?

Whether an event will be generated before t may not always be easy todetermine:

Some complex model Alarm Sinkcancel alarm

DE algorithm must work independently of how Alarm is connected.

That’s what modular means.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 37 / 53

Page 69: EE 144/244: Fundamental Algorithms for System Modeling ...

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 removeevents from Q;

7: end while

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 38 / 53

Page 70: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Issue: Simultaneous Events

The AddSubtract actor is supposed to behave as follows:

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

If it receives an event in just one of the two inputs, it simply forwards it.

Suppose the two SingleEvent actors produce two simultaneous events with thesame value x.

What should the output be?

A single event with value x− x = 0.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 39 / 53

Page 71: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Issue: Simultaneous Events

The AddSubtract actor is supposed to behave as follows:

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

If it receives an event in just one of the two inputs, it simply forwards it.

Suppose the two SingleEvent actors produce two simultaneous events with thesame value x.

What should the output be? A single event with value x− x = 0.Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 39 / 53

Page 72: EE 144/244: Fundamental Algorithms for System Modeling ...

Another Issue: Simultaneous Events

How to achieve the desired behavior with the DE simulation algorithm?

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 40 / 53

Page 73: EE 144/244: Fundamental Algorithms for System Modeling ...

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 removeevents from Q;

7: end while

Not as simple ...

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 41 / 53

Page 74: EE 144/244: Fundamental Algorithms for System Modeling ...

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 removeevents from Q;

7: end while

Not as simple ...

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 41 / 53

Page 75: EE 144/244: Fundamental Algorithms for System Modeling ...

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneous events.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 new simultaneousevents not in E ...

We need some systematic way to do this ...

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 42 / 53

Page 76: EE 144/244: Fundamental Algorithms for System Modeling ...

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneous events.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 new simultaneousevents not in E ...

We need some systematic way to do this ...

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 42 / 53

Page 77: EE 144/244: Fundamental Algorithms for System Modeling ...

Issues with Simultaneous Events

Suppose the two SingleEvent sources produce two simultaneous events.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 new simultaneousevents not in E ...

We need some systematic way to do this ...

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 42 / 53

Page 78: EE 144/244: Fundamental Algorithms for System Modeling ...

Back to the Alarm Example

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ t

What if Source produces an event also at time t?

According to the semantics of Alarm, it should not raise an alarmevent.

Does the DE simulation algorithm guarantee this?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 43 / 53

Page 79: EE 144/244: Fundamental Algorithms for System Modeling ...

Back to the Alarm Example

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ tWhat if Source produces an event also at time t?

According to the semantics of Alarm, it should not raise an alarmevent.

Does the DE simulation algorithm guarantee this?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 43 / 53

Page 80: EE 144/244: Fundamental Algorithms for System Modeling ...

Back to the Alarm Example

Source Alarm Sinkcancel alarm

Alarm actor: produces event at given time t, unless it receives inputat time t′ ≤ tWhat if Source produces an event also at time t?

According to the semantics of Alarm, it should not raise an alarmevent.

Does the DE simulation algorithm guarantee this?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 43 / 53

Page 81: EE 144/244: Fundamental Algorithms for System Modeling ...

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; possibly remove events from Q;7: end while

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 44 / 53

Page 82: EE 144/244: Fundamental Algorithms for System Modeling ...

Dealing with Simultaneous Events

Source Alarm Sinkcancel alarm

Chronological ordering (= ordering by timestamps) of events in thequeue is not enough.

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

time t

How to define event dependencies?

First let’s formalize actor dependencies.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 45 / 53

Page 83: EE 144/244: Fundamental Algorithms for System Modeling ...

Dealing with Simultaneous Events

Source Alarm Sinkcancel alarm

Chronological ordering (= ordering by timestamps) of events in thequeue is not enough.

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

time t

How to define event dependencies?

First let’s formalize actor dependencies.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 45 / 53

Page 84: EE 144/244: Fundamental Algorithms for System Modeling ...

Dependency Relation among Actors

Let A1, A2 be two actors in the DE model.

Define the dependency relation A1 → A2 (A2 depends on A1) as follows:

A1 → A2 =̂ A1 is zero-delay (i.e., its output may have the sametimestamp as the input that produced it) and there is a connection froman output of A1 to an input of A2.

Claim: → is acyclic.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 46 / 53

Page 85: EE 144/244: Fundamental Algorithms for System Modeling ...

Dependency Relation among Actors

Let A1, A2 be two actors in the DE model.

Define the dependency relation A1 → A2 (A2 depends on A1) as follows:

A1 → A2 =̂ A1 is zero-delay (i.e., its output may have the sametimestamp as the input that produced it) and there is a connection froman output of A1 to an input of A2.

Claim: → is acyclic.

Why?

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 46 / 53

Page 86: EE 144/244: Fundamental Algorithms for System Modeling ...

Dependency Relation among Actors

Let A1, A2 be two actors in the DE model.

Define the dependency relation A1 → A2 (A2 depends on A1) as follows:

A1 → A2 =̂ A1 is zero-delay (i.e., its output may have the sametimestamp as the input that produced it) and there is a connection froman output of A1 to an input of A2.

Claim: → is acyclic.

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

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 46 / 53

Page 87: EE 144/244: Fundamental Algorithms for System Modeling ...

Actor Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink

Scale → AddSubtract → TimedPlotter

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 47 / 53

Page 88: EE 144/244: Fundamental Algorithms for System Modeling ...

Actor Dependencies – Examples

Source Alarm Sinkcancel alarm

Alarm → Sink

Scale → AddSubtract → TimedPlotter

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 47 / 53

Page 89: EE 144/244: Fundamental Algorithms for System Modeling ...

Precedence Relation on Events

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

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

This information can be encoded in v1, v2.

We assume a unique recipient per event.I No loss of generality: can view fan-out junctions as zero-delay actors

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 48 / 53

Page 90: EE 144/244: Fundamental Algorithms for System Modeling ...

Precedence Relation on Events

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

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

This information can be encoded in v1, v2.

We assume a unique recipient per event.I No loss of generality: can view fan-out junctions as zero-delay actors

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 48 / 53

Page 91: EE 144/244: Fundamental Algorithms for System Modeling ...

Precedence Relation on Events

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

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

This information can be encoded in v1, v2.

We assume a unique recipient per event.I No loss of generality: can view fan-out junctions as zero-delay actors

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 48 / 53

Page 92: EE 144/244: Fundamental Algorithms for System Modeling ...

Event Precedences – ExamplesAssuming simultaneous events in the examples below:

Source Alarm Sinkcancel alarm

Alarm → Sink, therefore cancel ≺ alarm.

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

e1 ≺ e2 and e1 ≺ e3.

e2 and e3 are independent.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 49 / 53

Page 93: EE 144/244: Fundamental Algorithms for System Modeling ...

Event Precedences – ExamplesAssuming simultaneous events in the examples below:

Source Alarm Sinkcancel alarm

Alarm → Sink, therefore cancel ≺ alarm.

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

e1 ≺ e2 and e1 ≺ e3.

e2 and e3 are independent.Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 49 / 53

Page 94: EE 144/244: Fundamental Algorithms for System Modeling ...

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 eventsfrom Q;

7: end while

Claim: any new event e produced in step 6 is guaranteed to be greater than allevents in set E w.r.t. ≺. That is, either e has greater timestamp than all eventsin E, or it depends on some event in E.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 50 / 53

Page 95: EE 144/244: Fundamental Algorithms for System Modeling ...

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 eventsfrom Q;

7: end while

Claim: any new event e produced in step 6 is guaranteed to be greater than allevents in set E w.r.t. ≺. That is, either e has greater timestamp than all eventsin E, or it depends on some event in E.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 50 / 53

Page 96: EE 144/244: Fundamental Algorithms for System Modeling ...

DE Simulation and HDLs

HDLs: Hardware Description Languages

Verilog, VHDL, SystemC, ...

Real-world languages

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

Simulation tools: based on DE simulation

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 51 / 53

Page 97: EE 144/244: Fundamental Algorithms for System Modeling ...

SystemC

Remarks:

Co-operative multitasking: processes must release control back to thekernel/scheduler

I Process executes forever ⇒ zeno system!

Processes may generate instantaneous events and the same processmay become runnable multiple times without time advancing –immediate and delta steps

“The order in which process instances are selected from the set ofrunnable processes is implementation-defined.”

Execution apparently not ordered w.r.t. dependencies.⇒ non-deterministic simulation results!

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 52 / 53

Page 98: EE 144/244: Fundamental Algorithms for System Modeling ...

SystemC

Remarks:

Co-operative multitasking: processes must release control back to thekernel/scheduler

I Process executes forever ⇒ zeno system!

Processes may generate instantaneous events and the same processmay become runnable multiple times without time advancing –immediate and delta steps

“The order in which process instances are selected from the set ofrunnable processes is implementation-defined.”

Execution apparently not ordered w.r.t. dependencies.⇒ non-deterministic simulation results!

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 52 / 53

Page 99: EE 144/244: Fundamental Algorithms for System Modeling ...

Bibliography

R. Alur and D. Dill.

A theory of timed automata.Theoretical Computer Science, 126:183–235, 1994.

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, December 1998.

E. A. Lee.

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

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 (UC Berkeley) EE 144/244, Fall 2016 Discrete Event Simulation 53 / 53


Recommended