coloured petri nets - hvlhome.hvl.no/ansatte/lmkr/acpn2010/colouredpetrinets.pdf · 2010. 9....

of 55/55
Advanced Course on Petri Nets 2010 - 1 Coloured Petri Nets Lars M. Kristensen Department of Computer Engineering Bergen University College, NORWAY Email: [email protected] /Web: www.hib.no/ansatte/lmkr

Post on 20-Jan-2021

0 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Advanced Course on Petri Nets 2010 - 1

    Coloured Petri Nets

    Lars M. KristensenDepartment of Computer EngineeringBergen University College, NORWAYEmail: [email protected] /Web: www.hib.no/ansatte/lmkr

    mailto:[email protected]://www.hib.no/ansatte/lmkrhttp://www.cs.au.dk/~cpnbook

  • Advanced Course on Petri Nets 2010 - 2

    Coloured Petri Nets (CPNs)Petri Nets and a programming language:

    Petri Nets:concurrency control structuressynchronisationcommunication

    Standard ML enables compact modelling and convenient modelling of data manipulation.

    Standard ML:Colour sets (data types)and markingsArc expressionsGuards

  • Advanced Course on Petri Nets 2010 - 3

    CPN Tools[ www.daimi.au.dk/CPNTools ]

    Editing and syntax check.

    Interactive- andautomatic simulation.

    State space exploration andverification.

    Performance analysis.

    Behavioural visualisation usingapplication domain graphics.

    Currently 8000+ CPN Tools license holders in 130+ countries.

    Modelling and validation of Coloured Petri Net models are supported by CPN Tools:

    http://www.daimi.au.dk/CPNTools

  • Advanced Course on Petri Nets 2010 - 5

    Example: A Simple Communication Protocol

  • Advanced Course on Petri Nets 2010 - 6

    The Problem – in Greendale

    http://images.google.dk/imgres?imgurl=http://www.warwickshire.gov.uk/Web/graphics/graphics.nsf/graphics/Parcels226/$file/parcels226.jpg&imgrefurl=http://www.warwickshire.gov.uk/Web/Corporate/Pages.nsf/Pages by Department/CD9A6EE2640955488025719A004BA6BD&h=192&w=261&sz=7&hl=da&start=13&um=1&tbnid=NzTqWiafPvTGBM:&tbnh=82&tbnw=112&prev=/images?q=Parcels&svnum=10&um=1&hl=da&sa=Nhttp://images.google.dk/imgres?imgurl=http://www.usps.com/websites/depart/inspect/3letters.jpg&imgrefurl=http://www.usps.com/websites/depart/inspect/nigwithg.htm&h=1124&w=1211&sz=184&hl=da&start=18&um=1&tbnid=0DhBF8gLzheUMM:&tbnh=139&tbnw=150&prev=/images?q=Letters&svnum=10&um=1&hl=da&sa=Nhttp://images.google.dk/imgres?imgurl=http://www.buyersbenefit.dk/Pictures/traepiller bigbag.jpg&imgrefurl=http://www.buyersbenefit.dk/php/ExSub.php?INDEX=21&h=876&w=646&sz=70&hl=da&start=3&tbnid=edwe14wyXou2sM:&tbnh=146&tbnw=108&prev=/images?q=Big+bag&gbv=2&svnum=10&hl=da&sa=G

  • Advanced Course on Petri Nets 2010 - 7

    The Problem – in Data Networks

    01101010001010101101010001101101

    SenderNetwork

    Receiver

    Receiver must assemble original data.Stop-and-wait protocol: transmit one data packet at a time and wait for a matching acknowledgement.Initially we will assume a reliable network (no loss).

    Packet

    Data

    01101100

    1234

    sequence numbers

    http://images.google.dk/imgres?imgurl=http://www.snia.org/about/images/network_component_icons/Large_Cloud.jpg&imgrefurl=http://www.snia.org/about/images/network_component_icons/&h=954&w=1412&sz=74&hl=da&start=2&tbnid=jK8N_JRh5WXzVM:&tbnh=101&tbnw=150&prev=/images?q=network+cloud&gbv=2&svnum=10&hl=da

  • Advanced Course on Petri Nets 2010 - 8

    Part 1: Basic Protocol CPN Model

  • Advanced Course on Petri Nets 2010 - 9

    The Coloured Petri Net Model

    Sender Network Receiver

  • Advanced Course on Petri Nets 2010 - 10

    Place

    Transition

    Arc

    Net inscriptions

  • Advanced Course on Petri Nets 2010 - 11

    Places model the state of the system

    Name

    Initial marking (multi-set of tokens)

    Colour set (type)

    Definition of colour sets:colset NO = int; (* integers *)colset DATA = string; (* text strings *)colset NOxDATA = product NO * DATA;

    Each place may contain a number of tokens.Each token carries a colour(data value).The colour set of a place specifies the set of allowed token colours.

  • Advanced Course on Petri Nets 2010 - 12

    Current marking

    Information aboutcurrent marking

    Circle: 6 tokens

    Square: Detailedtoken values

    Values:Token colours

    Token coefficient

  • Advanced Course on Petri Nets 2010 - 13

    Initial marking of CPN model

  • Advanced Course on Petri Nets 2010 - 14

    Intermediate marking of model

  • Advanced Course on Petri Nets 2010 - 15

    Transitions model events of the system

    Arc expression

    The type of the arc expression must match the colour set of the attached place(or the multi-set type over the colour set)

    Declaration of variables:var n : NO; (* integers *)var d : DATA; (* strings *)

    Binding of transition variables:

    Evaluation of expressions:

    (n,d) → (3,"CPN") : NOxDATAn → 3 : NO

  • Advanced Course on Petri Nets 2010 - 16

    Enabling of transitions

    Two variables:var n : NO; (* integers *)var d : DATA; (* strings *)

    Binding: < n=? , d=? >

    Transition is enabled if we can find a binding so that each input arc expression evaluates to a multi-set of tokens that are present on the corresponding input place.

    NO DATA

    ?

    ?

    Green border line indicates that thetransition is enabled(ready to occur)

  • Advanced Course on Petri Nets 2010 - 17

    Enabling of SendPacket

    One token with value 1

    Binding: < n=1 , d=? >

    We want to find a binding for the variable n such that the arc expression n evaluates to a multi-set of colours which is present on the place NextSend.Arc expression

  • Advanced Course on Petri Nets 2010 - 18

    Binding: < n=1 , d=? >

    Enabling of SendPacket

    Six different tokens

    Binding: < n=1 , d="COL" >

    We want to find a binding for the variable d such that the arc expression (n,d) evaluates to a multi-set which is present on the place PacketsToSend.

    Arc expression

  • Advanced Course on Petri Nets 2010 - 19

    1

    (1,"COL")

    Enabling of SendPacket

    Binding: < n=1 , d="COL" >

    We have found a binding so that each input arc expression evaluates to a colour that is present on the corresponding input place

    Transition is enabled(ready to occur)

  • Advanced Course on Petri Nets 2010 - 20

    Occurrence of SendPacketin binding

    1

    (1,"COL")

    (1,"COL")

    Remove: (1,"COL")

    Add a new token: (1,"COL")

    Remove: 1

  • Advanced Course on Petri Nets 2010 - 21

    New marking after occurrence of SendPacket in binding

    The first packet has been removed

    A copy of the first packet has been put on A

    No token on this place

    Transition is no longer enabled(no green border line)

  • Advanced Course on Petri Nets 2010 - 22

    New marking M1

    Transition enabled

  • Advanced Course on Petri Nets 2010 - 23

    Part 2: Extended Protocol CPN Model

  • Advanced Course on Petri Nets 2010 - 24

    The Simple Protocol Revisited 01101010001010101101010001101101

    SenderNetwork

    Receiver

    Unreliable network (loss and overtaking).

    Packet

    Data

    01101100

    1234

    Sender must retransmit packets and keep track of the data packet currently being sent.Receiver keeps track of the data packet expected next.

    http://images.google.dk/imgres?imgurl=http://www.snia.org/about/images/network_component_icons/Large_Cloud.jpg&imgrefurl=http://www.snia.org/about/images/network_component_icons/&h=954&w=1412&sz=74&hl=da&start=2&tbnid=jK8N_JRh5WXzVM:&tbnh=101&tbnw=150&prev=/images?q=network+cloud&gbv=2&svnum=10&hl=da

  • Advanced Course on Petri Nets 2010 - 25

    Second Versionval AllPackets = 1‘(1,"COL") ++ 1‘(2,"OUR") ++

    1‘(3,"ED ") ++ 1‘(4,"PET") ++ 1‘(5,"RI ") ++ 1‘(6,"NET");

  • Advanced Course on Petri Nets 2010 - 26

    Double Arcs

    Double arc

    Double arc

    A double arc is a shorthand for two oppositely directed arcs with the same arc expression

    We no longer remove the tokens from the input places

    Retransmission becomes possible

  • Advanced Course on Petri Nets 2010 - 27

    Occurrence of SendPacket

  • Advanced Course on Petri Nets 2010 - 28

    More Complex Arc ExpressionMore complicated

    arc expression(if-then-else expression)

  • Advanced Course on Petri Nets 2010 - 29

    If-then-else Expression

    1`(1,"COL")var success : BOOL;

    bsucc = bfail =

    success = true

    Successful transmissionover the network

    11`(1,"COL")

    11`(1,"COL")

    New variable:

  • Advanced Course on Petri Nets 2010 - 30

    If-then-else Expression

    emptyvar success : BOOL;

    bsucc = bfail =

    success = false

    Packet is lost during transmission

    11`(1,"COL")

    No packet is added

  • Advanced Course on Petri Nets 2010 - 31

    New Name and Type

    New type

    New name

    Initial marking:empty text string

  • Advanced Course on Petri Nets 2010 - 32

    New Place: NextRec

    New placePlays a similar role as NextSend

    Contains the number of the expected packet

  • Advanced Course on Petri Nets 2010 - 33

    Correct packet arrivesEmpty text string

    Binding:

  • Advanced Course on Petri Nets 2010 - 34

    Correct Packet Received

  • Advanced Course on Petri Nets 2010 - 35

    Wrong Packet Arrives

    Binding:

  • Advanced Course on Petri Nets 2010 - 36

    Wrong Packet Arrived

  • Advanced Course on Petri Nets 2010 - 37

    Acknowledgements can be lost

    Also possible to loose acknowledgements

  • Advanced Course on Petri Nets 2010 - 38

    NextSend is updated

    NextSend is updated with sequence number from acknowledgement

  • Advanced Course on Petri Nets 2010 - 39

  • Advanced Course on Petri Nets 2010 - 40

    Transitions can have a guard

    Guard( is theInequality operator)

    Guard(tests whether n and kare equal)

    Boolean expression which must evaluate to true for the binding to be enabled.

    Additional enabling condition.

    Correctpackets

    Wrongpackets

  • Advanced Course on Petri Nets 2010 - 41

    Guard must evaluate to true

    RN1 = (ReceiveNext, )RN2 = (ReceiveNext, )

    falsetrue

  • Advanced Course on Petri Nets 2010 - 42

    Guard must evaluate to true

    DP1 = (DiscardPacket,

  • Advanced Course on Petri Nets 2010 - 43

    Formal Definition of CPNs

    Net structure

    Types and variables

    Net inscriptions

  • Advanced Course on Petri Nets 2010 - 44

    Enabling and Occurrence

  • Advanced Course on Petri Nets 2010 - 45

    Part 3: Hierarchical Protocol CPN Model

  • Advanced Course on Petri Nets 2010 - 46

    CPN ModulesCPN models can be hierarchically organised into a set of modules with well-defined interfaces:

    Makes it possible to split models of large systems into manageable parts.Makes it possible to work at different abstraction levels and have the model reflect the structure of the system.Makes it possible to create building blocks that are used repeatedly in the CPN model.

    CPN models of larger systems typically have up to 10 abstraction (hierarchical) levels.CPN models with modules are also calledhierarchical Coloured Petri Nets.

  • Advanced Course on Petri Nets 2010 - 47

    Simple Protocol

    Sender Network Receiver

    The protocol model can be divided into three modules:

    SenderNetworkReceiver

    The buffer places are used as interfaces between the modules.

  • Advanced Course on Petri Nets 2010 - 48

    Sender Module

    Input portUsed to import tokens from the environment

    Output portUsed to export tokens to the environment

    Input/output portUsed to import and export tokens

    Internal placeLocal to themodule

    The module interacts with other modulesvia three port places.

  • Advanced Course on Petri Nets 2010 - 49

    Receiver module

    Input portUsed to import tokens from the environment

    Output portUsed to export tokens to the environment

    Input/output portUsed to import andexport tokens

    Internal placeLocal to the module

  • Advanced Course on Petri Nets 2010 - 50

    Network module

    Input port

    Input port

    Output port

    Output port

    Interaction with the sender

    Interaction with the receiver

  • Advanced Course on Petri Nets 2010 - 51

    Protocol ModuleTies the three other modules together using substitution transitions.Provides a more abstract view of the protocol system.

    Name of substitution transition

    Name of submodule

  • Advanced Course on Petri Nets 2010 - 52

    Protocol Module

    Sender

    (n,d)

    n

    (n,d)

    n

    SendPacket A

    Out

    NOxDATA

    D In

    NO

    NextSend

    1`1

    NO

    AllPackets

    NOxDATA

    In

    Out

    PacketsTo SendI/OI/O

    ReceiveAck

    k n

    (n,d)

    if n=k then data^delse data

    k

    data

    ReceivePacket

    COut

    NO

    BIn

    NOxDATA

    ""

    DATA

    1`1

    NO

    In

    Out

    if n=kthen k+1else k

    NextRec

    DataReceived I/OI/O

    if n=kthen k+1else kn

    if successthen 1`(n,d)else empty(n,d)

    TransmitAck

    TransmitPacket

    C In

    NO

    B Out

    NOxDATA

    DOut

    NO

    AIn

    NOxDATA

    In

    Out

    Out

    Inif successthen 1`nelse empty

    Network Receiver

  • Advanced Course on Petri Nets 2010 - 53

    Protocol Module

    Input socket for Network substitution transitionOutput socket for Sender substitution transition

    The places connected to the substitution transitions are socket places.They constitute the interface for the substitution transition.

    Input/output socketfor Sender substitutiontransition

  • Advanced Course on Petri Nets 2010 - 54

    Port-Socket RelationEach port place of a submodule is related to a socket place of its substitution transition:

    input port ↔ input socket. output port ↔ output socket.input/output port ↔ input/output socket.

    Ports and sockets that are related to each other constitute a single compound place.

    They have the same marking.When a token is added/removed at one of them it is also added/removed at the other.Also the colour sets and initial markings are required to be identical.

  • Advanced Course on Petri Nets 2010 - 55

    Sender

    (n,d)

    n

    (n,d)

    n

    SendPacket A

    Out

    NOxDATA

    D In

    NO

    NextSend

    1`1

    NO

    AllPackets

    NOxDATA

    In

    Out

    PacketsTo SendI/OI/O

    ReceiveAck

    k n

    (n,d)

    if n=k then data^delse data

    k

    data

    ReceivePacket

    COut

    NO

    BIn

    NOxDATA

    ""

    DATA

    1`1

    NO

    In

    Out

    if n=kthen k+1else k

    NextRec

    DataReceived I/OI/O

    if n=kthen k+1else kn

    if successthen 1`(n,d)else empty(n,d)

    TransmitAck

    TransmitPacket

    C In

    NO

    B Out

    NOxDATA

    DOut

    NO

    AIn

    NOxDATA

    In

    Out

    Out

    Inif successthen 1`nelse empty

    Network Receiver

    Port-Socket Relation

    For the protocol system ports and sockets have identical names, but this is not required in general.

  • Advanced Course on Petri Nets 2010 - 56

    References: Getting StartedK. Jensen, L.M. Kristensen, and L. Wells. ColouredPetri Nets and CPN Tools for Modelling and Validation of Concurrent Systems. In International Journal on Software Tools for Technology Transfer (STTT), Vol 9, No. 3-4, pp. 213-254. Springer-Verlag, 2007. CPN Tools: [ www.daimi.au.dk/CPNtools ] (see Download and Installation section)K. Jensen and L.M. Kristensen. Coloured Petri Nets: Modelling and Validation of Concurrent Systems. Springer, 2009. [book web: www.cs.au.dk/CPnets/cpnbook/ ]

    http://www.daimi.au.dk/CPNtoolshttp://www.cs.au.dk/CPnets/cpnbook/http://www.cs.au.dk/~cpnbook

    Coloured Petri Nets�Coloured Petri Nets (CPNs)CPN Tools �[ www.daimi.au.dk/CPNTools ]Example: A Simple �Communication ProtocolThe Problem – in GreendaleThe Problem – in Data NetworksPart 1: �Basic Protocol CPN ModelThe Coloured Petri Net ModelSlide Number 10Places model the state of the systemCurrent markingInitial marking of CPN modelIntermediate marking of modelTransitions model events of the systemEnabling of transitionsEnabling of SendPacketEnabling of SendPacketEnabling of SendPacketOccurrence of SendPacket�in binding New marking after occurrence of SendPacket in binding New marking M1Part 2: �Extended Protocol CPN ModelThe Simple Protocol Revisited Second VersionDouble ArcsOccurrence of SendPacket More Complex Arc ExpressionIf-then-else ExpressionIf-then-else ExpressionNew Name and TypeNew Place: NextRecCorrect packet arrivesCorrect Packet ReceivedWrong Packet ArrivesWrong Packet ArrivedAcknowledgements can be lostNextSend is updatedSlide Number 39Transitions can have a guardGuard must evaluate to trueGuard must evaluate to trueFormal Definition of CPNsEnabling and OccurrencePart 3: Hierarchical �Protocol CPN ModelCPN ModulesSimple ProtocolSender ModuleReceiver moduleNetwork moduleProtocol ModuleProtocol ModuleProtocol ModulePort-Socket RelationPort-Socket RelationReferences: Getting Started