41
Ch5: Software Specification

Ch5: Software Specification. 1 Petri Nets Introduced by C. Adams Petri in 1960. Widely used in the modeling and analysis of computer systems. Basic

Embed Size (px)

Citation preview

Page 1: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

Ch5: Software Specification

Page 2: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 3: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

3

Petri Nets

Legend:

Place

TransitionDirected arc

P1

P2

P3

t1

Token

Page 4: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

4

Petri Nets (contd..)

P1

P2

P3

t1

Input place:

Output place:

Page 5: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

5

Petri Nets (contd..)

P1

P2

P3

t12

Weighted connection: Default weight is 1.

Page 6: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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.

Page 7: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

7

Petri Nets (contd..)

P1

P2

P3

t1

Local State: P1 – 1 P2 – 0 P3 – 0Overall State: <1,0,0>

Page 8: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 9: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

9

Petri Nets (contd..)

Step #1

P1

P2

P3

t12

Page 10: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

10

Petri Nets (contd..)

P1

P2

P3

t12

Step 2

Page 11: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

11

Petri Nets (contd..)

P1

P2

P3

t12

Step 3:

Page 12: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

12

Petri Nets (contd..)

Enabled transitions not forced to fire Can be subject to external conditions Ordinary Petri net, firing of transitions occurs instantly

Page 13: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

13

Petri Nets (contd..)

Machine Idle LoadingPart

Operationin Progress

UnloadingPart

Robot Idle

Petri Nets: Manufacturing Example

Place represents availability of a resource.

Page 14: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

14

Petri Nets (contd..)

User & Candy

User hascoin

Machineready

User hascandy

Machine busy

eat resetDispensecandy

Page 15: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

15

Petri nets (contd..)

Petri nets may be used to model concurrent systems Concurrent transitions:

Petri nets are non-deterministic

Page 16: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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.

Page 17: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 18: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 19: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 20: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 21: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 22: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

22

Petri nets (contd..)

Transitions t3 and t4 were both enabled:

Conflict

A process may never get a resource (starvation)

Page 23: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 24: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 25: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 26: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 27: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 28: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

28

Petri nets (contd..)

Firing sequence: t1, t3, t5 Firing sequence: t2, t4, t6 The shared resource alternates between the two

processes

Page 29: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

29

Petri nets (contd..)

Deadlock:

Live:

Page 30: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 31: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 32: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 33: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 34: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 35: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 36: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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

Page 37: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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.

Page 38: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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.

Page 39: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

39

Petri nets: Limitations and extensions

PP

P

PP

34

71 4

t t1 2

45

12

3

Assigning values to tokens

Page 40: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

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.

Page 41: Ch5: Software Specification. 1 Petri Nets  Introduced by C. Adams Petri in 1960.  Widely used in the modeling and analysis of computer systems.  Basic

41

Petri Nets: Case Study

WrtTxt DrwFg

DrwFgCmpWrtTxtCmp

MrgDoc RvDoc PrDoc

PrOn PrOff