Agent-based Modelling with Statecharts

Studying the behaviour of spatially distributed systems using collections of interacting Statecharts


Contents:


Team

Nabeelah Ali is the sole team member for this project.


Motivation

Emergent behaviour is the complex behaviour and patterns that arise out of many simple interactions. Examples of emergent behaviour can be seen everywhere: for example, in the flocking of birds, ant colonies, and weather patterns. In the case of the flocking of birds, birds are agents that follow simple rules - the pattern that emerges is the familiar V shape.

This project will be concerned with using Harel Statecharts to model the behaviour of individual agents. Statecharts are a modelling formalism that allow superstate and concurrent states, allowing for detailed description of agent behaviour.

For this project, the spreading of disease in a spatially-distributed system will be studied.


Proposal/Requirements

The system will be a cellular automaton, with the behaviour of each cell/agent specified by a Statechart.

The requirements of the system are as follows:


Design

I propose to use the funcitonality of AToM3 to create the Statecharts that will model the behaviour of the agents (in this case of disease-spreading, the agents are people). Statecharts can compile through AToM3 to Python code, whereby the Statechart becomes a class whose functionality can be used.

The second part will then be to create a 2D spatial layout that allows the agents to move about it. Proximity to other agents will dictate what events are triggered. These triggered events are broadcast to the Statechart, which will react by changing states or completing whatever other behaviour is dictated. This part will be coded in Python, using Numpy for array-handling, and pygame for visual relaying information back to the user.


Implementation

A ZIP | TAR of the project files can be downloaded. To run the files, Python, as well as the numPy and pyGame extensions, are needed. The main file is simpleDisease.py, run this to run the simulation. It is not recommended that it be run through IDLE, as IDLE and pyGame don't much like each other. Instead, the file should be run via the UNIX command line, DOS Prompt on Windows, or a more pyGame friendly editor like drPython. It is liberally commented to allow for easy reading and self-documenting.

The 2D layout for the agents is implemented as a numpy array. When agents reach one end of the canvas, the continue on the other end. The agents move one square in a random direction when the move action occurs on their corresponding Statecharts.

The script initially asks the user to input values for several variables relating to the simulation. The GUI the intializes and the simuulation runs for the specified time period.

Here is a screenshot of the program running, with grid size set to 30x30 and 100 agents.

To see the program running without needing the proper extensions, in an AVI format, view a demo here[9.55MB]. At the end of the simulation, the script prints out the total number of agents that are healthy, infected and dead.

When creating Statecharts to model disease behaviour, the following triggers and actions can be used:

Triggers:

AFTER(x)   # Time-delay. Replace x with appropriate number.
start      # Occurs when the Statechart is initialized.
infection  # Occurs when agent is next to an infected agent.
immunized  # Can be manually triggered to immunize agents.
healthy    # Broadcast when makeHealthy() runs.
dead       # Broadcast when die() runs.
infected   # Broadcast when makeInfected() runs.

Actions:

controller=[PARAMS]       # Must be used in the first transition.
controller.move()         # Move in a random direction.
controller.makeHealthy()  # Change state ->healthy.
controller.makeInfected() # Change state ->infected.
controller.die()          # Change to 'dead' state.
controller.bury()         # Remove agent from screen.

To create a Statechart, use the DCharts meta-model in AToM3. After drawing up the Statechart using the permissible triggers and actions listed above (and make sure to include the trigger start with the action controller=[PARAMS] to initialize the simulation properly), click on the generate .des button. Save the .des file in the same directory as simpleDisease.py, then when asked whether to compile the DES file immediately, click 'Configure compiler'. Select the Python path, and then press OK. In the dialog box that follows, type in -l python --ext and then click OK. Done!

Here is an example of a Statechart that determines disease behaviour for an agent:


Experiments

Three experiments were carried out, to view the effects of:


Conclusions

The advantages of combining a Statechart with cellular automaton formalism include:

The merging of statechart + cellular automaton formalisms gives rise to a new formalism than can be extended to many fields to view the effects of agents with complex behaviour.


References

David Harel, Statecharts: A visual formalism for complex systems. Science of Computer Programming, 8(3):231–274, June 1987.


Presentation

Download a copy of the presentation in PDF format.


Interesting Asides

A mushroom take on John Conway's Game of Life [click]

|