Elementary Petri Nets - cas.mcmaster.ca

Preview:

Citation preview

Elementary Petri NetsCS 3SD3

Ryszard Janicki

Department of Computing and Software, McMaster University, Hamilton,Ontario, Canada

Ryszard Janicki Elementary Petri Nets 1/26

From State Machines to Elementary Petri NetsElementary Petri Nets are directed bipartite graphs with

places, represented by circles or ovals (represent some type ofresource)transitions, represented by rectangles or lines (consume and produceresources)arcs (from places to transitions or transitions to places)tokens, placed in placesinitial marking, tokens is some places

6

Some definitionssource transition: no inputssink transition: no outputsself-loop: a pair (p,t) s.t. p is both an input and an output of tpure PN: no self-loopsordinary PN: all arc weights are 1’sinfinite capacity net: places can accommodate an unlimited number of tokensfinite capacity net: each place p has a maximum capacity K(p)strict transition rule: after firing, each output place can’t have more than K(p) tokensTheorem: every pure finite-capacity net can be transformed into an equivalent infinite-capacity net

Modeling FSMs

15

2010

5

10

vend 15¢ candy

10

55

10

5

vend 20¢ candy

0

5

Ryszard Janicki Formal Methods 10 / 30

7

Modeling FSMs

5 10

vend 15¢ candy

10

5

5

10

5

vend 20¢ candy

state machines:each transitionhas exactlyone input andone output

Modeling FSMs

5 10

vend

10

5

5

10

5

vend

conflict,decisionor choice

Ryszard Janicki Formal Methods 11 / 30Finite State Machine Petri NetRyszard Janicki Elementary Petri Nets 2/26

Modeling Concurrency

Elementary Petri Nets are directed bipartite graphs withplaces, represented by circles or ovals (represent some type ofresource)transitions, represented by rectangles or lines (consume and produceresources)arcs (from places to transitions or transitions to places)tokens, placed in placesinitial marking, tokens is some places

8

Modeling concurrency

t2

t3

t1 t4marked graph:each place hasexactly oneincoming arc and one outgoingarc.

Modeling concurrency

t2

t3

t1 t4

concurrency

Ryszard Janicki Formal Methods 14 / 30

Ryszard Janicki Elementary Petri Nets 3/26

Firing Rules for Elementary Petri NetsA transition t can be fired if and only if it has tokens in all itsinput places and all output places are empty.After firing t, all its input places become empty and all itsoutput places contain tokens.

Before fining t After firing t

t can not be firedRyszard Janicki Elementary Petri Nets 4/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Without any synchronization, individual viewpoints ofcomputers.

Example 1read

write

idle

write

read

idle

The token tells us the state of the process

17

20

Ryszard Janicki Elementary Petri Nets 5/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Without any synchronization, individual viewpoints ofcomputers.

Example 1read

write

idle

write

read

idle

The token tells us the state of the process

18

21

Ryszard Janicki Elementary Petri Nets 6/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Without any synchronization, individual viewpoints ofcomputers.

Example 1read

write

idle

write

read

idle

The token tells us the state of the process

19

22

Ryszard Janicki Elementary Petri Nets 7/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Without any synchronization, individual viewpoints ofcomputers.

Example 1read

write

idle

write

read

idle

The token tells us the state of the process

20

23

Ryszard Janicki Elementary Petri Nets 8/26

Modeling Mutual ExclusionTwo computers, one printer/data base, etc.Without any synchronization, individual viewpoints of computers.PROBLEM, both computers want to write but there is only oneprinter/data base, etc.

Example 1read

write

idle

write

read

idle

The token tells us the state of the process

21

24

Ryszard Janicki Elementary Petri Nets 9/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Synchronization is added.

Example 1read

write

idle

write

read

idle

Add a lock to ensure mutual exclusion22

25

Ryszard Janicki Elementary Petri Nets 10/26

Modeling Mutual Exclusion

Two computers, one printer/data base, etc.Synchronization is added.

Example 1read

write

idle

write

idle

23

26

Ryszard Janicki Elementary Petri Nets 11/26

Modeling Dataflow Computation

Petri nets allow modeling without decomposing the wholesystem into sequential component!x = (a + b)/(a− b)

9

Modeling dataflow computation

x = (a+b)/(a-b)a

a

b

b

a+b

a-b

+

-

/

!=0

=0

x

NaN

copy

copy

Modeling communication protocols

readyto send

waitfor ack.

ack.received

msg.received

ack.sent

readyto receive

bufferfull

bufferfullsend

msg.

receiveack.

receivemsg.

sendack.

proc.1 proc.2

Ryszard Janicki Formal Methods 15 / 30

The two copy transitions can be removed, they representinputs from environment.

Ryszard Janicki Elementary Petri Nets 12/26

Modeling Communication Protocols

9

Modeling dataflow computation

x = (a+b)/(a-b)a

a

b

b

a+b

a-b

+

-

/

!=0

=0

x

NaN

copy

copy

Modeling communication protocols

readyto send

waitfor ack.

ack.received

msg.received

ack.sent

readyto receive

bufferfull

bufferfullsend

msg.

receiveack.

receivemsg.

sendack.

proc.1 proc.2

Ryszard Janicki Formal Methods 16 / 30

Ryszard Janicki Elementary Petri Nets 13/26

Loading and Unloading Two MachinesAn Example

Edward Lin, University of Maryland 20

An Example

Machine States:LoadingProcessingWaiting for unloadingUnloading

Machine 1

Machine 2

Robot

Buffer

