Write-in-file monitoring functions

Each one of the Write-in-file monitors has the following monitoring functions:

Initialization function
is called once before a simulation starts. It returns a string that is added to the file before the simulation starts.
Predicate function
is called after simulation steps. When the predicate function returns true, the observation and action functions are called.
Observation function
examines the monitored nodes, and returns a string to be added to the file.
Action function
adds the strings that are returned by the observation function to the file.
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

Generic Write-in-file monitors

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.

Examples of monitoring functions

All of the following examples are examples of monitoring functions for the Simple protocol example net. Additional examples of write-in-file monitoring functions can be found in the Example nets for the Queue system example.

Initialization functions

Initialization functions cannot examine transitions – for more information see the help page for Monitoring functions.

Example 1

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) =  ""

Example 2

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 Color set functions, and the ms_to_col is a function for Multisets.

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  

Predicate functions

Example 1

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

Example 2

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

Observation functions

Example 1

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

Example 2

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

Stop functions cannot examine transitions – for more information see the help page for Monitoring functions.

Example 1

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

Example 2

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

Related pages