[home] [info] [docu] [examples] [download] [contact] [applications] [bugs]

AGG

   Computing n!
   with a simple actor system

Summary

Here is an introductory graph grammar, simply-structured, explaining how to combine graph transformations with computations on attributes in AGG.

Actors are processing units which may communicate with each other by message passing.  When modeling  an actor system by a graph grammar, an actor is represented by a node. Actor nodes are linked by edges if they know each other. Message passing and processing is modeled by graph rules.


Screenshots

In this example, the start graph contains no actor. Rule Ask For Value asks the user for the number n for which  n! should be computed:

Now the start graph consists of one actor holding the number n.

Rule Delegate delegates the task  for n-1 to a new actor. This rule is applied until number 2 is reached:

When we are done applying delegate, a chain of actors has been created, just as shown in the figure above. Now, rule endDelegate is applicable once.

Then, rule multiply is applicable: it takes the numbers of the last two actors and multiplies them. The result is stored in the last but one actor, while the very last one is deleted. Applying rule Multiply as long as possible yields the following result, where there is only one actor left, containing the computed result for n!.

 
Revision: