SE561 Formal Methods in Software Petri Nets I

  • Slides: 29
Download presentation
SE-561 Formal Methods in Software Petri Nets - I 1

SE-561 Formal Methods in Software Petri Nets - I 1

Petri nets • The classical Petri net was invented by Carl Adam Petri in

Petri nets • The classical Petri net was invented by Carl Adam Petri in 1962. • A lot of research has been conducted (>10, 000 publications). • Until 1985 it was mainly used by theoreticians. • Since the 80 -ties the practical use is increasing because of the introduction of high-level Petri nets and the availability of many tools. • High-level Petri nets are Petri nets extended with – color (for the modeling of attributes) – time (for performance analysis) – hierarchy (for the structuring of models) 2

The classical Petri net model A Petri net is a network composed of places

The classical Petri net model A Petri net is a network composed of places ( ) and transitions ( ). t 2 t 1 p 2 p 1 t 3 p 4 p 3 • Connections, called arcs, are directed and between a place and a transition. • Tokens ( ) are the dynamic objects. • The state of a Petri net, called marking, is determined by the distribution of tokens over the places. • Initial marking (1, 2, 0, 0) 3

p 1 p 4 t 1 p 2 p 3 Transition t 1 has

p 1 p 4 t 1 p 2 p 3 Transition t 1 has three input places (p 1, p 2 and p 3) and two output places (p 3 and p 4). Place p 3 is both an input and an output place of t 1. 4

Enabling condition • Transitions are the active components, while places and tokens are passive.

Enabling condition • Transitions are the active components, while places and tokens are passive. • A transition is enabled if each of the input places contains tokens. t 1 t 2 • Transition t 1 is not enabled, transition t 2 is enabled. 5

Firing An enabled transition may fire. Firing corresponds to consuming tokens from the input

Firing An enabled transition may fire. Firing corresponds to consuming tokens from the input places and producing tokens for the output places. t 2 Firing is atomic. 6

Example 7

Example 7

Petri Net Structures • sequence of events/actions: t 1 t 2 t 3 t

Petri Net Structures • sequence of events/actions: t 1 t 2 t 3 t 4 t 5 • concurrent execution: t 1 8

Non-determinism t 1 Two transitions fight for the same token: conflict. Even if there

Non-determinism t 1 Two transitions fight for the same token: conflict. Even if there are two tokens, there is still a conflict. t 2 Synchronization t 1 9

Modeling • States of a process or a system are modeled by tokens in

Modeling • States of a process or a system are modeled by tokens in places and state transitions leading from one state to another are modeled by transitions. • Tokens represent objects (humans, goods, machines), information, conditions or states of objects. • Places represent buffers, channels, geographical locations, conditions or states. • Transitions represent events, transformations or transportations. 10

Example: Traffic light red yr yellow rg gy green 11

Example: Traffic light red yr yellow rg gy green 11

Two traffic lights red 1 red 2 yr 1 yr 2 yellow 1 rg

Two traffic lights red 1 red 2 yr 1 yr 2 yellow 1 rg 1 gy 1 yellow 2 rg 2 gy 2 green 1 green 2 12

Two safe traffic lights red 1 red 2 safe yr 1 yr 2 yellow

Two safe traffic lights red 1 red 2 safe yr 1 yr 2 yellow 1 rg 1 gy 1 yellow 2 rg 2 gy 2 green 1 green 2 13

Two safe and fair traffic lights red 1 red 2 safe 2 yr 1

Two safe and fair traffic lights red 1 red 2 safe 2 yr 1 yr 2 yellow 1 rg 1 yellow 2 gy 1 rg 2 gy 2 safe 1 green 2 14

Reachability • Reachable marking A marking is said to be reachable if it can

Reachability • Reachable marking A marking is said to be reachable if it can be reached by firing a sequence of enabled transitions form the initial marking of a Petri net. • Petri net token game http: //psim. tue. nl/staff/wvdaalst/Downloads/pn_applet. html 15

Exercise: readers and writers begin receive_mail_box rest type_mail read_mail send_mail ready • How many

Exercise: readers and writers begin receive_mail_box rest type_mail read_mail send_mail ready • How many states are reachable? • How to model the situation with 2 writers and 3 readers? • How to model a "bounded mailbox" (buffer size =4)? 16

Restaurant Scenario Waiter free Customer 1 Customer 2 Take order wait eating Serve food

Restaurant Scenario Waiter free Customer 1 Customer 2 Take order wait eating Serve food Order taken Tell kitchen wait eating Serve food 17

A Puzzle: Crossing River § A ferry-man has to bring a goat, a cabbage,

A Puzzle: Crossing River § A ferry-man has to bring a goat, a cabbage, and a wolf safely from the left bank to the right bank of a river. § The ferry-man cross the river alone or with exactly one of these three passengers. § At any time, either the ferry-man should be on the same bank as the goat, or the goat should be alone on a bank. § Otherwise, the goat could go ahead and eat the cabbage or the wolf may eat the goat 18

Modeling • We are going to model the situation with a Petri net. •

Modeling • We are going to model the situation with a Petri net. • The puzzle mentions the following objects: – Man, wolf, goat, cabbage, boat. • The puzzle mentions the following actions: – Crossing the river, wolf eats goat, goat eats cabbage. • Objects and their states are modeled by places. • Actions are modeled by transitions. • Actually, we can omit the boat, because it is always going to be on the same side as the man. 19

Places 20

Places 20

Crossing the river (left to right) 21

Crossing the river (left to right) 21

Crossing the river (left to right) 22

Crossing the river (left to right) 22

Crossing the river (left to right) 23

Crossing the river (left to right) 23

Crossing the river (right to left) 24

Crossing the river (right to left) 24

Wolf eats goat 25

Wolf eats goat 25

Formal Definition of a Petri Net A Petri net N is a tuple N

Formal Definition of a Petri Net A Petri net N is a tuple N = {P, T, I, O, M 0}, where § P is a finite set of places, § T is a finite set of transitions, § Places P and transitions T are disjoint (P ∩ T = f), § I: P × T N (N = {0, 1, 2, …})is the pre-incidence function representing input arcs, § O: T × P N (N = {0, 1, 2, …})is the post-incidence function representing output arcs, § M 0 : P N is the initial marking representing the initial distribution of tokens. 26

Example t 1 p 2 t 2 • • • t 3 P =

Example t 1 p 2 t 2 • • • t 3 P = {p 1, p 2} T = {t 1, t 2, t 3} I(t 1) = (1, 1), I(t 2) = (2, 0), I(t 3) = (0, 2) O(t 1) = ? M 0 = (3, 2) 27

Transition firing • A transition t is enabled at marking Mi if and only

Transition firing • A transition t is enabled at marking Mi if and only if Mi ≥ I(t) • Suppose that the firing of t takes the Petri net from Mi to Mi. Then Mj = Mi - I(t) + O(t) 28

t 1 p 2 t 2 • • • t 3 P = {p

t 1 p 2 t 2 • • • t 3 P = {p 1, p 2} T = {t 1, t 2, t 3} I(t 1) = (1, 1), I(t 2) = (2, 0), I(t 3) = (0, 2) O(t 1) = (1, 0), O(t 2) = (0, 1), O(t 3) = (0, 1) M 0 = (3, 2) Mj = Mi - I(t) + O(t) 29