Petri Nets Refesher: Prof - Dr.ir. Wil Van Der Aalst

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 159

Petri nets refesher

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

Petri nets
Classical Petri nets: The basic model

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-2

Process modeling
Emphasis on dynamic behavior rather than structuring the state space Transition system is too low level We start with the classical Petri net Then we extend it with:
Color Time Hierarchy

/faculteit technologie management


PN-3

Classical Petri net


Simple process model
Just three elements: places, transitions and arcs. Graphical and mathematical description. Formal semantics and allows for analysis.

History:
Carl Adam Petri (1962, PhD thesis) In sixties and seventies focus mainly on theory. Since eighties also focus on tools and applications (cf. CPN work by Kurt Jensen). Hidden in many diagramming techniques and systems.
/faculteit technologie management
PN-4

p4 place

Elements
(name) place

t34 p3

t43

transition

t23 p2

t32

(name)

transition

token

arc (directed connection)


t12 t21 p1

token

t01 p0

t10

/faculteit technologie management


PN-5

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.
PN-6

/faculteit technologie management

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-7

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-8

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-9

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-10

Non-determinism
t34

p4

p4

t43 p3

t34 p3

t43

t23 p2

t32 transition t23 fires

t23 p2

t32

t12 p1

t21

t12 p1

t21

Two transitions are enabled but only one can fire


/faculteit technologie management

t01 p0

t10

t01 p0

t10

PN-11

Example: Single traffic light

rg

green

red

go

orange

or
/faculteit technologie management
PN-12

Two traffic lights


rg rg

rg

green
green green

red

go

red

go

OR
orange

red

go

orange

or

or

orange

or
/faculteit technologie management
PN-13

Problem

/faculteit technologie management


PN-14

Solution
rg1 rg2

g1

g2

r1

go1

go2

r2

How to make them alternate?


or1

o1

o2

or2
PN-15

/faculteit technologie management

Playing the Token Game on the Internet


Applet to build your own Petri nets and execute them: http://www.tm.tue.nl/it/staff/wvdaalst/Downloads/ pn_applet/pn_applet.html FLASH animations: http://www.tm.tue.nl/it/staff/wvdaalst/courses/pm /flash/

/faculteit technologie management


PN-16

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-17

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-18

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-19

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-20

WARNING
It is not sufficient to understand the (process) models. You have to be able to design them yourself !
/faculteit technologie management
PN-21

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-22

Example: Ball game


red rb black

rr

bb

/faculteit technologie management


PN-23

Exercise: Manufacturing a chair


Model the manufacturing of a chair from its components: 2 front legs, 2 back legs, 3 cross bars, 1 seat frame, and 1 seat cushion as a Petri net. Select some sensible assembly order. Reverse logistics?
/faculteit technologie management
PN-24

Exercise: Burning alcohol.


Model C2H5OH + 3 * O2 => 2 * CO2 + 3 * H2O Assume that there are two steps: first each molecule is disassembled into its atoms and then these atoms are assembled into other molecules.

/faculteit technologie management


PN-25

Exercise: Manufacturing a car


Model the production process shown in the BillOf-Materials.
car

subassembly2
engine 2 chair subassembly1 4 chassis
/faculteit technologie management
PN-26

wheel

Formal definition
A classical Petri net is a four-tuple (P,T,I,O) where: P is a finite set of places, T is a finite set of transitions, I : P x T -> N is the input function, and O : T x P -> N is the output function. Any diagram can be mapped onto such a four tuple and vice versa.
/faculteit technologie management
PN-27

Formal definition (2)


The state (marking) of a Petri net (P,T,I,O) is defined as follows: s: P-> N, i.e., a function mapping the set of places onto {0,1,2, }.

/faculteit technologie management


PN-28

Exercise: Map onto (P,T,I,O) and S


red rb black

rr

bb

/faculteit technologie management


PN-29

Exercise: Draw diagram


Petri net (P,T,I,O): P = {a,b,c,d} T = {e,f} I(a,e)=1, I(b,e)=2, I(c,e)=0, I(d,e)=0, I(a,f)=0, I(b,f)=0, I(c,f)=1, I(d,f)=0. O(e,a)=0, O(e,b)=0, O(e,c)=1, O(e,d)=0, O(f,a)=0, O(f,b)=2, O(f,c)=0, O(f,d)=3. State s: s(a)=1, s(b)=2, s(c)=0, s(d) = 0.
/faculteit technologie management
PN-30

