Transcript Document

Petri nets
refresher
Prof.dr.ir. Wil van der Aalst
Eindhoven University of Technology, Faculty of Technology Management,
Department of Information and Technology, P.O.Box 513, NL-5600 MB,
Eindhoven, The Netherlands.
/faculteit technologie management
PN-1
free
Rules
wait
enter
before
make_picture
after
leave
gone
occupied
•
•
•
•
Connections are directed.
No connections between two places or two transitions.
Places may hold zero or more tokens.
First, we consider the case of at most one arc between
two nodes.
/faculteit technologie management
PN-5
Enabled
• A transition is enabled if each of its input places
contains at least one token.
free
wait
enter
before
make_picture
after
leave
gone
occupied
enabled
/faculteit technologie management
Not
enabled
Not
enabled
PN-6
Firing
• An enabled transition can fire (i.e., it occurs).
• When it fires it consumes a token from each
input place and produces a token for each
output place.
free
fired
wait
enter
before
make_picture
after
leave
gone
occupied
/faculteit technologie management
PN-7
Play “Token Game”
• In the new state, make_picture is enabled. It will fire, etc.
free
wait
enter
before
make_picture
after
leave
gone
occupied
/faculteit technologie management
PN-8
Remarks
• Firing is atomic.
• Multiple transitions may be enabled, but only one
fires at a time, i.e., we assume interleaving
semantics (cf. diamond rule).
• The number of tokens may vary if there are
transitions for which the number of input places is
not equal to the number of output places.
• The network is static.
• The state is represented by the distribution of
tokens over places (also referred to as marking).
/faculteit technologie management
PN-9
p4
Non-determinism
t34
p4
t43
t34
p3
t23
p3
t32
t23
transition t23
fires
p2
t12
t21
t01
t12
t21
p1
t10
p0
t32
p2
p1
Two transitions are
enabled but only
one can fire
t43
t01
t10
p0
/faculteit technologie management
PN-10
Playing the “Token Game” on the Internet
• Applet to build your own Petri nets and execute
them:
http://is.tm.tue.nl/staff/wvdaalst/workflowcourse/
pn_applet/pn_applet.htm
• FLASH animations: www.workflowcourse.com
/faculteit technologie management
PN-15
Exercise: Train system (1)
• Consider a circular railroad system with 4 (oneway) tracks (1,2,3,4) and 2 trains (A,B). No two
trains should be at the same track at the same
time and we do not care about the identities of
the two trains.
/faculteit technologie management
PN-16
Exercise: Train system (2)
• Consider a railroad system with 4 tracks
(1,2,3,4) and 2 trains (A,B). No two trains should
be at the same track at the same time and we
want to distinguish the two trains.
/faculteit technologie management
PN-17
Exercise: Train system (3)
• Consider a railroad system with 4 tracks
(1,2,3,4) and 2 trains (A,B). No two trains should
be at the same track at the same time.
Moreover the next track should also be free to
allow for a safe distance. (We do not care about
train identities.)
/faculteit technologie management
PN-18
Exercise: Train system (4)
• Consider a railroad system with 4 tracks
(1,2,3,4) and 2 trains. Tracks are free, busy or
claimed. Trains need to claim the next track
before entering.
/faculteit technologie management
PN-19
Multiple arcs connecting two nodes
• The number of arcs between an input place and
a transition determines the number of tokens
required to be enabled.
• The number of arcs determines the number of
tokens to be consumed/produced.
free
wait
enter
before
make_picture
after
leave
gone
/faculteit technologie management
PN-21
Reachability graph
•
•
The reachability graph of a Petri net is the part
of the transition system reachable from the
initial state in graph-like notation.
The reachability graph can be calculated as
follows:
1. Let X be the set containing just the initial state and let Y
be the empty set.
2. Take an element x of X and add this to Y. Calculate all
states reachable for x by firing some enabled transition.
Each successor state that is not in Y is added to X.
3. If X is empty stop, otherwise goto 2.
/faculteit technologie management
PN-33
Example
red
black
rb
rr
(3,2)
(3,1)
(3,0)
(1,3)
(1,2)
(1,1)
bb
(1,0)
Nodes in the reachability graph can be represented by a
vector “(3,2)” or as “3 red + 2 black”. The latter is useful for
“sparse states” (i.e., few places are marked).
/faculteit technologie management
PN-34
Exercise: Give the reachability graph using
both notations
rg1
rg2
g1
r1
go1
g2
x
go2
o1
or1
r2
o2
or2
/faculteit technologie management
PN-35
Different types of states
• Initial state: Initial distribution of tokens.
• Reachable state: Reachable from initial state.
• Final state (also referred to as “dead states”):
No transition is enabled.
• Home state (also referred to as home marking):
It is always possible to return (i.e., it is
reachable from any reachable state).
How to recognize these states in the reachability
graph?
/faculteit technologie management
PN-36
Exercise: Producers and consumers
• Model a process with one producer and one
consumer, both are either busy or free and
alternate between these two states. After every
production cycle the producer puts a product in
a buffer. The consumer consumes one product
from this buffer per cycle.
• Give the reachability graph and indicate the final
states.
• How to model 4 producers and 3 consumers
connected through a single buffer?
• How to limit the size of the buffer to 4?
/faculteit technologie management
PN-37
Exercise: Two switches
• Consider a room with two switches and one
light. The light is on or off. The switches are in
state up or down. At any time any of the
switches can be used to turn the light on or off.
• Model this as a Petri net.
• Give the reachability graph.
/faculteit technologie management
PN-38
Modeling
•
•
•
•
Place: passive element
Transition: active element
Arc: causal relation
Token: elements subject to change
The state (space) of a process/system is modeled
by places and tokens and state transitions are
modeled by transitions (cf. transition systems).
/faculteit technologie management
PN-39
Role of a token
Tokens can play the following roles:
• a physical object, for example a product, a part, a drug,
a person;
• an information object, for example a message, a
signal, a report;
• a collection of objects, for example a truck with
products, a warehouse with parts, or an address file;
• an indicator of a state, for example the indicator of the
state in which a process is, or the state of an object;
• an indicator of a condition: the presence of a token
indicates whether a certain condition is fulfilled.
/faculteit technologie management
PN-40
Role of a place
• a type of communication medium, like a
telephone line, a middleman, or a
communication network;
• a buffer: for example, a depot, a queue or a
post bin;
• a geographical location, like a place in a
warehouse, office or hospital;
• a possible state or state condition: for
example, the floor where an elevator is, or the
condition that a specialist is available.
/faculteit technologie management
PN-41
Role of a transition
• an event: for example, starting an operation, the
death of a patient, a change seasons or the
switching of a traffic light from red to green;
• a transformation of an object, like adapting a
product, updating a database, or updating a
document;
• a transport of an object: for example,
transporting goods, or sending a file.
/faculteit technologie management
PN-42
Typical network structures
•
•
•
•
•
Causality
Parallelism (AND-split - AND-join)
Choice (XOR-split – XOR-join)
Iteration (XOR-join - XOR-split)
Capacity constraints
– Feedback loop
– Mutual exclusion
– Alternating
/faculteit technologie management
PN-43
Causality
/faculteit technologie management
PN-44
Parallelism
/faculteit technologie management
PN-45
Parallelism: AND-split
/faculteit technologie management
PN-46
Parallelism: AND-join
/faculteit technologie management
PN-47
Choice: XOR-split
/faculteit technologie management
PN-48
Choice: XOR-join
/faculteit technologie management
PN-49
Iteration: 1 or more times
XOR-join before XOR-split
/faculteit technologie management
PN-50
Iteration: 0 or more times
XOR-join before XOR-split
/faculteit technologie management
PN-51
Capacity constraints: feedback loop
AND-join before AND-split
/faculteit technologie management
PN-52
Capacity constraints: mutual exclusion
/faculteit technologie management
AND-join before AND-split
PN-53
Capacity constraints: alternating
/faculteit technologie management
AND-join before AND-split
PN-54
We have seen most patterns, e.g.:
rg1
Example of
mutual
exclusion
rg2
g1
r1
go1
How to make
them
alternate?
/faculteit technologie management
g2
x
go2
o1
or1
r2
o2
or2
PN-55
Exercise: Witness statements
• As part of the process of handling insurance
claims there is the handling of witness
statements.
• There may be 0-10 witnesses per claim. After
an initialization step (one per claim), each of the
witnesses is registered, contacted, and informed
(i.e., 0-10 per claim in parallel). Only after all
witness statements have been processed a
report is made (one per claim).
• Model this in terms of a Petri net.
/faculteit technologie management
PN-61
Exercise: Dining philosophers
• 5 philosophers sharing 5 chopsticks: chopsticks are
located in-between philosophers
• A philosopher is either in state eating or thinking and
needs two chopsticks to eat.
• Model as a Petri net.
/faculteit technologie management
PN-62
Preview: Analysis
• Various types of analysis techniques:
– Simulation (repeatedly playing the token game)
– Reachability analysis (constructing the reachability
graph)
– Markovian analysis (reachability graph with transition
probabilities)
– Invariants: place invariants and transition invariants
(conservation of tokens and sequences without effect)
• Role of models: (1) insight, (2) analysis, and (3)
specification.
/faculteit technologie management
PN-63
Place invariant: Example
free
wait
enter
before
make_picture
after
leave
gone
occupied
wait+before+after+gone
free+occupied
/faculteit technologie management
PN-64
Transition invariant: Example
accident
free
wait
enter
before
make_picture
after
leave
gone
occupied
enter+make_picture+leave+accident
/faculteit technologie management
PN-65
High level Petri nets
Extending classical Petri nets with color,
time and hierarchy (informal introduction)
/faculteit technologie management
PN-66
Limitations of classical Petri nets
•
•
•
•
Inability to test for zero tokens in a place.
Models tend to become large.
Models cannot reflect temporal aspects
No support for structuring large models, cf. topdown and bottom-up design
/faculteit technologie management
PN-67
Inability to test for zero tokens in a place
t
?
p
“Tricks” only work if p is bounded
/faculteit technologie management
PN-68
Models tend to become (too) large
r2
r1
incr2
incr1
bell
decr2
decr1
l2
r4
incr3
wheel
bike
l1
r3
decr3
l3
r5
incr4
incr5
steering
wheel
frame
decr4
l4
decr5
l5
Size linear in the
number of
products.
/faculteit technologie management
PN-69
Models tend to become (too) large (2)
b1
transfer
b2
transfer
c1
b3
transfer
c2
b4
transfer
c3
c4
claim_track
f1
claim_track
f2
claim_track
f3
claim_track
f4
Size linear in the
number of tracks.
/faculteit technologie management
PN-70
Models cannot reflect temporal aspects
rg1
rg2
g1
r1
go1
Duration of each
phase is highly
relevant.
g2
x
go2
o1
or1
r2
o2
or2
/faculteit technologie management
PN-71
No support for structuring large models
rg1
rg2
g1
r1
go1
g2
x
go2
o1
or1
r2
o2
or2
/faculteit technologie management
PN-72
High-level Petri nets
• To tackle the problems identified.
• Petri nets extended with:
– Color (i.e., data)
– Time
– Hierarchy
• For the time being be do not choose a concrete
language but focus on the main concepts.
• Later we focus on a concrete language: CPN.
• These concepts are supported by many variants
of CPN including ExSpect, CPN AMI, etc.
/faculteit technologie management
PN-73
Running example: Making punch cards
free
free desk
employees
wait
done
start
stop
busy
waiting
patients
patient/
employees
served
patients
/faculteit technologie management
PN-74
Extension with color (1)
• Tokens have a color (i.e., a data value)
{Brand="BMW", RegistrationNo="GD-XW-11", Year=1993, Colour="blue", Owner= "Inge"}
{Brand="Lada", RegistrationNo="PH-14-PX", Year=1986, Color="grey", Owner="Inge"}
/faculteit technologie management
PN-75
Extension with color (2)
• Places are typed (also referred to as color set).
record Brand:string * RegistrationNo:string * Year:int *
Color:string * Owner:string
{Brand="BMW", RegistrationNo="GD-XW-11", Year=1993, Colour="blue", Owner= "Inge"}
{Brand="Lada", RegistrationNo="PH-14-PX", Year=1986, Color="grey", Owner="Inge"}
/faculteit technologie management
PN-76
Extension with color (3)
• The relation between production and
consumption needs to be specified, i.e., the
value of a produced token needs to be related
to the values of consumed tokens.
3
in
sum
2
3
add
1
/faculteit technologie management
0
The value of the token produced for
place sum is the sum of the values of
the consumed tokens.
PN-77
Running example: Tokens are colored
{EmpNo=641112, Experience=7}
wait
done
start
free
stop
busy
{Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M"}
/faculteit technologie management
PN-78
Running example: Places are typed
record EmpNo:int * Experience:int
wait
done
start
free
stop
record Name:string *
record Name:string *
Address:string *
Address:string *
busy
DateOfBirth:str *
record
Name:string
*
DateOfBirth:str *
Gender:string
Address:string
*
Gender:string
DateOfBirth:str *
Gender:string *
EmpNo:int *
/faculteit technologie management Experience:int
PN-79
Running example: Initial state
{EmpNo=641112, Experience=7}
wait
done
start
free
stop
busy
{Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M"}
start is enabled
/faculteit technologie management
PN-80
Running example: Transition start fired
New value is created by simply merging the two records.
wait
done
start
free
stop
busy
{Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M", EmpNo=641112, Experience=7}
stop is enabled
/faculteit technologie management
PN-81
Running example: Transition stop fired
{EmpNo=641112, Experience=7}
wait
done
start
free
stop
busy
{Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M"}
New values are created by simply spliting the record into two parts.
/faculteit technologie management
PN-82
The number of tokens produced is no longer
fixed (1)
{sample_number=931101011, measurement_outcomes="XYV"}
positive
test
sample
negative
{sample_number=931101023, measurement_outcomes="VXY"}
Note that the network structure is no longer a complete
specification!
/faculteit technologie management
PN-83
The number of tokens produced is no longer
fixed (2)
{sample_number=931101011, measurement_outcomes="XYV"}
positive
test
sample
negative
The number of tokens produced for each output place is
between 0 and 3 and the sum should be 3.
/faculteit technologie management
PN-84
r2
r1
r3
r4
r5
Example
incr2
incr1
wheel
bike
bell
decr2
decr1
l1
incr3
l2
decr3
l3
incr4
incr5
steering
wheel
frame
decr4
l4
decr5
l5
Model as a colored Petri net.
/faculteit technologie management
PN-85
in
{prod="bell", num=2}
Product and
quantity are in
the value of the
token
The entire
stock is
represented by
the value of a
single token,
i.e., a list of
records.
/faculteit technologie management
increase
[{prod="bike", num=4},
{prod="wheel", num=2},
{prod="bell", number=3},
{prod="steering wheel", num=3},
{prod="frame", num=2}]
stock
decrease
out
PN-86
in
{prod="bell", num=2}
Types
StockItem
increase
[{prod="bike", num=4},
{prod="wheel", num=2},
{prod="bell", number=3},
{prod="steering wheel", num=3},
{prod="frame", num=2}]
stock
Stock
color Product = string;
color Number = int;
decrease
color StockItem = record
prod:Product * num:Number;
color Stock = list StockItem;
/faculteit technologie management
StockItem
out
PN-87
Extension with time (1)
• Each token has a timestamp.
• The timestamp specifies the earliest time when
it can be consumed.
2
5
/faculteit technologie management
PN-88
Extension with time (2)
• The enabling time of a transition is the maximum
of the tokens to be consumed.
• If there are multiple tokens in a place, the earliest
ones are consumed first.
• A transition with the smallest firing time will fire first.
• Transitions are eager, i.e., they fire as soon as they
can.
• Produced token may have a delay.
• The timestamp of a produced token is the firing
time plus its delay.
/faculteit technologie management
PN-89
Running example: Enabling time
• Transition start is enabled at time 2 =
max{0,min{2,4,4}}.
0
4
wait
done
2
start
free
stop
4
busy
/faculteit technologie management
PN-90
Running example: Delays
• Tokens for place busy get a delay of 3
• @+3 = firing time plus 3 time units
0
4
@+0
wait
2
start
free
@+3
done
stop
@+0
4
/faculteit technologie management
busy
PN-91
Running example: Transition start fired
• Transition start fired a time 2.
4
wait
@+0
free
start
done
stop
@+3
@+0
5
4
busy
Continue to play (timed) token game…
/faculteit technologie management
PN-92
Exercise: Final state?
a
1
d
x
@+1
3
b
5
c
e
y
@+2
4
/faculteit technologie management
PN-93
Exercise: Final state?
3
red
1
black
@+2
4
rb
2
2
@+1
@+1
rr
bb
/faculteit technologie management
PN-94
Extension with hierarchy
• Timed and colored Petri nets result in more
compact models.
• However, for complex systems/processes the
model does not fit on a single page.
• Moreover, putting things at the same level does
not reflect the structure of the process/system.
• Many hierarchy concepts are possible. In this
course we restrict ourselves to transition
refinement.
/faculteit technologie management
PN-95
Instead of
rg1
rg2
g1
r1
go1
g2
x
go2
o1
or1
r2
o2
or2
/faculteit technologie management
PN-96
We can use hierarchy
tl1
tl2
x
rg1
rg2
g1
r1
g2
go1
go2
x
x
o1
or1
r2
o2
or2
/faculteit technologie management
PN-97
Reuse
tl1
tl2
x
• Reuse saves design
efforts.
• Hierarchy can have
any number of
levels
• Transition
refinement can be
used for top-down
and bottom-up
design
/faculteit technologie management
rg
g
go
r
x
o
or
PN-98
Exercise: model three (parallel) punch card
desks in a hierarchical manner
free
wait
done
start
stop
busy
/faculteit technologie management
PN-99