Guards
CPN ML


Related pages

Transition inscriptions, Add/edit inscriptions, Variables

Guards

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

Syntax

Use

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

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

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

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]

Example

The following example nets contain guards: Resource Allocation.