Concepts of Concurrent Computtion Spring 205 Lecture 9: Petri Nets Sebstin Nnz Chris Poskitt Chir of Softwre Engineering
Petri nets Petri nets re mthemticl models for describing systems with concurrency nd resource shring they fcilitte mny utomtic nlyses of interest for concurrent systems rich, intuitive grphicl nottion for choice, concurrent execution, interction with the environment,... 2
Petri nets - the origins proposed by Crl Adm Petri in his fmous thesis Kommuniktion mit Automten (962) imed for system rchitecture tht could be expnded indefinitely => no centrl components => in prticulr, no centrl, synchronising clock => ctions with loclly confined cuses/effects originl presenttion omitted the grphicl representtion 3
Tody s gend. modelling concepts: cookies for everyone! 2. synchronistion problems s Petri nets 3. Petri net nlyses 4. true concurrency semntics; unfoldings 4
Let s design cookie vending mchine coin slot comprtment 5
Let s design cookie vending mchine coin slot comprtment 6
Let s design cookie vending mchine t coin slot comprtment 7
Let s design cookie vending mchine t coin slot comprtment 8
Terminology plce tokens t trnsition (with precondition ) t mrking (distribution of tokens) 9
Let s design cookie vending mchine t coin slot comprtment 0
Let s design cookie vending mchine t coin slot comprtment trnsition t is enbled it cn occur nd chnge the mrking
Let s design cookie vending mchine t coin slot comprtment trnsition t is enbled it cn occur nd chnge the mrking 2
Let s design cookie vending mchine t coin slot comprtment trnsition t is enbled it cn occur nd chnge the mrking! csh box? finitely mny cookies?
Let s look inside storge b coin slot signl comprtment csh box 4
Let s look inside storge b coin slot signl comprtment csh box 5
Let s look inside storge b coin slot signl comprtment csh box 6
Let s look inside storge b coin slot signl comprtment csh box 7
Let s open it up to the world 8
Let s open it up to the world storge ϵ insert coin slot signl b comprtment ϵ tke csh box 9
Let s open it up to the world storge ϵ insert coin slot signl b comprtment ϵ tke csh box ϵ denotes trnsition tht once enbled, need not ctully occur we ssume tht other enbled trnsitions occur eventully 20
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box 2
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box 22
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box 23
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box! conflict! nondeterminism! 24
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box 25
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter csh box 26
The ultimte cookie mchine storge coin slot ϵ insert signl b comprtment ϵ tke return coin counter exercise: strengthen the design such tht the coin slot nd signl plces csh box store t most one token ech 27
Elementry Petri nets if we re interested in only control flow, we cn use specil cse - elementry Petri nets - where ll tokens re simply blck dots ssume ll edges to be lbelled by: henceforth, we ssume ll Petri nets to be elementry 28
Elementry cookie vending mchine coin slot storge ϵ insert signl b comprtment ϵ tke return coin counter csh box 29
Petri nets: definition n (elementry) Petri net consists of net structure: N = (P, T, F) with finite sets P nd T of plces nd trnsitions, F n edge reltion F (P x T) (T x P) nd n initil mrking M0: P -> N mrkings hve the form M: P -> N; ech plce p holds M(p) tokens 30
Petri nets: definition the preset of trnsition t is the set of plces p connected by edges from p to t (postset defined nlogously) trnsition is enbled if M(p) for ll plces p in the preset n enbled trnsition cn occur, removing token from ech plce in the preset nd dding one to ech plce in the postset 3
Next on the gend. modelling concepts: cookies for everyone! 2. synchronistion problems s Petri nets 3. Petri net nlyses 4. true concurrency semntics; unfoldings 32
Producer-consumer problem store (buffer, int) consume (buffer) Producers 243 46 7 97 Buffer Consumers 33
Producer-consumer problem wit consume produce wit 34
Producer-consumer problem wit consume buffer spce buffer count produce wit 35
Producer-consumer problem wit consume buffer spce buffer count produce wit 36
Producer-consumer problem wit consume buffer spce buffer count produce wit 37
Producer-consumer problem wit consume buffer spce buffer count produce wit 38
Producer-consumer problem wit consume buffer spce buffer count produce wit 39
Producer-consumer problem wit consume buffer spce buffer count produce wit 40
Mutul exclusion witing witing2 ϵ CR CR2 ϵ locl locl2 4
Mutul exclusion witing witing2 semphore ϵ CR CR2 ϵ locl locl2 42
Next on the gend. modelling concepts: cookies for everyone! 2. synchronistion problems s Petri nets 3. Petri net nlyses 4. true concurrency semntics; unfoldings 43
Modelling power vs. nlysbility mny properties of interest for concurrent systems cn be utomticlly determined for Petri nets => but cn be very expensive in the generl cse properties include: => k-boundedness (i.e. no plce ever hs more thn k tokens) => liveness => rechbility severl tools re vilble => http://www.informtik.uni-hmburg.de/tgi/petrinets/tools/quick.html 44
Rechbility problem the problem to decide whether some mrking M cn be derived from the initil mrking strting point: construct rechbility grph from the initil mrking => i.e. trnsition system completely describing its behviour => nodes denote mrkings => edges denote occurrences (more sophistiction is needed when rechbility grphs re not finite) 45
Rechbility grph for our semphore wit wit2 sem ϵ CR CR2 ϵ loc loc2 express mrking M s vector: ( M(wit) M(CR) M(loc) M(sem) M(wit2) M(CR2) M(loc2) ) i.e. ( 0 0 0 0 )
Rechbility grph for our semphore wit wit2 sem ϵ CR CR2 ϵ loc loc2 prove tht (0 0 0 0 0) is unrechble prove tht M(CR)+M(CR2)+M(sem) =
Rechbility grph for our semphore ( 0 0 0 0 ) ( 0 0 0 0 0 ) ( 0 0 0 0 0 ) ( 0 0 0 0 ) ( 0 0 0 0 ) ( 0 0 0 0 0 ) ( 0 0 0 0 0 ) ( 0 0 0 0 ) 48
Deciding rechbility is expensive rechbility is n importnt nlysis decidble, but expensive in the generl cse => EXPSPACE-hrd => rechbility grph not lwys finite prt II of Reisig (203) trets the problem with more sophistiction thn we hve 49
Next on the gend. modelling concepts: cookies for everyone! 2. synchronistion problems s Petri nets 3. Petri net nlyses 4. true concurrency semntics; unfoldings 50
The problem of interleving semntics consider the following Petri net:... n its rechbility grph contins 2 n sttes => stte explosion problem => due to interleving of occurrences => unnecessry: ordering of occurrences here immteril! 5
Interleving vs. true concurrency semntics n interleving semntics imposes totl ordering on sequences of occurrences => completely described by rechbility grph => nodes denote mrkings; edges denote occurrences => stte explosion! true concurrency semntics insted models time s prtil order => two or more occurrences cn hppen simultneously => completely described by so-clled unfolding 52
Unfoldings re more compct representtions of concurrency n unfolding of Petri net N is Petri net tht is more tree like - but represents the sme behviour explicitly represents concurrency nd cusl dependence between different behviours ide: nlyse the unfolding of Petri net itself, rther thn n underlying trnsition system (s in the interleving semntics) 53
A Exmple: n unfolding C B D 54
A Exmple: n unfolding C B D A C 55
A Exmple: n unfolding C B D A B C 56
A Exmple: n unfolding C B D A B A C 57
A Exmple: n unfolding C B D A B A B C 58
A Exmple: n unfolding C B D A B A B D C 59
A Exmple: n unfolding C B D A B A B A C D 60
A Exmple: n unfolding C B D A B A B A... D D C... 6
Constructing n unfolding ssumption: Petri nets re -bounded => possible to generlise to other Petri net vrints steps to construct n unfolding N from Petri net N: () initilise N with the plces in N contining tokens in the initil mrking (2) if rechble* mrking in N enbles trnsition t in N, then disjointly dd t to N nd: => link it to the corresponding preset => disjointly dd the postset of t (3) iterte step 2 *checking rechbility is fr esier for the unfolding net clss 62
A B C Another exmple A2 B2 C2 63
A B C Another exmple A2 B2 C2 A B C 64
A B C Another exmple A2 B2 C2 A B C C2 65
A B C Another exmple A2 B2 C2 A B B2 C C2 C 66
A B C Another exmple A2 B2 C2 A A2 B B2 B C C2 C 67
A B C Another exmple A2 B2 C2 A A2 B B2 B C C2 C C2 68
A B C Another exmple A2 B2 C2 A A2 A B B2 B C C2 C C2 69
A B C Another exmple A2 B2 C2... A A2 A B B2 B B2... C C2 C C2 C... 70
Returning to our smll exmple construct n unfolding of the following Petri net:... n 7
Returning to our smll exmple construct n unfolding of the following Petri net:... n the unfolding is just the Petri net itself! => size O(n) => wheres interleving yields 2 n rechble sttes 72
Petri net nlysis using unfoldings suppose we wnt to know if some trnsition t in Petri net N cn occur compute n nswer by exploring the unfolding of N until either: => trnsition lbelled t is found => or it cn be concluded tht no such trnsition occurs for finite unfoldings, compute nd explore the whole structure for infinite unfoldings, only finite prefix is computed nd explored 73
A B b c A2 d B2 e f A3 B3 x A4 cn x ever occur?
A B A B b c A2 d B2 e f A3 B3 x A4 cn x ever occur?
A B b c A2 A b B B2 A2 B2 d e f A3 B3 x A4 cn x ever occur?
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 cn x ever occur?
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 b cn x ever occur? A2 B2
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 b e cn x ever occur? A2 B2 A2 B3
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 b e cn x ever occur? A2 B2 A2 B3 d A A3
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 b e cn x ever occur? A2 B2 A2 B3... d f A A3 B2......
A B b c A2 A b B B2 A2 d B2 e f c d A3 B3 x A B A3 A4 b e cn x ever occur? A2 B2 A2 B3 d f need we compute further? A A3 B2
Complete finite prefix complete finite prefix is finite prt of n unfolding tht is sufficient for deciding certin questions bout the originl Petri net => e.g. executbility, repeted executbility, livelock,... chllenge is to determine when to stop unfolding without informtion loss => outside scope of this lecture; see Esprz & Heljnko (2008) previous slide gve complete finite prefix => no x in the prefix; hence x cn never occur in the originl Petri net complete finite prefixes cn be exponentilly more concise thn n interleving-bsed representtion
Next on the gend. modelling concepts: cookies for everyone! 2. synchronistion problems s Petri nets 3. Petri net nlyses 4. true concurrency semntics; unfoldings 84
Min sources for this lecture Understnding Petri Nets (203) => by Wolfgng Reisig => chpters -3 Unfoldings (2008) => by Jvier Esprz & Keijo Heljnko => chpters -3 A Flse History of True Concurrency => http://dx.doi.org/0.007/978-3-642-664-3_3 => https://www7.in.tum.de/~esprz/tlks/lmpstrueconc.pdf 85
Summry Petri nets fcilitte grphicl, intuitive mens of modelling concurrent nd distributed systems utomtic nlyses exist for rechbility, boundedness, liveness,... but re expensive in the generl cse unfoldings (bsed on true concurrency) my give more compct representtion of concurrency thn rechbility grphs (bsed on interlevings) 86