next up previous
Next: STAY schedules exit time Up: INSTRUCTIONS Previous: SENDTO sends messages in

STATE controls activations and state of G type node

Syntax:

    STATE <associated instruction>;
It is used to change the state in a type G node. The state is specified by the user using variables of any type, and giving them values by means of any code.

It may be used only in type G nodes. If it is used must be the first instruction in the code.

The <associated instruction> is only executed if the event refers to the node. No execution is made during the scanning of the network.

The instruction is executed even if the EL of the node is empty.

If the node is a multiple one, the instruction is activated and the value of the index IEV of the event element is passed to the variable INO. Thus, the programmer can control the execution for the different nodes.

The <associated instruction> cannot have SENDTO instructions but can use Pascal and common GLIDER instructions.

Examples:

  1.        Portal (G) :: STATE IF p = open 
                                          THEN BEGIN p := closed; IT := 10 END
                                          ELSE BEGIN p := open;   IT := 20 END;
                               IF p = open THEN SENDTO(Castle) ELSE STOPSCAN;
    Messages (Knights) that arrived at Portal only pass to Castle if the value of p is open. Due to the STOPSCAN only one message of the EL (the first one) is considered if p is closed. The STATE instruction works in an independent way. The variable p is put closed by 10 units of time, and open by 20 units of time alternatively. To start this process the node Portal must be firstly activated from other part of the program.

    The part of the code outside the <associated instruction> of the STATE (the second IF instruction) is executed each time the node Portal is activated during the scanning of the network if the EL is not empty.

  2.        RandomSend (G) ::
                            STATE BEGIN j := 1; u := UNIF(0, 1);
                                    WHILE tran[i,j] < u DO i := i + 1; j := i;
                                    IT := perm[i]
                                    END;
                            SENDTO(Destination[j]);
    tran is a matrix with accumulated values of a probability distribution in each column. It can, for instance, be defined by:
            ASSI tran[1..3, 1..3] :=  (( 0.1, 0.4, 0.2),
                                       ( 0.7, 0.9, 0.6),
                                       ( 1.0, 1.0, 1.0));
    This corresponds to the transition probability matrix T:
                                      0.1  0.4  0.2
                               T =    0.6  0.5  0.4
                                      0.3  0.1  0.4
    If it is j = 2, the probability of transition to 1 is 0.4, to 2 is 0.5, to 3 is 0.1. See that:
    Tran[1, 2] := 0.4; Tran[2, 2] := 0.4 + 0.5; Tran[3, 2] := 0.4 + 0.5 + 0.1; When a message in the EL of the node is processed and a initial value was assigned to j (that is the state of the RandomSend node), then a random value between 0 and 1 is assigned to u. The WHILE cycle searches from top to bottom in the column j, for the last row for which u < Tran[i, j]. So, the probability of a certain final value of i is the value of T[i,j]. That i value is assigned to j. The next change of state is made after a time given in the Perm array. Messages arriving during this time interval are sent to Destination[j]. So, the destination varies according to states that change at random with the transition probabilities given by the matrix T.

next up previous
Next: STAY schedules exit time Up: INSTRUCTIONS Previous: SENDTO sends messages in

domingo c
Mon Mar 20 17:36:19 PST 2000