320 likes | 904 Views
SE-561 Formal Methods in Software Petri Nets - I. 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.
E N D
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)
The classical Petri net model A Petri net is a network composed of places ( ) and transitions ( ). t2 p2 t1 p1 p4 t3 p3 • 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)
p1 p4 t1 Transition t1 has three input places (p1, p2 and p3) and two output places (p3 and p4). Place p3 is both an input and an output place of t1. p2 p3
t1 t2 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. • Transition t1 is not enabled, transition t2 is enabled.
t2 t2 Firing An enabled transition may fire. Firing corresponds to consuming tokens from the input places and producing tokens for the output places. Firing is atomic.
t2 t3 t1 t3 t2 t1 t5 t4 Petri Net Structures • sequence of events/actions: • concurrent execution:
t1 Non-determinism t1 Two transitions fight for the same token: conflict. Even if there are two tokens, there is still a conflict. t2 Synchronization
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.
red yr yellow rg gy green Example: Traffic light
red1 red2 yr1 yr2 yellow1 yellow2 rg1 rg2 gy1 gy2 green1 green2 Two traffic lights
red1 red2 safe yr1 yr2 yellow1 yellow2 rg1 rg2 gy1 gy2 green1 green2 Two safe traffic lights
Two safe and fair traffic lights red1 red2 safe2 yr1 yr2 yellow1 yellow2 rg1 rg2 gy1 gy2 safe1 green1 green2
Reachability • Reachable markingA 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.tm.tue.nl/staff/wvdaalst/Downloads/pn_applet/pn_applet.html
Exercise: readers and writers begin receive_mail • 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)? mail_box rest rest type_mail read_mail send_mail ready
Waiter free Customer 1 Customer 2 Take order Take order wait Order taken wait eating eating Tell kitchen Serve food Serve food Restaurant Scenario
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 can 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
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.
Formal Definition of a Petri Net A Petri net N is a tuple N = {P, T, I, O, M0}, 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, • M0 : P N is the initial marking representing the initial distribution of tokens.
Example t1 • P = {p1, p2} • T = {t1, t2, t3} • I(t1) = (1, 1), I(t2) = (2, 0), I(t3) = (0, 2) • O(t1) = ? • M0 = (3, 2) p1 p2 t2 t3
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)
t1 p1 p2 t2 t3 • P = {p1, p2} • T = {t1, t2, t3} • I(t1) = (1, 1), I(t2) = (2, 0), I(t3) = (0, 2) • O(t1) = (1, 0), O(t2) = (0, 1), O(t3) = (0, 1) • M0 = (3, 2) Mj= Mi- I(t) + O(t)