A number of functions are predefined for some or all color sets. In the following, we assume that the color set cs
has been declared.
If cs
is a timed color set, then the functions below can be used for the untimed version of the color set. Functions for the timed version of the color set are described on the help page for Timed color set functions.
Declare clause
Please read about the declare clause if one or more of the following is true:
- The version of CPN Tools that you are using is 0.1.53 or below
- You have declared product color sets that are cartesian products of 10 or more sets
- You have declared record color sets with 10 or more identifiers.
Equality Operators
The equality operators =
and <>
are defined for all color sets, while <
, >
, <=
and >=
are only defined for integer color sets and string color sets. To test the order of the elements in other color sets, use the lt
function, which is described below.
Operations for all color sets
cs.lt(c1,c2)
: less than in the color set orderingcs.legal(v)
: test whether valuev
is a member of the color setcs
.v
must be a member of either the color setcs
, an alias color set forcs
or a superset color set ofcs
.cs.mkstr(c)
: make string representation of a colorcs.mkstr_ms(ms)
: make string representation of a multi-set
Examples of legal expressions
INT.lt(3,5)
evaluates to true
Weekend.legal(Mon)
evaluates to false
Answer.mkstr(no)
evaluates ton
INT.mkstr_ms(1`3++2`7++4`3)
evaluates to "5`3++2`7"
Examples of illegal expressions
INT.lt(3,true)
INT.legal(3.1415)
Input/Output Operations
cs.input(s)
: read a color from input streams
cs.input_ms(s)
: read a multi-set from input streams
cs.output(s,c)
: write color c to output streams
cs.output_ms(s,ms)
: write multi-set ms to output streams
Examples of use
val fid = TextIO.openOut(“/tmp/outputfile.txt”);
INT.output_ms(fid,1`3++2`7);
TextIO.closeOut(fid);
For additional details about opening and closing text files see the TextIO structure in the SML Basis Library Manual.
Operations for small color sets
The following functions can be used for all small color sets.
cs.all()
: multi-set with one of each element in the color setcs.ran()
: returns a random colorcs.size()
: number of elements in the color setcs.ord(c)
: convert color to number representing its position in the color set, where positions are numbered from0
tocs.size()-1
cs.col(i)
: convert position number to color
These functions also exist for large color sets. However, an exception will raised when these functions are invoked for large color sets.
Examples of useful expressions
Day.size()
evaluates to 7
Day.col(0)
evaluates to Mon
SmallInt.ran()
returns an integer between (inclusive) 1 and 10
Examples of expressions resulting in exceptions
INT.ran()
String.size()
Functions for union color sets
The of_
functions are only available for union color sets.
cs.of_idi(v)
tests whether valuev
belongs to the componentidi
Examples of use
Packet.of_DATA(DATA(“abc”))
returns true
Packet.of_DATA(DATA(“abc123”))
returns false
Packet.of_DATA(ACK)
returns false
Functions for product and record color sets
The following functions are only available for product color sets and record color sets.
cs.set_idi c v
: changes componentidi
in color c to valuev
while leaving all other components unchanged.cs.mult(ms1, ms2, ...,msn)
: returns product of multi-sets, where for i=1..n,msi
is a multi-set of values from color setnamei
as determined by the declaration forcs
.
For product color sets idi
must be a value between 1 and n, where n is the number of components in the product. For record color sets idi
must be one of the labels defined in the declaration of the color set.
Examples of use
colset P = product INT * STRING;
colset R = record i:INT * s:STRING;P.set_1 (5, “abc”) 3
evaluates to (3, "abc")
R.set_s {s=”abc”, i=5} “def”
evaluates to {i=5, s="def"}
P.mult(1`2++1`3, 1`”abc”++1`”def”)
evaluates to 1`(2,"abc")++1`(2,"def")++1`(3,"abc")++1`(3,"def")
The mult
function is used in the example CP-net for the Distributed Database example.
You must be logged in to post a comment.