Upload
ethelbert-reed
View
216
Download
0
Tags:
Embed Size (px)
Citation preview
Ch5: Software Specification
2
Petri Nets
Introduced by C. Adams Petri in 1960. Widely used in the modeling and analysis of computer
systems. Basic elements:
Places Transitions Directed arcs Tokens
3
Petri Nets
Legend:
Place
TransitionDirected arc
P1
P2
P3
t1
Token
4
Petri Nets (contd..)
P1
P2
P3
t1
Input place:
Output place:
5
Petri Nets (contd..)
P1
P2
P3
t12
Weighted connection: Default weight is 1.
6
Petri Nets (contd..)
Net structure:
Marking: Overall state.
Marked vs. Unmarked places: Places with zero or more tokens.
Local state vs. Global state: Number of tokens in a place, number of tokens in all places.
7
Petri Nets (contd..)
P1
P2
P3
t1
Local State: P1 – 1 P2 – 0 P3 – 0Overall State: <1,0,0>
8
Petri Nets (contd..)
Dynamic behavior:
Firing of transitions
Transition firing:
Tokens from input place are moved to output place Evolution of the net Steps involved in firing of a transition
9
Petri Nets (contd..)
Step #1
P1
P2
P3
t12
10
Petri Nets (contd..)
P1
P2
P3
t12
Step 2
11
Petri Nets (contd..)
P1
P2
P3
t12
Step 3:
12
Petri Nets (contd..)
Enabled transitions not forced to fire Can be subject to external conditions Ordinary Petri net, firing of transitions occurs instantly
13
Petri Nets (contd..)
Machine Idle LoadingPart
Operationin Progress
UnloadingPart
Robot Idle
Petri Nets: Manufacturing Example
Place represents availability of a resource.
14
Petri Nets (contd..)
User & Candy
User hascoin
Machineready
User hascandy
Machine busy
eat resetDispensecandy
15
Petri nets (contd..)
Petri nets may be used to model concurrent systems Concurrent transitions:
Petri nets are non-deterministic
16
Petri nets (contd..)
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
Transitions t1 and t2 are both enabled.Any one of t1 and t2 can fire.
17
Petri nets (contd..)
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
Before t1 fires After t1 firesWhich transitions are enabled?
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
18
Petri nets (contd..)
Before t2 fires After t2 firesWhich transitions are enabled?
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
19
Petri nets (contd..)
Before t1 & t2 fire Firing sequence t1,t2 t2,t1
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
20
Petri nets (contd..)
Before t3 fires After t3 fires
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
21
Petri nets (contd..)
Before t4 fires After t4 fires
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
P
P
P
t
tP
t
1
3
1
3
4
6
5
P
P
P
2
5
7
t
t
t
2
4
6
22
Petri nets (contd..)
Transitions t3 and t4 were both enabled:
Conflict
A process may never get a resource (starvation)
23
Petri nets (contd..)
P P
P
P P
t t
t t
P P
t t
1
1 2
3
4
5
6
7
4
2
3
6
5
How to avoid starvation
24
Petri nets (contd..)
How to avoid starvation
Transition t1 fires.Which transitionsare enabled?
P P
P
P P
t t
t t
P P
t t
1
1 2
3
4
5
6
7
4
2
3
6
5
25
Petri nets (contd..)
How to avoid starvation
Transition t3 fires.Which transitionsare enabled?
P P
P
P P
t t
t t
P P
t t
1
1 2
3
4
5
6
7
4
2
3
6
5
26
Petri nets (contd..)
How to avoid starvation
Transition t5 fires.Which transitionsare enabled?
P P
P
P P
t t
t t
P P
t t
1
1 2
3
4
5
6
7
4
2
3
6
5
27
Petri nets (contd..)
How to avoid starvation
Transition t2 fires.Which transitionsare enabled?
P P
P
P P
t t
t t
P P
t t
1
1 2
3
4
5
6
7
4
2
3
6
5
28
Petri nets (contd..)
Firing sequence: t1, t3, t5 Firing sequence: t2, t4, t6 The shared resource alternates between the two
processes
29
Petri nets (contd..)
Deadlock:
Live:
30
Petri nets (contd..)
Initial state of the net
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
31
Petri nets (contd..)
Transition t1 fires
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
32
Petri nets (contd..)
Transition t3’ fires
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
33
Petri nets (contd..)
Transition t2 fires
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
34
Petri nets (contd..)
Transition t4’ fires
No transition is enabled.The net is deadlocked.
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
35
Petri nets (contd..)
R
P P
t t
t'
t"
t
t'
t"
t
1
1
3
3
2
2
4
4
56
2 2
2 2
A deadlock free net
36
Petri nets: Limitations
Tokens are anonymous:
Cannot compute the value of a token No selection policy to decide between different enabled
transitions
Lack exact timing constraints
37
Petri nets: Limitations and extensions
P
channel1 channel2
Token represents a message.Delivery channel depends on the contents. Correct message goesThrough one channel, incorrect through the other one.
38
Petri nets: Limitations and extensions
Assign values to tokens Predicates and functions can be associated with
transitions
Firing of a transition implies:
Ready tokens consumed from input places h new tokens produced by the function associated with the
transition go to output places.
39
Petri nets: Limitations and extensions
PP
P
PP
34
71 4
t t1 2
45
12
3
Assigning values to tokens
40
Petri Net: Case Study
Consider the process of producing a document in an organization. Each document is written by two technical writers, one technical writer isresponsible for writing the text, while the other writer is responsible for drawing and inserting figures. When the technical writers completetheir respective pieces, these pieces are merged into a single draft. This draft is then forwarded to the manager for review. Upon review the manager prints this draft using a printer. The printer is usually available except when it is offline for either maintenance or repair. Draw a Petri net model to represent the document production process.
41
Petri Nets: Case Study
WrtTxt DrwFg
DrwFgCmpWrtTxtCmp
MrgDoc RvDoc PrDoc
PrOn PrOff