Example declarations | CPN Tools help |
Detailed description of declarations from example CP-net | CPN ML |
Declares a value (i.e. a constant). In this case the constant n
is bound to the value 4
.
Declares an index colour set named DBM
. The colour set consists of the set of elements {d(i) | i = 1..n}, i.e. the set {d(1),d(2),d(3),d(4)}.
Declares a product colour set named PR
. Each value (i.e. colour) in PR
is a pair, where each element of the pair is of type DBM
. The values in PR
have the form (d(i), d(j))
where i
and j
are integers between 1 and 4. For example, the value (d(1),d(4))
is an element in DBM
, but the value (d(1),d(10))
is not an element in DBM
.
Declares a function named diff
which has two formal parameters x
and y
. The function returns true
if the values bound to x
and y
are not equal, otherwise returns false
.
Declares a subset colour set named MES
which is a subset of the colour set PR
. The colour set MES
consists of the values of PR
that are mapped to true
by the function diff
. For example, the value (d(1),d(2))
is in MES
, but the value (d(3),d(3))
is not in MES
.
Declares an enumerated colour set named E
. The only element in E
is the value e
.
Declares a function named Mes
which has one formal parameter s
. The function Mes
returns a multi-set of elements from the colour set PR
.
The multi-set that is returned by Mes
is generated using the function PR.mult
. The function mult
is one of the colour set functions that is available for product colour sets. The two arguments for the function PR.mult
are multi-sets of elements from the colour set DBM
. The first argument consists of the multi-set 1`s
, i.e. the multi-set consists of a single element, and the value of the element is determined by the binding of the parameter s
.
The second multi-set is generated using the DBM.all
function and multi-set subtraction. Evaluating the colour set function DBM.all()
will result in the multi-set with one of each element from the colour set DBM
.
Suppose Mes(d(2))
is called, in which case, the formal parameter s
is bound to the value d(2)
. The results of evaluating subexpressions in the body of the function Mes
are described below:
Expression | Evaluates to |
1`s | 1`d(2) |
DBM.all() | 1`d(1)++1`d(2)++1`d(3)++1`d(4) |
DBM.all()--1`s | 1`d(1)++1`d(3)++1`d(4) |
PR.mult(1`s,DBM.all()--1`s) | 1`(d(2),d(1))++1`(d(2),d(3))++1`(d(2),d(4)) |
Mes(d(2)) | 1`(d(2),d(1))++1`(d(2),d(3))++1`(d(2),d(4)) |
Declares two variables, s
and r
, which have type DBM
.
All of the colour sets in this example are small, i.e. they contain a finite number of elements. More information is available about the size and complexity of colour sets.