9.5. What is an Activity?

The Activity class is a vital element of the Swarm approach. It's fundamental purpose is to merge all the subjective points of view of agents at different levels into a single objective time sequence. Somehow, the name Activity does not seem powerful enough. Perhaps perhaps it would be better called an ActivityManagerAndIntegrator, or something grand. Of course, on a practical level, it responds to messages like run, stop, next, terminate, and so forth.

If you have an object subclassed from Activity, you can tell it to make the simulation run, stop, terminate, or respond to a number of other commands. Swarm programs are designed hierarchically, so that if you tell an activity from one level to stop, you stop all lower levels of the simulation as well. Many Swarm programmers do not come face-to-face with the Activity class because it sits behind the scenes. The control panel, in particular, allows users to start and stop their simulations, and all the while the Activity class objects are behind the scenes, doing the actual work.

It is easy to "grab" the activity object of a given Swarm. The method which returns the activity of a Swarm is getActivity. If one needs to tell the object modelSwarm to stop, for example, then the command:

[[modelSwarm getActivity] stop];

will get the job done. This first grabs that object's activity, and tells that activity to stop. To make that object start up again, it can be sent the run message.

The ability to start, stop, and terminate an activity is particularly handy when designing a program that repeats a Swarm experiment. These methods are used in the Swarm tutorial's "SimpleExperBug2" model as well as the "RepeatingHeatbugs" application that is available at the Swarm ftp site.