Process modeling - Monmouth University

Download Report

Transcript Process modeling - Monmouth University

SE-561
Formal Methods in Software
Petri Nets - I
1
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 ( ) and transitions ( ).
t2
t1
p2
p1
t3
p4
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)
3
p1
p4
t1
p2
p3
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.
4
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.
t1
t2
• Transition t1 is not enabled, transition t2 is enabled.
5
Firing
An enabled transition may fire.
Firing corresponds to consuming tokens from the input places and
producing tokens for the output places.
t2
t2
Firing is atomic.
6
Example
7
Petri Net Structures
• sequence of events/actions:
t1
t2
t3
t2
t3
t4
t5
• concurrent execution:
t1
8
Non-determinism
t1
Two transitions fight for the same token: conflict.
Even if there are two tokens, there is still a conflict.
t2
Synchronization
t1
9
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
Two traffic lights
red1
red2
yr1
yr2
yellow1
rg1
gy1
yellow2
rg2
gy2
green1
green2
12
Two safe traffic lights
red1
red2
safe
yr1
yr2
yellow1
rg1
gy1
yellow2
rg2
gy2
green1
green2
13
Two safe and fair traffic lights
red1
red2
safe2
yr1
yr2
yellow1
rg1
yellow2
gy1
rg2
gy2
safe1
green1
green2
14
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.tm.tue.nl/staff/wvdaalst/Downloads/pn_applet/pn_applet.html
15
Exercise: readers and writers
begin
receive_mail
mail_box
rest
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
Take
order
wait
Order
taken
wait
eating
eating
Serve food
Tell
kitchen
Serve food
17
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
18
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
Crossing the river (left to right)
21
Crossing the river (left to right)
22
Crossing the river (left to right)
23
Crossing the river (right to left)
24
Wolf eats goat
25
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.
26
Example
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) = ?
M0 = (3, 2)
27
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
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)
29