Variables
Description of CPN variables and reference variables CPN ML


Term Definitions

Variables A variable is an identifier whose value can be changed during the execution of the model.
Binding Binding is the association of a value with a variable. A binding has both scope and content.
Scope Scope is the locations in a model in which a particular binding can be referenced.
Extent Extent is the interval during which a particular binding is in effect.

CPN Variables

CPN variables are variables that are used in CP-net inscriptions. They have the following characteristics: If a variable is from a colour set with less than 100 elements, the simulator is always able to bind a value to it.

Declaration Syntax

var id1, id2, ..., idn : cs_name;

where:

Declaration Examples

var i,j,k : INT;

var intList : IntList;

Reference Variables

A reference variable is similar to a pointer in C. The references may only be used in code segments. The scope of a reference variable is the entire CP-net.

Reference variables must never be used in any way that affects the enabling of transitions. To illustrate the problems that could arise if this rule were broken, consider the following example:

A reference variable, refvar is used in the arc inscription of two different transitions, transition A and transition B. Both are enabled, and transition A fires. Transition A changes the value of refvar in such a way that transition B is no longer actually enabled. However, the simulator has no way of knowing this, since enabled transitions are not rechecked before they are fired (to recheck each time a trasition is chosen for firing would degrade performance to the point of unusability). Attempting to fire transition B results in unpredictable system errors.

Declaration Syntax

globref id = exp;

Declaration Examples

globref i = 10;

globref cur_date = (Mon, 5);

Operations

!r contents of the reference variable r
r:=v assignment of the value v to the reference variable r
ref v reference constructor
inc r increment contents of integer reference variable r by one, i.e. add one to the contents of r
dec r decrement contents of integer reference variable r by one, i.e. subtract one from the contents of r