4.5. Scheduling a Model Swarm

Once all of the simulated objects are created in buildObjects, the next task is to schedule them in the method buildActions.

modelActions = [ActionGroup create: [self getZone]];
[modelActions createActionTo: heat message: M(stepRule)];
[modelActions createActionForEach: heatbugList message: M(step)];
[modelActions createActionTo: heat message: M(updateLattice)];

modelSchedule = [Schedule createBegin: [self getZone]];
[modelSchedule setRepeatInterval: 1];
modelSchedule = [modelSchedule createEnd];
[modelSchedule at: 0 createAction: modelActions];

The heatbug model schedule actually consists of two components: an ActionGroup called modelActions and a Schedule called modelSchedule. The ActionGroup is a tightly coupled list of three messages: every time the action group is executed, it will send three messages in a row:

[heat stepRule];
[heatbugList forEach: step];
[heat updateLattice];
The ActionGroup alone specifies three messages to send - in order to put it in the simulation, that ActionGroup is then dropped into a Schedule. The Schedule itself only has one action - to execute modelActions itself. That action takes place at time 0. But because we've set a repeat interval on the schedule of 1, the schedule itself loops, executing every 1 time step. The final result is that modelActions is executed at time 0, time 1, etc.