Petri Nets

Petri Nets

prepared March 26, 2009
  • These slides will be covered during TWO lectures.
  • Slides by Topic

  • Introduction
  • Goals for Studying Petri Nets
  • Characteristics of the Model
  • Petri Nets & Finite State Automata
  • Beyond DFDs
  • Basic Definition
  • Game Metaphor for Petri Nets
  • The Gameboard
  • The Pieces
  • The Rules of Play
  • Example
  • Modeling Program Graphs
  • Basic Control Constructs
  • Parallel Programming
  • Modeling Control
  • Switches
  • Mutual Exclusion
  • Producer/Consumer Model
  • Process Pipeline
  • Modeling Non-computer Systems
  • Machine Shop Specification
  • Petri Net Model of Machine Shop
  • Petri Net Can Model Any Flow
  • Formalism
  • Formal Definitions
  • Firings
  • Vector Addition Systems
  • Example VAS
  • Properties of Petri Nets
  • Analysis of Behavior
  • Conflict
  • Boundedness
  • Liveness
  • Liveness Examples
  • Reachability & Coverability
  • Coverability Tree Example
  • Modeling Databases & Operating Systems
  • Two-Phase Commit
  • OS Model Correspondences
  • Deadlocked Programs
  • Petri Model with Possible Deadlock
  • Petri Model without Deadlock
  • Variations in Modeling

  • Goals for Studying Petri Nets

    1. Familiarity with an important modeling tool

    * areas Petri nets can model well

    * limitations of Petri nets

    * variety of representations

    * common properties

    2. Capabilities with the tool

    * understand complex models

    * develop simple models

    3. Further information:

    World of Petri Nets

    look for simulators under «Tools and Software» link


    Characteristics of the Model

    * complex processes

    * concurrent activities

    * flow of data or other things

    may be transformed on the way

    * multiple coordinated flows

    hence abstraction of Data Flow Diagrams

    focusing on synchronization


    Petri Nets & Finite State Automata

    Some visual similarity between FSA and Petri Nets diagrams
    both have circle and arrows

    FSA are special cases of Petri nets

    In general, Petri nets

    * emphasize locality of condition
    verses global state

    * have multiple conditions active at once
    hence non- determinacy more global

    * express complex transitions succinctly

    * allow multiple instances in one condition
    without bound


    Beyond DFDs

    + explicit coordination / synchronization

    - no identity of «packets»

    How do invoice and build order from the same purchase order get matched up?

    expand this figure


    Game Metaphor for Petri Nets

    Can imagine each Petri net as

    * a unique gameboard

    but

    * using the same kind of pieces and

    * following the same general rules


    The Gameboard

    Each Petri net looks like a gameboard with

    * circles called conditions or places

    * bars called events or transitions

    * arrows, called input arcs , from conditions to events

    * condition is input to the event

    * arrows, called output arcs , from events to conditions

    * condition is output from the event

    * multiple parallel edges possible

    Notation:

    expand this figure

    * formally, a «bipartite directed multigraph»


    The Pieces

    A token on a condition

    * means that condition currently is true

    * is drawn by a black dot on that condition

    * may share that condition with other tokens, indicating multiple objects sharing that condition

    * during a given turn, may stay on a condition or move to an event

    A marking of a Petri net

    * is a function from the conditions to the non-negative integers

    * indicates the number of tokens currently at that condition


    The Rules of Play

    An event is enabled when it is possible to place

    on each input arc

    a token from the corresponding input condition

    An event fires

    * only if it is enabled

    * by consuming a token along each input arc

    * and producing a token along each output arc

    Indeterminate firing:

    * If more than one event is enabled at a given time, any of the enabled events may fire

    Concurrency:

    * Formally, two events may not fire at the same time

    * However, this is often not relevant, so it is common to think of event firings as being concurrent


    Example

    expand this figure


    Basic Control Constructs

    expand this figure


    Parallel Programming

         PARBEGIN
              S1, S2, ... Sk
         PAREND 

    expand this figure


    Switches

    The simplest switch:

    expand this figure

    Use this to en/dis-able other transition(s)

    expand this figure

    What is wrong with the above?


    Mutual Exclusion

    Objective: prevent two programs from accessing the same data structure simultaneously

    Code where a program accesses the shared structure is called the critical section

    expand this figure


    Producer/Consumer Model

    Issue is lock on buffer to prevent simultaneous access

    expand this figure


    Process Pipeline

    expand this figure


    Machine Shop Specification

    A machine shop has resources:

    * machines M0, M1, and M2

    * operators O1 and O2

    Subject to the constraints:

    * O1 can operate M0 and M1

    * O2 can operate M0 and M2

    * an order is processed first by M0 and then either M1 or M2

    Significant events:

    * order arrives

    * Oi [ begins | ends ] operating Mj

    * product is shipped

    Significant conditions:

    * order waiting for Mj

    * Oi or Mj is idle (5 cases)

    * Oi is operating Mj (4 cases)

    * order partially done

    * product awaiting shipment


    Petri Net Model of Machine Shop

    expand this figure


    Petri Net Can Model Any Flow

    * PERT networks

    * example: building a house

    * Many complex processes in society

    * example: civil legal action


    Formal Definitions

    A Petri net graph consists of

    P a finite set of conditions (Places)

    T a finite set of events (Transitions)

    I a finite multiset of arcs from P to T (Inputs)

    O a finite multiset of arcs from T to P (Outputs)

    A marked Petri net consists of

    G a Petri net graph <P,T,I,O>

    m a function, m : P -> Z
    Z = non-negative integers


    Firings

    Formally define:

    * event enabled

    * firing

    * firing sequence


    Vector Addition Systems

    An (almost) equivalent formalism:

    * an n place Petri net written as a vector of conditions < p1, p2, . . ., pn >

    * a marking of that net is written as a vector of non-negative integers < m1, m2, . . ., mn >

    * an event is written as a vector of integers
    < d1, d2, . . ., dn >

    * di < 0 for input arcs from condition pi

    * di > 0 for output arcs to condition pi

    * one event cannot have same condition as both input and output

              |
              |     conditions
           ---+---------------------
           e  |
           v  |
           e  |
           n  |
           t  |
           s  |
    
           


    Example VAS

    A Petri net in VAS notation

    
                                p1       p2       p3       p4
    

    t1 < 1 , 0 , 0 , 0 > t2 < -1 , -1 , 2 , 2 > t3 < 0 , 0 , -2 , -1 > t4 < 0 , 1 , 0 , -1 >

    The same Petri net in graphical notation

    expand this figure


    Analysis of Behavior

    Given

    * a Petri net with

    * an initial marking

    determine

    * behavior patterns

    * over all possible firing sequences


    Conflict

    Two events are said to be in conflict if there is a marking in which both events are enabled, but the firing of one event disables the other

    A conflict:

    expand this figure


    Boundedness

    A condition t is bounded by b if there is no firing sequence that marks t with a value greater than b

    A condition bounded by 1 is called safe .


    Liveness

    An event t is

    dead
    if it is never enabled

    live-1
    if there is some firing sequence after which t is enabled

    live-2
    if, for every integer n, there is a firing sequence in which t fires n times

    live-3
    if there is an infinite firing sequence in which t fires n times, for any integer n

    live-4
    if every finite firing sequence can be extended to one that enables t


    Liveness Examples

    * dead

    expand this figure

    * live-1 but not live-2

    expand this figure

    * live-2 but not live-3, for t3

    expand this figure

    * live-3 but not live-4, for t1 in same net

    * live-4, non-trivially

    expand this figure

    * live-4, but trivial

    expand this figure

    [ slides 28 thru 29 combined in above ]


    Reachability & Coverability

    Reachability question: Given

    * a Petri net with an initial marking and

    * a target marking M

    does there exist

    * a firing sequence that produces M ?

    A marking < m1, m2, . . ., mn > covers a marking
    < k1, k2, . . ., kn > if ki <= mi for all i, 1 <= i <= n

    Coverability question: Given

    * a Petri net with an initial marking and

    * a target marking M

    does there exist

    * a firing sequence that produces a marking covering M ?

    Coverability tree formed by

    1. initial marking is root

    2. successive markings form branches except

    3. if identical marking on path to root, stop branch

    4. if covers a marking on path to root, mark increased conditions with o


    Coverability Tree Example

    expand this figure


    Two-Phase Commit

    expand this figure


    OS Model Correspondences

    A condition typically is

    * a queue of processes

    * where many tokens may be in one condition

    * an active process

    * where one token may occupy a condition

    Tokens model

    * processes

    * controls (semaphores, etc.)


    Deadlocked Programs

     loop                loop
       acquire R1;         acquire R2;
       acquire R2;         acquire R1;
       critical            critical
           section;          section;
       release R1          release R1
           and R2;            and R2; end
    end 


    Petri Model with Possible Deadlock

    expand this figure


    Petri Model without Deadlock

    expand this figure


    Colored Petri Nets

    * allow tokens of various colors

    * events specify colors of tokens input and output

    Example:

    expand this figure

    * t1 takes a Yellow token and outputs a Green one

    * t2 consumes a Green token as long as a Red is present, outputing a Red token

    * t3 takes either a Green or Red token as input


    Coloring Doesn't Matter

    expand this figure


    Numeric Petri Nets

    expand this figure

    © Copyright Edward Robertson, 2109-3-26