- A variable is an identifier whose value can be changed during the execution of the model.
- A binding is the association of a value with a variable. A binding has both scope and content.
- A scope is the locations in a model in which a particular binding can be referenced.
- An extent is the interval during which a particular binding is in effect.
CPN variables are variables that are used in CP-net inscriptions. They have the following characteristics:
- They are declared using the reserved word
varand the name of a previously declared color set.
- They are bound to a variety of different values from their color set by the simulator as it attempts to determine if a transition is enabled.
- A variable is bound to a value, the scope of a variable is local to the transition.
- There can be multiple bindings simultaneously active on different transitions. These bindings can exist simultaneously because they have different scopes.
- The extent of a CPN variable binding is the firing of a particular transition.
- They provide arc inscriptions with the ability to reference different values.
If a variable is from a color set with less than 100 elements, the simulator is always able to bind a value to it.
var id1, id2, …, idn : cs_name;
idimust be an identifier.
:is the syntactic separator between the identifier(s)
cs_nameis the name of a previously declared color set.
var i,j,k : INT;
var intList : IntList;
A reference variable is similar to a pointer in C. The scope of a reference variable is the entire CPN.
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 arc inscriptions for input arcs 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 transition is chosen for firing would degrade performance to the point of unusability). Attempting to fire transition B results in unpredictable system errors.
Reference variables may be read and updated in code segments.
Reference variables may be read in
- Output arc inscriptions on output arcs from transitions
- Arc delay inscriptions on output arcs from transitions
- Time inscriptions for transitions
Several kinds of inscriptions may not depend on reference variables in any way. The following kinds of inscriptions may not be used to read or update reference variables, nor may they depend on any declarations that depend on reference variables:
- Input arc inscriptions on input arcs to transitions
- Arc delay inscriptions on input arcs to transitions
- Color set inscriptions for places
- Initial marking inscriptions for places
The restrictions on where reference variables may and may not be used are currently not checked or enforced by CPN Tools. The simulator and state space tool may malfunction if the restrictions are violated.
globref id = exp;
globref i = 10;
globref cur_date = (Mon, 5);
!r: contents of the reference variable
r:=v: assignment of the value
vto the reference variable
ref v: reference constructor
inc r: increment contents of integer reference variable
rby one, i.e. add one to the contents of
dec r: decrement contents of integer reference variable
rby one, i.e. subtract one from the contents of