A guard is a CPN ML Boolean expression that evaluates to true or false.

Before a guard has been added, the default text for the inscription is [].

Default guard text

Default guard text


  • a Boolean expression or
  • a list of Boolean expressions: [b-exp1, b-exp2, ..., b-expn]

The latter corresponds to b-exp1 andalso b-exp2 andalso ... bexpn, but is preferred as it gives the simulator more opportunities to bind the variables. Using a list of expressions does not necessarily have lazy evaluation like andalso as the simulator may find more efficient ways of evaluation.


Guards are used for tests on input arc inscription variables (enabling restrictions), typically using one or more of the following syntactical elements:


Guards are also used to restrict values of output arc inscription, variables, based on the values of the input arc inscription variables.

Binding variables in guards

Variables that are not found in input arc inscriptions can, in some cases, be bound in the guard.

In this example, the variable i is not on any input arcs, but it is bound to the value of the variable j in the guard.

Binding variable in a guard

Binding variable in a guard

In some cases, it is not possible to bind variables from large color sets in guards. In this example, i is a variable of an integer color set.

Large unbindable variable in guard

Large unbindable variable in guard

Side effects

Guards are not allowed to have side effects and cannot:

These restrictions are currently not checked by CPN Tools, and the system may malfunction if the restrictions are violated.

Conditional expressions

Each expression used in a guard must be a Boolean expression, evaluating to true or false. Thus the following example is legal because each variable binding is either true or not true:

[if a=3 then b=4 else c=5]

The following example is not legal because the then and else clauses evaluate to integers:

[if a=3 then 4 else 5]


The following example net contains guards: Resource Allocation.

Related pages

Transition inscriptions, Add/edit inscriptions, Variables

Inscriptions in comments
Code segments

You must be logged in to post a comment.