Enabling formalized
Transition t is enabled in state s1 if and only if:

/faculteit technologie management


PN-31

Firing formalized
If transition t is enabled in state s1, it can fire and the resulting state is s2 :

/faculteit technologie management


PN-32

Mapping Petri nets onto transition systems


A Petri net (P,T,I,O) defines the following transition system (S,TR):

/faculteit technologie management


PN-33

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-34

Example
red rb black

(3,2)

(3,1)

(3,0)

(1,3)
rr bb

(1,2)

(1,1)

(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-35

Exercise: Give the reachability graph using both notations


rg1 rg2

g1

g2

r1

go1

go2

r2

o1

o2

or1

or2

/faculteit technologie management


PN-36

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-37

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-38

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-39

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-40

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-41

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-42

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-43

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-44

Causality

/faculteit technologie management


PN-45

Parallelism

/faculteit technologie management


PN-46

Parallelism: AND-split

/faculteit technologie management


PN-47

Parallelism: AND-join

/faculteit technologie management


PN-48

Choice: XOR-split

/faculteit technologie management


PN-49

Choice: XOR-join

/faculteit technologie management


PN-50

Iteration: 1 or more times

XOR-join before XOR-split


/faculteit technologie management
PN-51

Iteration: 0 or more times

XOR-join before XOR-split


/faculteit technologie management
PN-52

Capacity constraints: feedback loop

AND-join before AND-split


/faculteit technologie management
PN-53

Capacity constraints: mutual exclusion

/faculteit technologie management

AND-join before AND-split


PN-54

Capacity constraints: alternating

/faculteit technologie management

AND-join before AND-split


PN-55

We have seen most patterns, e.g.:


Example of mutual exclusion
rg1 rg2

g1

g2

r1

go1

go2

r2

How to make them alternate?


/faculteit technologie management
or1

o1

o2

or2

PN-56

Exercise: Manufacturing a car (2)


Model the production process shown in the Bill-Of-Materials with car resources. Each assembly step engine requires a dedicated machine and an operator. There are two operators subassembly1 and one machine of each type. 4 Hint: model both the wheel start and completion of an assembly step.
PN-57

subassembly2
2 chair

chassis
/faculteit technologie management

Modeling problem (1): Zero testing


Transition t should fire if place p is empty.

p
/faculteit technologie management
PN-58

Solution
Only works if place is N-bounded
N input and output arcs

t p

Initially there are N tokens

p
/faculteit technologie management
PN-59

Modeling problem (2): Priority


Transition t1 has priority over t2

t1

?
t2
/faculteit technologie management

Hint: similar to Zero testing!


PN-60

A bit of theory
Extensions have been proposed to tackle these problems, e.g., inhibitor arcs. These extensions extend the modeling power (Turing completeness*). Without such an extension not Turing complete. Still certain questions are difficult/expensive to answer or even undecidable (e.g., equivalence of two nets).
* Turing completeness corresponds to the ability to execute any computation.
/faculteit technologie management
PN-61

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-62

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-63

High level Petri nets


Extending classical Petri nets with color, time and hierarchy (informal introduction)
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-64

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-65

Inability to test for zero tokens in a place

p
Tricks only work if p is bounded
/faculteit technologie management
PN-66

Models tend to become (too) large


r1 r2 r3 r4 r5

incr1

incr2

incr3

incr4

incr5

bike

wheel

bell

steering wheel

frame

decr1

decr2

decr3

decr4

decr5

l1

l2

l3

l4

l5

Size linear in the number of products.


PN-67

/faculteit technologie management

Models tend to become (too) large (2)


b1 transfer c1 claim_track f1 f2 f3 f4 transfer c2 b2 transfer c3 b3 transfer c4 b4

claim_track

claim_track

claim_track

Size linear in the number of tracks.


/faculteit technologie management
PN-68

Models cannot reflect temporal aspects


rg1 rg2

g1

g2

r1

go1

go2

r2

Duration of each phase is highly relevant.


or1

o1

o2

or2
PN-69

/faculteit technologie management

No support for structuring large models


rg1 rg2

g1

g2

r1

go1

go2

r2

o1

o2

or1

or2
PN-70

/faculteit technologie management

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-71

Running example: Making punch cards


free

free desk employees


done

wait start stop

busy

waiting patients
/faculteit technologie management

patient/ employees

served patients
PN-72

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-73

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-74

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 2 3 1 add sum 0

/faculteit technologie management

The value of the token produced for place sum is the sum of the values of the consumed tokens.
PN-75

Running example: Tokens are colored


{EmpNo=641112, Experience=7}

wait start free stop

done

busy {Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M"}

/faculteit technologie management


PN-76

Running example: Places are typed


record EmpNo:int * Experience:int
wait start free stop done

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-77

Running example: Initial state


{EmpNo=641112, Experience=7}

wait start free stop

done

busy {Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M"}

start is enabled
/faculteit technologie management
PN-78

Running example: Transition start fired


New value is created by simply merging the two records.

wait start free stop

done

busy

{Name="Klaas", Address="Plein 10", DateOfBirth="13-Dec-1962", Gender="M", EmpNo=641112, Experience=7}

stop is enabled
/faculteit technologie management
PN-79

Running example: Transition stop fired


{EmpNo=641112, Experience=7}

wait start free stop

done

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-80

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-81

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-82

r1

r2

r3

r4

r5

Example
incr1 incr2 incr3 incr4 incr5

bike

wheel

bell

steering wheel

frame

decr1

decr2

decr3

decr4

decr5

l1

l2

l3

l4

l5

Model as a colored Petri net.


/faculteit technologie management
PN-83

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

stock

[{prod="bike", num=4}, {prod="wheel", num=2}, {prod="bell", number=3}, {prod="steering wheel", num=3}, {prod="frame", num=2}]

decrease

out
PN-84

in

Types
increase

{prod="bell", num=2}

StockItem

stock

color Product = string; color Number = int;

Stock
decrease

[{prod="bike", num=4}, {prod="wheel", num=2}, {prod="bell", number=3}, {prod="steering wheel", num=3}, {prod="frame", num=2}]

color StockItem = record prod:Product * num:Number; color Stock = list StockItem;


/faculteit technologie management

StockItem
out
PN-85

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-86

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-87

Running example: Enabling time


Transition start is enabled at time 2 = max{0,min{2,4,4}}.
0 4 wait 2 start free stop done

4 busy
/faculteit technologie management
PN-88

Running example: Delays


Tokens for place busy get a delay of 3 @+3 = firing time plus 3 time units
0 4 wait 2 start @+3 free @+0 done stop @+0

4
/faculteit technologie management

busy
PN-89

Running example: Transition start fired


Transition start fired a time 2.
4 wait start @+3 4 busy 5 free @+0 stop @+0 done

Continue to play (timed) token game


/faculteit technologie management
PN-90

Exercise: Final state?


a 1 x @+1 3 b d

5 c y @+2 4
/faculteit technologie management
PN-91

Exercise: Final state?


3 red 1 2 @+2 rb 2 @+1 @+1 rr bb black 4

/faculteit technologie management


PN-92

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-93

Instead of

rg1

rg2

g1

g2

r1

go1

go2

r2

o1

o2

or1

or2

/faculteit technologie management


PN-94

We can use hierarchy

tl1 x

tl2

rg1

rg2

g1

g2

r1

go1 x x

go2

r2

o1

o2

or1

or2

/faculteit technologie management


PN-95

Reuse
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

tl1 x

tl2

rg

go x

or

PN-96

Exercise: model three (parallel) punch card desks in a hierarchical manner

free

wait start stop

done

busy

/faculteit technologie management


PN-97

Analysis of Process Models:


Reachability graphs, invariants, and simulation

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-98

Questions raised when considering the handling of customer orders


How many orders arrive on average? How many orders can be handled? Do orders get lost? Do back orders always have priority? What is the utilization of office workers? If the desired product is no longer available, does the order get stuck? Etc.
/faculteit technologie management
PN-99

Questions raised when considering the handling of customers in the canteen


What is the average waiting time from 12.3013.00? What is the variance of waiting times? What is the effect of an additional cashier on the queue length? Etc.

/faculteit technologie management


PN-100

Questions raised when considering the an intersection with multiple traffic lights
How much traffic can be handled per hour? Give some volume of traffic, what is the probability to get a red light? Is the intersection safe, i.e., crossing flows have never a green light at the same time? Can a light go from yellow to green? Is the intersection fair (i.e., a traffic light cannot turn green twice while cars are waiting on the other side)?
/faculteit technologie management
PN-101

Questions raised when considering a printer shared by multiple users


Can two print jobs get mixed? Do small jobs always get priority? Can the settings of one job influence the next job? Do out-of-paper events cause jobs to get lost? How many jobs can be handled per day? What is the probability of a paper jam?
/faculteit technologie management
PN-102

Questions raised when considering a teller machine


What is the average response time? Is there a balance, i.e., the amount of money leaving the machine matches the amount taken from bank accounts? How often should the machine be filled to guarantee 90% availability? Is fraud possible? Etc.
/faculteit technologie management
PN-103

Analysis
Analysis is typically modeldriven to allow e.g. what-if questions. Models of both operational processes and/or the information systems can be analyzed. Types of analysis: validation verification

Operational process

Information System

Model

performance analysis
/faculteit technologie management
PN-104

Three analysis techniques (Chapter 8)


Reachability graph Place & transition invariants Simulation
Each can be applied to both classical and high-level Petri nets. Nevertheless, for the first two we restrict ourselves to the classical Petri nets. Use:
reachability graph (validation, verification) invariants (validation, verification) simulation (validation, performance analysis)
/faculteit technologie management
PN-105

Reachability graph
rg1 rg2

(0,0,1,1,0,0,0)
g1 g2

(1,0,0,0,0,1,0)

r1

go1

go2

r2

(1,0,0,1,0,0,1)

o1

o2

(0,1,0,1,0,0,0)
or1 or2

(1,0,0,0,1,0,0)

/faculteit technologie management

Five reachable states. Traffic lights are safe!


PN-106

Alternative notation
rg1 rg2

o1+r2
g1 g2

r1+o2

r1

go1

go2

r2

r1+r2+x

o1

o2

g1+r2
or1 or2

r1+g2

/faculteit technologie management


PN-107

Reachability graph (2)


Graph containing a node for each reachable state. Constructed by starting in the initial state, calculate all directly reachable states, etc. Expensive technique. Only feasible if finitely many states (otherwise use coverability graph). Difficult to generate diagnostic information.

/faculteit technologie management


PN-108

Infinite reachability graph


rg1 rg2

g1

g2

r1

go1

go2

r2

o1

o2

or1

or2

/faculteit technologie management


PN-109

Exercise: Construct reachability graph


free

wait

enter

before

make_picture

after

leave

gone

occupied

/faculteit technologie management


PN-110

Exercise: Dining philosophers (1)


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-111

Exercise: Dining philosophers (2)


Assume that philosophers take the chopsticks one by one such that first the right-hand one is taken and then the left-hand one. Model as a Petri net. Is there a deadlock?

/faculteit technologie management


PN-112

Exercise: Dining philosophers (3)


Assume that philosopher take the chopsticks one by one in any order and with the ability to return a chopstick. Model as a Petri net. Is there a deadlock?

/faculteit technologie management


PN-113

Structural analysis techniques


To avoid state-explosion problem and bad diagnostics. Properties independent of initial state. We only consider place and transition invariants. Invariants can be computed using linear algebraic techniques.

/faculteit technologie management


PN-114

Place invariant
man

couple marriage divorce

woman

1 man + 1 woman + 2 couple


/faculteit technologie management

Assigns a weight to each place. The weight of a token depends on the weight of the place. The weighted token sum is invariant, i.e., no transition can change it
PN-115

Other invariants
man

couple marriage divorce

woman

1 man + 0 woman + 1 couple (Also denoted as: man + couple) 2 man + 3 woman + 5 couple -2 man + 3 woman + couple man woman woman man (Any linear combination of invariants is an invariant.)

/faculteit technologie management


PN-116

Example: traffic light


rg1 rg2

g1

g2

r1

go1

go2

r2

r1 + g1 + o1 r2 + g2 + o2 r1 + r2 + g1 + g2 + o1 + o2 x + g1 + o1 + g2 + o2 r1 + r2 - x

o1

o2

or1

or2

/faculteit technologie management


PN-117

Exercise: Give place invariants


start_production start_consumption

free

producer

wait

consumer

product

end_production
/faculteit technologie management

end_consumption

PN-118

Transition invariant
man

couple marriage divorce

woman

2 marriage + 2 divorce
/faculteit technologie management

Assigns a weight to each transition. If each transition fires the number of times indicated, the system is back in the initial state. I.e. transition invariants indicate potential firing sets without any net effect.
PN-119

Other invariants
man

couple marriage divorce

woman

1 marriage + 1 divorce (Also denoted as: marriage + divorce) 20 marriage + 20 divorce Any linear combination of invariants is an invariant, but transition invariants with negative weights have no obvious meaning. Invariants may be not be realizable.
PN-120

/faculteit technologie management

Example: traffic light


rg1 rg2

g1

g2

r1

go1

go2

r2

rg1 + go1 + or1 rg2 + go2 + or2 rg1 + rg2 + go1 + go2 + or1 + or2 4 rg1 + 3 rg2 + 4 go1 + 3 go2 + 4 or1 + 3 or2

o1

o2

or1

or2

/faculteit technologie management


PN-121

Exercise: Give transition invariants


start_production start_consumption

free

producer

wait

consumer

product

end_production
/faculteit technologie management

end_consumption

PN-122

Exercise: four philosophers


st1 e1 t1 se1

c4 t4 st4 e4 c3 se3 t3 e3 se4

c1 e2 se2 t2 c2 st2

Give place invariants. Give transition invariants

/faculteit technologie management st3


PN-123

Two ways of calculating invariants


"Intuitive way": Formulate the property that you think holds and verify it. "Linear-algebraic way": Solve a system of linear equations. Humans tend to do it the intuitive way and computers do it the linear-algebraic way.

/faculteit technologie management


PN-124

man

Incidence matrix of a Petri net


Each row corresponds to a place. marriage Each column corresponds to a transition. Recall that a Petri net is described by (P,T,I,O). N(p,t)=O(t,p)-I(p,t) where p is a place and t a transition.
/faculteit technologie management

couple divorce

woman

1 1 N 1 1 1 1
PN-125

man

Example
man

woman

marriage

couple marriage divorce

woman

1 1 N 1 1 1 1
couple divorce
PN-126

/faculteit technologie management

Place invariant
Let N be the incidence matrix of a net with n places and m transitions Any solution of the equation X.N = 0 is a transition invariant
X is a row vector (i.e., 1 x n matrix) O is a row vector (i.e., 1 x m matrix)

Note that (0,0,... 0) is always a place invariant. Basis can be calculated in polynomial time.

/faculteit technologie management


PN-127

Example
man

couple marriage divorce

woman

1 1 X 1 1 (0,0) 1 1

Solutions: (0,0,0) 1 1 (1,0,1) (man, woman, couple) 1 1 (0,0) (0,1,1) 1 1 (1,1,2) (1,-1,0)
/faculteit technologie management
PN-128

Transition invariant
Let N be the incidence matrix of a net with n places and m transitions Any solution of the equation N.X = 0 is a place invariant
X is a column vector (i.e., m x 1 matrix) 0 is a column vector (i.e., n x 1 matrix)

Note that (0,0,... 0)T is always a place invariant. Basis can be calculated in polynomial time.

/faculteit technologie management


PN-129

Example
man

couple marriage divorce

woman

1 1 0 1 1 X 0 1 1 0
Solutions: (0,0)T (1,1)T (32,32)T
PN-130

1 1 0 marriage 1 1 divorce 0 0 1 1
/faculteit technologie management

start_production

start_consumption

Exercise
free producer wait consumer

product

end_production

end_consumption

Give incidence matrix. Calculate/check place invariants. Calculate/check transition invariants.


/faculteit technologie management
PN-131

Simulation
Most widely used analysis technique. From a technical point of view just a "walk" in the reachability graph. By making many "walks" (in case of transient behavior) or a very "long walk" (in case of steady-state) behavior, it is possible to make reliable statements about properties/ performance indicators. Used for validation and performance analysis. Cannot be used to prove correctness!
/faculteit technologie management
PN-132

Stochastic process
Simulation of a deterministic system is not very interesting. Simulation of an untimed system is not interesting. In a timed and non-deterministic system, durations and probabilities are described by some probability distribution. In other words, we simulate a stochastic process! CPN allows for the use of distributions using some internal random generator.
/faculteit technologie management
PN-133

Uniform distribution

pdf

cumulative

/faculteit technologie management


PN-134

Negative exponential distribution

/faculteit technologie management


PN-135

Normal distribution

/faculteit technologie management


PN-136

Distributions in CPN Tools


Assume some library with functions: uniform(x,y) nexp(x) erlang(n,x) Etc. A nice function is also C.ran() which returns a randomly selected element of finite color set C, e.g., color C = int with 1..5; fun select1to5() = C.ran() returns a number between 1 and 5
/faculteit technologie management
PN-137

Example

color BT = unit; color Dice = int with 1..6;

() trigger BT

() ()

Dice.ran()
throw_dice outcome Dice

/faculteit technologie management


PN-138

Example(2)

color INT = int; color TINT = int timed; color Dice = int with 1..6; color Delay = int with 0..99; trigger TINT 0

throw_dice

Dice.ran()
outcome Dice

(x+1)@+(Delay.ran())

/faculteit technologie management


PN-139

Subruns and confidence intervals


A single run does not provide information about reliability of results. Therefore, multiple runs or one run cut into parts: subruns. If the subruns are assumed to be mutually independent, one can calculate a confidence interval, e.g., the flow time is with 95% confidence within the interval 5.5+/-0.5 (i.e. [5,6]).
/faculteit technologie management
PN-140

Example of a simulation model


Gas station with one pump and space for 4 cars (3 waiting and 1 being served). Service time: uniform distribution between 2 and 5 minutes. Poisson arrival process with mean time between arrivals of 4 minutes. If there are more than 3 cars waiting, the "sale" is lost. Questions: flow time, waiting time, utilization, lost sales, etc.
/faculteit technologie management
PN-141

Top-level page: main


color Car = string
HS

arrive

Car

HS

environment

gas_station

drive_on

Car

depart
/faculteit technologie management

Car

PN-142

In

arrive

Car c [len(q)>=3] drive_on

Subpage gas_station
color Car = string; color Pump = unit; color TCar = Car timed; color Queue = list Car; var c:Car; var q:Queue; fun len(q:Queue) = if q=[] then 0 else 1+len(tl(q));

c [len(q)<3] put_in_queue q q^^[c] [] queue q start Queue c::q q q

c@+uniform(2,5)

() pump_free () Pump ()

fill_up

TCar c end c
Out

Out

/faculteit technologie management

depart

Car

drive_on

Car

PN-143

Assuming pages for the environment and measurements the last two pages allow for ...
Calculation of flow time (average, variance, maximum, minimum, service level, etc.). Calculation of waiting times (average, variance, maximum, minimum, service level, etc.). Calculation of lost sales (average). Probability of no space left. Probability of no cars waiting. For each of these metrics, it is possible to formulate a confidence interval given sufficient observations.
/faculteit technologie management
PN-144

In

arrive

Car c [len(q)>=3] drive_on

Alternatives
color Car = string; color Pump = unit; color TCar = Car timed; color Queue = list Car; var c:Car; var q:Queue; fun len(q:Queue) = if q=[] then 0 else 1+len(tl(q));

c [len(q)<3] put_in_queue q q^^[c] [] queue q start c@+uniform(2,5) () pump_free () Queue c::q q q

Model the following alternatives: 5 waiting spaces 2 pumps 1 faster pump


/faculteit technologie management

fill_up

TCar c end c
Out

Pump ()

Out

depart

Car

drive_on

Car

PN-145

Simulation of a Production system

A B C
/faculteit technologie management
PN-146

Use distributions

Data
A B C

X 2 3 4

Y 5 6 7

Z 8 9 1

X Y Z

2 3 4

Processing times

Resources per work center

A B C

2 1 2

A B C

2 1 1

A B C

7 9 8

Replenishment lead times


/faculteit technologie management

Kanbans inbetween work centers

Time inbetween subsequent orders


PN-147

Top level page: main


color INT = int; color Prod = string; color PT = product Prod * INT; color PTimed = Prod timed; color PTTimed = PT timed; var p:Prod; var t:INT; var i:INT; resources_X 2`"A"++ 1`"B"++ 1`"C"
HS

4 INT 2`"A"++ 1`"B"++ 1`"C" kanban2


HS

5 resources_Y INT 2`"A"++ 1`"B"++ 1`"C" kanban3


HS

6 resources_Z INT

Prod kanban1 work_ center_ X

Prod work_ center_ Y

Prod kanban4
HS

Prod
HS

supplier

work_ center_ Z

customer

product1 1`("A",2)++ 1`("B",1)++ 1`("C",2) io_lead_time PT

Prod

product2 1`("A",2)++ 1`("B",3)++ 1`("C",4) PT

Prod

product3 1`("A",5)++ 1`("B",6)++ 1`("C",7) PT

Prod

product4 1`("A",8)++ 1`("B",9)++ 1`("C",1) PT

Prod 1`("A",7)++ 1`("B",9)++ 1`("C",8) PTTimed

processing_ time_X

processing_ time_Y

processing_ time_Z

c_ia_time

supplier io_lead_time = io_lead_time kanban_in = kanban1 product_out = product1

/faculteit technologie management

work_center processing_time = processing_time_X resources = resources_X kanban_in = kanban2 product_in = product1 kanban_out = kanban1 product_out = product2

work_center processing_time = processing_time_Y resources = resources_Y kanban_in = kanban3 product_in = product2 kanban_out = kanban2 product_out = product3

work_center processing_time = processing_time_Z resources = resources_Z kanban_in = kanban4 product_in = product3 kanban_out = kanban3 product_out = product4

customer c_ia_time = c_ia_time kanban_out = kanban4 product_in = product4

PN-148

Sub page: supplier


accept_order p (p,t) p@+t
In/Out In

kanban_in

Prod

(p,t)

io_lead_time

PT

oip

PTimed p p

Out

deliver_order

product_out

Prod

/faculteit technologie management


PN-149

Sub page: customer


Out

place_order p

kanban_out

Prod (p,t)@+t

(p,t)
In/Out

c_ia_time
In

PTTimed

p Prod consume

product_in

/faculteit technologie management


PN-150

Sub page: work_center


Out

kanban_out
Out

Prod

p end_proc p

product_out

Prod p i

i+1
In/Out

wip
In

[i>=1] p Prod p

PTimed p@+t i-1 i

resources

INT

kanban_in
In

start_proc (p,t)

(p,t)
In/Out

processing_time product_in Prod

PT

/faculteit technologie management


PN-151

Overview
Results: response time utilization % backorders average stock etc.
accept_order p (p,t) p@+t
In/Out

color INT = int; color Prod = string; color PT = product Prod * INT; color PTimed = Prod timed; color PTTimed = PT timed; var p:Prod; var t:INT; var i:INT; resources_X 2`"A"++ 1`"B"++ 1`"C"
HS

4 INT 2`"A"++ 1`"B"++ 1`"C" kanban2


HS

5 resources_Y INT 2`"A"++ 1`"B"++ 1`"C" kanban3


HS

6 resources_Z INT

Prod kanban1 work_ center_ X

Prod work_ center_ Y

Prod kanban4
HS

Prod
HS

supplier

work_ center_ Z

customer

product1 1`("A",2)++ 1`("B",1)++ 1`("C",2) io_lead_time PT

Prod

product2 1`("A",2)++ 1`("B",3)++ 1`("C",4) PT

Prod

product3 1`("A",5)++ 1`("B",6)++ 1`("C",7) PT

Prod

product4 1`("A",8)++ 1`("B",9)++ 1`("C",1) PT

Prod 1`("A",7)++ 1`("B",9)++ 1`("C",8) PTTimed

processing_ time_X

processing_ time_Y

processing_ time_Z

c_ia_time

supplier io_lead_time = io_lead_time kanban_in = kanban1 product_out = product1

work_center processing_time = processing_time_X resources = resources_X kanban_in = kanban2 product_in = product1 kanban_out = kanban1 product_out = product2

work_center processing_time = processing_time_Y resources = resources_Y kanban_in = kanban3 product_in = product2 kanban_out = kanban2 product_out = product3

work_center processing_time = processing_time_Z resources = resources_Z kanban_in = kanban4 product_in = product3 kanban_out = kanban3 product_out = product4

customer c_ia_time = c_ia_time kanban_out = kanban4 product_in = product4

Out

In

kanban_out

Prod

p end_proc p

Out

place_order p

kanban_in

Prod

Out

(p,t)
product_out Prod p i

kanban_out
i+1

Prod (p,t)@+t

(p,t)
In/Out

io_lead_time

PT

In/Out

oip

PTimed p p

Out
In

wip [i>=1] p Prod p

PTimed p@+t i-1 i

resources

INT
In

c_ia_time p Prod consume

PTTimed

deliver_order

product_out

Prod
kanban_in
In

start_proc (p,t)

(p,t)
In/Out

product_in

processing_time product_in Prod

PT

/faculteit technologie management


PN-152

Classical versus high-level Petri nets


Simulation clearly works for all types of nets. Hierarchy is never a problem. Time allows for new types of analysis. Reachability graphs and invariants can also be extended to high-level nets.
More complex (both technique and computation)

Sometimes abstraction from color is possible to derive invariants (consider previous example).

/faculteit technologie management


PN-153

Exercise: Five Chinese philosophers


Recall hierarchical CPN model of five Chinese philosophers alternating between states thinking and eating.
Give place invariants Give transition invariants

Change the model such that philosophers can take one chopstick at a time but avoid deadlocks and a fixed ordering of philosophers.
Give place invariants Give transition invariants
/faculteit technologie management
PN-154

color BlackToken = unit; var b:BackToken

Top-level page
()
HS philosopher left = CS2 right = CS1

CS1 BlackToken

CS2

()

PH1 BlackToken
HS philosopher left = CS1 right = CS5

PH5

PH2
HS philosopher left = CS3 right = CS2

CS5 BlackToken

()

CS3 BlackToken

()

CS4 PH4
HS philosopher left = CS5 right = CS4

() PH3
HS philosopher left = CS4 right = CS3

BlackToken

/faculteit technologie management


PN-155

Page philosopher
think BlackToken b take_chopsticks b () eat BlackToken b b put_down_chopsticks

b b left BlackToken
/faculteit technologie management

b b right

In/Out

In/Out

BlackToken

PN-156

Flat model is obtained by replacing substitution transitions by subpages


color BlackToken = unit; var b:BackToken
philosopher left = CS2 right = CS1

CS1 BlackToken

()

HS

CS2

()

PH1 BlackToken
HS philosopher left = CS1 right = CS5

PH5

PH2
HS philosopher left = CS3 right = CS2

Naming: PH3.think PH3.eat PH3.take_chopsticks PH3.put_down_chopsticks


think BlackToken () eat BlackToken b take_chopsticks b b b put_down_chopsticks

CS5 BlackToken

()

CS3 BlackToken

()

CS4 PH4
HS philosopher left = CS5 right = CS4

() PH3
HS philosopher left = CS4 right = CS3

BlackToken

b b left BlackToken
In/Out

b b right
In/Out

BlackToken

/faculteit technologie management

Repeat 5 times...
PN-157

Alternative page

think BlackToken b start_eating

()

eat BlackToken b b b start_thinking

b b hold_left BlackToken b return_left take_left b

b b hold_ right BlackToken b take_right b return_right

b left BlackToken

b right
In/Out In/Out

BlackToken

/faculteit technologie management


PN-158

You should be able to ...


Construct a reachability graph for a classical Petri net. Give meaningful place and transition invariants for a classical Petri net. Construct a reachability graph and give meaningful place and transition invariants for a hierarchical CPN after abstracting from data and time and removing hierarchy. Build a simple simulation model using CPN. Motivate the use of each of the analysis techniques.
/faculteit technologie management
PN-159

You might also like