Write-in-file monitoring functions | CPN Tools help |
CPN ML |
Each one of the Write-in-file monitors has the following monitoring functions:
The predicate function is called after simulation steps. When the predicate function returns true, the observation and action functions are called.
The observation function examines the monitored nodes, and returns a string to be added to the file.
The action function adds the strings that are returned by the observation function to the file.
The stop function is called when simulation stop criteria have been met. It returns a string that is added to the file, when stop criteria have been met.
Accessibility of the monitoring functions for write-in-file monitors:
initialization | predicate | observation | action | stop | |
Generic write-in-file | accessible | accessible | accessible | hidden | accessible |
Function types for the accessible functions
init : markings -> string |
initialization function |
pred : subnet -> bool |
predicate function |
obs : subnet -> string |
observation function |
stop : markings -> string |
stop function |
For more information about the subnet
and markings
data types see Data types for monitored subnets.
All of the following examples are examples of monitoring functions for the Simple Protocol net. Additional examples of write-in-file monitoring functions can be found in the example net for the Queue System.
Initialization functions cannot examine transitions -- for more information see the help page for monitoring functions.
The following initialization function is for a monitor that is associated with one place and two transitions, and it returns the empty string.
fun init (Top'NextRec_1_mark : INT ms) = ""
The following initialization function is for a monitor that is associated with one place and two transitions, and it returns a string with information about number of tokens on the place NextRec
on the page Top
. If there is just one token on the place, then the function will also return information about the value of the token on the place. The INT.mkstr
function is one of the colour set functions, and the ms_to_col
is a function for multi-sets.
fun init (Top'NextRec_1_mark : INT ms) = let val n = size Top'NextRec_1_mark in "Number of tokens on NextRec in initial marking: "^ Int.toString(n)^ (if n=1 then "\n Value of the token: "^ INT.mkstr(ms_to_col Top'NextRec_1_mark) else "")^"\n\n" end
The following predicate function is for a monitor that is associated with one place and two transitions, and it returns true when either one of the transitions occurs. The function ignores the marking of the place NextRec
.
fun pred (bindelem, Top'NextRec_1_mark : INT ms) = let fun predBindElem (Top'Receive_Packet (1, {k,n,p,str})) = true | predBindElem (Top'Send_Packet (1, {n,p})) = true | predBindElem _ = false in predBindElem bindelem end
The following predicate function that is associated with one place and two transitions. The function returns true either when the Transmit_Ack
transition occurs and the acknowledgement is lost (as indicated by not (Ok(s,r))
, or when the Transmit_Packet
transition occurs and the packet is lost.
fun pred (bindelem, Top'B_1_mark : INTxDATA ms) = let fun predBindElem (Top'Transmit_Ack (1, {n,r,s})) = not(Ok(s,r)) | predBindElem (Top'Transmit_Packet (1, {n,p,r,s})) = not(Ok(s,r)) | predBindElem _ = false in predBindElem bindelem end
The following observation function is for a monitor that is associated with one place and two transitions. The function returns a string. The first part of the string shows the simulation step number. The step()
function is one of the simulator functions. The second part of the string contains information about which transition occurred.
fun obs (bindelem, Top'B_1_mark : INTxDATA ms) = let fun obsBindElem (Top'Transmit_Ack (1, {n,r,s})) = "Transmit Ack occurred\n" | obsBindElem (Top'Transmit_Packet (1, {n,p,r,s})) = "Transmit Packet occurred\n" | obsBindElem _ = "" in "In step: "^Int.toString(step())^", "^(obsBindElem bindelem) end
The following observation function is for a monitor that is associated with one place and two transitions. The function returns a string. The first part of the string indicates how many tokens are on place B
. The function size
is a function for multi-sets. The second part of the string contains information about which transition occurred. When the Transmit_Ack
transition occurs, the value of the variable n
which has type INT
is included in the string. When the Transmit_Packet
transition occurs, the values of the variables n
and p
, which are of type INT
and DATA
, are included in the string.
fun obs (bindelem, Top'B_1_mark : INTxDATA ms) = let fun obsBindElem (Top'Transmit_Ack (1, {n,r,s})) = "Transmit Ack occurred, n="^INT.mkstr(n)^"\n" | obsBindElem (Top'Transmit_Packet (1, {n,p,r,s})) = "Transmit Packet occurred, (n,p)=("^ INT.mkstr(n)^","^DATA.mkstr(p)^")\n" | obsBindElem _ = "" in "#tokens on B: "^Int.toString(size Top'B_1_mark)^ ", "^(obsBindElem bindelem) end
Stop functions cannot examine transitions -- for more information see the help page for monitoring functions.
The following stop function is for a monitor that is associated with one place and two transitions. The function returns a string which indicates how many simulation steps were executed.
fun stop (Top'B_1_mark : INTxDATA ms) = "\nThe simulation stopped after step "^ Int.toString(step())
The following stop function is for a monitor that is associated with one place and two transitions. The function returns a string which indicates how many simulation steps were executed together with a representation of the tokens on the place B. The INTxDATA.mkstr_ms
function is one of the colour set functions.
fun stop (Top'B_1_mark : INTxDATA ms) = "\nThe simulation stopped after step "^ Int.toString(step())^"\nFinal marking of place B: "^ INTxDATA.mkstr_ms(Top'B_1_mark)