Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Modelling and Simulation / 4th year

Practical session 1

Petri Nets
Introduction:
- Petri nets were introduced in 1962 by Dr. Carl Adam Petri
- A powerful modeling formalism in computer science
- Petri nets combine:
- Mathematical theory (modeling and analysis of system behavior)
- Graphical representation of the dynamic behavior of systems
(state changes)
- good for modelling:
- Concurrency
- Synchronization
Definition:
- Petri net is a particular kind of bipartite (2-nodes) directed graphs with
three types of objects.

Places represent possible states of the system


(circles)
Transitions events or actions which cause the change of
(rectangles) state
Directed arc(arrow) connect place – transition , weight k=k
directed (parallel) arcs connecting p-t

- its simplest form , a transition together with an input place and an output
place , may be used for example to represent a data processing event in a
data processing system (modeled system)
- study the dynamic behavior of a Petri net modeled system in terms of its
states and state changes , each place may potentially hold either none or a
positive number of tokens.
- Tokens can represent : resource availability , jobs to perform , fulfillment
of the condition,….
Petri net structure:
- A Petri net is composed of 5 parts, PN(P,T,I,O,M0):

- P  { p1 , p 2 ,....... p m } is a finite set of places


- T  {t1 , t 2 ,.......t n } is a finite set of transitions
- I : ( P  T )  N is an input function that defines the weight of the directed
arcs from places to transitions

1
Modelling and Simulation / 4th year
Practical session 1

- O : (T  P)  N is an output function that defines the weight of the directed


arcs from transitions to places
- M 0 : P  N is the initial marking (Initial distribution of tokens among
places)
- Marking is an assignment of tokens to the places of a PN.
- A Change of system state : is denoted by a movement of token(s) (black
dots) from place(s) to place(s) caused by firing of a transition
(occurrence of event or action) .

- Example 1: A simple Petri net

.
Transition Firing:

- Execution of a PN is controlled by the number and distribution of tokens


- A Petri net executes by firing transitions.

(1) Enabling Rule: A transition t is said to be enabled if each input place


