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 []
.
Syntax
- 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.
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.
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.
Side effects
Guards are not allowed to have side effects and cannot:
- Contain input/output or
use
commands. - Update or use reference variables.
- Use the
time
function - Use the
random
function.
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 net contains guards: Resource Allocation.
You must be logged in to post a comment.