Buffer State:Space availability

Ryszard Janicki Formal Methods 17 / 25Ryszard Janicki Elementary Petri Nets 14/26

Loading and Unloading Two Machines

Ryszard Janicki Elementary Petri Nets 15/26

Composition of LTS (Maker-User Example)

MAKER = make → ready → MAKER

USER = ready → use → USER

‖ MAKER USER = Maker ‖ USER

LTS:

Ryszard Janicki Elementary Petri Nets 16/26

LTS via Elementary Petri Nets1 Represent each LTS as a Petri Net

2 ‘Glue’ together both nets through the common transition ready .

Ryszard Janicki Elementary Petri Nets 17/26

Reachability Graphs

Reachability graphs are finite state machines that representthe behaviours of Petri nets.

Each state of the reachability graph represent a ‘marking’ of Petrinet.

Simultaneous executions (steps), like {make, use}, may be allowed.

Ryszard Janicki Elementary Petri Nets 18/26

Reachability Graphs and ‖ operator

Reachability graphs are the same as final LTS obtained viaoperator ‘‖’ !

Getting final LTS vis Petri nets is more natural than viastandard procedure!

Ryszard Janicki Elementary Petri Nets 19/26

Formal Definition (1)

Definition

An Elementary Net is a tuple

N = (P,T ,F ,Cinit)

such that

1 P and T are finite and disjoint sets of places and transitionsrepresented, respectively, as circles and rectangles;

2 F ⊆ (P × T ) ∪ (T × P) is the flow relation of N - representedas directed arcs between places and transitions;

3 Cinit ⊆ P is the initial marking (or initial configuration) of N.

Ryszard Janicki Elementary Petri Nets 20/26

Example

P = {p1, p2, p3, p4, p5},T = {t1, t2, t3, t4},F = {(p1, t2), (p2, t3), (p3, t4), (p4, t4), (p5, t1),

(t1, p1), (t1, p2), (t2, p3), (t3, p4), (t4, p5)},Cinit = {p1, p2}.

Ryszard Janicki Elementary Petri Nets 21/26

Formal Definition (2)

For every x ∈ P ∪ T , the set •x = {y | (y , x) ∈ F} denotesthe input nodes of x , and

the set x• = {y | (x , y) ∈ F} denotes the output nodes of x .

The dot-notation extends to sets in the natural way, e.g. theset X • comprises all outputs of the nodes in X .

We often (but not always) assume that for every t ∈ T , both•t and t• are non-empty and disjoint.

Ryszard Janicki Elementary Petri Nets 22/26

Example

•p1 = {t1}, •p2 = {t1}, •p3 = {t2}, •p4 = {t3}, •p5 = {t4},p•1 = {t2}, p•2 = {t3}, p•3 = {t4}, p•4 = {t4}, p•2 = {t1},•t1 = {p5}, •t2 = {p1}, •t3 = {p2}, •t4 = {p3, p4},t•1 = {p1, p2}, t•2 = {p3}, t•3 = {p4}, t•4 = {p5},•{p1, p4} = {t1, t3}, •{p1, p2} = {t1},{p1, p4}• = {t2, t4}, {p1, p2}• = {t2, t3},•{t1, t3} = {p2, p5}, •{t2, t3} = {p1, p2},{t1, t3}• = {p1, p2, p4}, {t2, t3}• = {p3, p4}.

Ryszard Janicki Elementary Petri Nets 23/26

Interleaving Semantics

A transition t is enabled at a configuration C if •t ⊆ C andt• ∩ C = ∅.An enabled transition t can fire leading to a new configurationC ′ = (C \ •t) ∪ t•.

We denote this by C [t〉C ′, or by C [t〉NC ′, if C , C ′ and t maybelong to different nets.

We will also write C [t1 . . . tn〉C ′ if C [t1〉C1 . . .Cn−1[tn〉C ′ forsome configurations C1, . . . ,Cn−1.

Definition

A firing sequence of an Elementary Petri Net is any sequence oftransitions t1, . . . , tn for which there are markings C1, . . . ,Cn

satisfying:Cinit [t1〉C1[t2〉C2 . . . [tn〉Cn.

Ryszard Janicki Elementary Petri Nets 24/26

Step-sequence Semantics

Let A ⊆ T be a non-empty set such that for all distinctt1, t2 ∈ A:

(t•1 ∪ •t1) ∩ (t•2 ∪ •t2) = ∅.

Then A is enabled at a marking C if •A ⊆ C and A• ∩ C = ∅.We also denote this by C [A〉C ′, or C [A〉NC ′ when C , C ′ andA may belong to different nets, where C ′ = (C \ •A) ∪ A•.

Definition

A firing step sequence is a sequence of sets (or steps) A1, . . . ,An

for which there are markings C1, . . . ,Cn satisfying:

Cinit [A1〉C1[A2〉C2 . . . [An〉Cn.

Ryszard Janicki Elementary Petri Nets 25/26

Example

Some firing sequences: t2t3t4t1 since{p1, p2}[t2〉{p2, p3}[t3〉{p3, p4}[t4〉{p5}[t1〉{p1, p2},t2t4t3t1 since{p1, p2}[t3〉{p1, p4}[t2〉{p3, p4}[t4〉{p5}[t1〉{p1, p2}.A firing step-sequence: {t2, t3}{t4}{t1} since{p1, p2}[{t2, t3}〉{p3, p4}[{t4}〉{p5}[{t1}〉{p1, p2}.

Ryszard Janicki Elementary Petri Nets 26/26

Recommended