9.3. ActionGroups

An ActionGroup is a set of actions that are supposed to happen in sequence. The buildActions method is often designed to first create an ActionGroup and then to schedule that is be repeated every now and then.

Consider the Swarm SugarScape again. Its model swarm has this buildActions method [1]:

- buildActions 
  [super buildActions];

  // One time tick, a set of several actions:
  //   randomize the order of agent updates (to be fair)
  //   update all the agents
  //   kill off the agents who just died
  //   update the sugar on the world
  modelActions = [ActionGroup create: [self getZone]];
  [modelActions createActionTo: sugarSpace message: M(updateSugar)];
  [modelActions createActionTo: shuffler message: M(shuffleList:) : agentList];
  [modelActions createActionForEach: agentList message: M(step)];
  [modelActions createActionTo: self message: M(reapAgents)];

  // The schedule is just running our actions over and over again
  modelSchedule = [Schedule createBegin: [self getZone]];
  [modelSchedule setRepeatInterval: 1];
  modelSchedule = [modelSchedule createEnd];
  [modelSchedule at: 0 createAction: modelActions];

  return self;

ActionGroups group together events at same timestep. Schedule then executes the actions. If there is only one ActionGroup in a schedule, then one might as well not create a group and just add the actions to a schedule one at a time. The use of ActionGroups is most valuable when several sets of separate actions are considered and they need to be scheduled to start at different times or repeat at different intervals.



Note: the use of shuffler to mix the agents in the list has been integrated into the Swarm libraries and by the time you read this there may be some new syntax involved.