Firing rule in SNAKES
Saturday, January 16, 2010
In SNAKES, one cannot use Expression objects as input arcs annotations, moreover, all the variables used in a transition guard and output arcs should be bound through (at least) one of the input arcs. These restrictions can be explained.
When calling method t.modes(), the available modes are computed by matching the input arcs annotations with respect to the available tokens in the corresponding input places. This is a simple task when input arcs are only annotated with values, variables or tuples of such objects. But it may become impossible if expressions would be used. Indeed, imagine a place p and an arc from p to t labelled by Expression("f(x)") where f is an arbitrary Python function. For each token value v in p, t.modes() would required to solve f(x)==v wrt x in order to find all possible bindings of x.
So, SNAKES simply forbids expressions on input arcs. This could be relaxed a bit when, for instance, x can be known from another input arc. But this would lead to complex code and usually, there is another way to achieve the same effect. In this instance, we can bind tokens from p using an annotation Variable("y") and add "y == f(x)" in the guard of t.
Now, given a Transition instance t and a Substitution instance m, the execution of t.fire(m) can be decomposed into several steps:
- check if the guard evaluates to True;
- check if the input places have enough tokens with respect to the evaluation of each input arc;
- check if the output places can accept the tokens corresponding to the evaluation of each output arc;
- consume tokens from the input place;
- produce tokens to the output places.
This explains why it is recommended that all variables are bound through input arcs. But this is not a requirement when modes are user-provided instead of being computed using t.modes().
Post a comment