p of t contains at least the number of tokens equal to the weight of the
directed arc connecting p to t, i.e., M(p) >= I(t, p) for any p in P.
(2) Firing Rule: Only enabled transition can fire. The firing of an
enabled transition t removes from each input place p the number of
tokens equal to the weight of the directed arc connecting p to t.it also
deposits in each output place p the number of tokens equal to the
weight of the directed arc connecting t to p.
- Mathematically, firing t at M yields a new marking
M `(p) = M(p)  I(t, p) + O(t, p) for any p in P.

2
Modelling and Simulation / 4th year
Practical session 1

Examples:

Enabling Rule :
(a) Enabled
(b) Disabled

(a) (b)

Firing Rule:

3
Modelling and Simulation / 4th year
Practical session 1

Behavioural properties:

1) Reachability
Can we reach one
particular state from
intial state?

When studying the dynamics of Petri nets, it is often desirable to know if the given
marking M1 can be reached from the initial marking M0 or if an undesirable
marking M2 can be avoided.
Therefore, it is necessary to know if there is a firing sequence that can bring the net to
a new marking.

 The firing of an enabled transition will change the token distribution (marking)
in a net
 A marking M is said to be reachable from M0 (initial marking) if there exists a
sequence of firings of transitions σ that transforms M0 to M .
 A firing sequence is denoted by σ=t1 t2 t3 ….tn .

4
Modelling and Simulation / 4th year
Practical session 1

2) Bounded and safe


Will a storage
place overflow?

It is often desirable to know whether Petri net model is bounded. The bounded
property is especially useful when we want to define the size of the system or to
reveal some design errors.

5
Modelling and Simulation / 4th year
Practical session 1

A place p is said to be k-bounded if the number of tokens in p is always less or


equal to k ( nonnegative integer number) for every marking M reachable from the
Initial marking M0
A Petri net PN(P,T,I,O,M0) is k-bounded if each place P gets at most k
tokens for all markings belonging to the reachability set.

A place in a Petri net is safe if the number of tokens in that place never exceeds
one (The number of tokens in that place is either 0 or 1) .

A Petri net is safe if all places in the net are safe.


Safety is a special case of bounded. Any net that is 1-bounded is safe.

Note
The concept of safe and bounded nets is independent of the firing sequences. It
should be noticed that bounded indicates the finiteness of reachability space.

Places in a Petri net are often used to represent buffers and registers for
storing intermediate data. By verifying that the net is bounded or safe, it is
guaranteed that there will be no overflows in the buffers or registers, no matter
what firing sequence is taken.

6
Modelling and Simulation / 4th year
Practical session 1

3) Live
Will the system die in
a particular state ?

The concept of live is closely related to the complete absence of deadlocks in


operating systems.
A Petri net is said to be live if, no matter what marking has been reached from M0 ,
it is possible to ultimately fire any transition of the net by progressing through some
further firing sequence.
This means that a live Petri net guarantees deadlock-free operation, no matter what
firing sequence is chosen.

It’s easier to prove if a petri net is alive by proving that it’s not dead because there are
only two cases in which a petri net is said to be dead:
1. There is a transition that is impossible to get enabled, which can be
represented in a reachability graph by the absence of that impossible
transition.
2. After some firing sequence, there is no enabled transition, which can be
represented in a reachability graph by the existence of a leaf marking.

Non_live Petri net Live Petri net

7
Modelling and Simulation / 4th year
Practical session 1

4) Reversibility
A Petri net is said to be reversible if for each marking M , M0 is reachable from M .
Thus, in reversible net one can always get back to the initial marking or state.
Existence of the reversibility ensures that the system can always recover the normal
behavior and is important for systems subject to failures.

5) Persistence
A PN is persistent if, for any two enabled transitions, the firing of one of them will
not disable the other. Then, once a transition is enabled, it remains enabled until it’s
fired. Persistency means conflict-free nets.
In other words, we can say: no action can disable another one.
The notion of persistence is useful in the context of parallel program.

Examples:
Explain behavioral properties (Bounded – Live- Reversibility- persistence) for
the following nets:

Unbounded, not live , not reversible, Unbounded, live , not reversible ,


persistent persistent

8
Modelling and Simulation / 4th year
Practical session 1

Bounded, not live , not reversible, not Unbounded, live , reversible, persistent
persistent

Bounded, live , reversible , persistent Bounded, not live , reversible, not


persistent

Modeling with Petri Nets

How Petri net handles real life modeling situations, thus revealing the
modeling power and ease of representation of Petri net

Sequential Transition t2 can fire


execution only after the firing of t1

concurrency - forking transition that


deposits tokens
simultaneously in two or
more output places

- t1,t2,t3 are concurrent

9
Modelling and Simulation / 4th year
Practical session 1

Synchronization - t1 will fire only when


the empty input place p2
gets a token.
- Thus, the three input
places of t1 are
synchronized for the
firing of transition t
mutually - cannot be performed at
exclusive the same time due to
events constraints on the usage
of shared resources
(processes)
- If the shared resources
in place p1 is used by
process 1, it is forbidden
for process 2.

conflict - three transitions are


enabled but Firing one
will lead to the disabling
of other transitions
- The conflict is
resolved in a non-
deterministic way
priority - t2 can’t firing before
t1
- t1 is enabled if p1
contains a token
- t2 is enabled if p2
contains a token and p1
has no token
- this give priority to t1
over t2(inhibitor arc)

- In the presence of the Inhibitor arc , a transition is regarded as


enabled if no tokens are present in each input place connected to the
transition by the Inhibitor arc and input places connected to the
transition by the normal arc contain at least tokens equal to the
weight of the arc.

10

You might also like