Dynamic scheduling in simpleObserverBug2-growth

Changes in ModelSwarm

The ModelSwarm now has a new schedule, called growthSchedule, which starts out with no actions on it. It is then called by ModelSwarm to schedule future events. Note that we set AutoDrop to true, which means that actions are assumed to happen only once and will be erased from memory.

This is where growthSchedule is created

  growthSchedule = [Schedule createBegin: [self getZone]];
  [growthSchedule setAutoDrop: 1];
  growthSchedule = [growthSchedule createEnd];

And this is where it gets activated with the other actions in the activation phase, although the schedule is for now empty.

  [growthSchedule activateIn: self];

This method in ModelSwarm is called by FoodSpace to schedule growth at a certain time. The growthInterval parameter determines how many periods hence growth will occur.


-scheduleGrowthAtX: (int) x Y: (int) y {
  long time;
  
  time=[[self getActivity] getCurrentTime];

  [growthSchedule at: time+growthInterval
      createActionTo: foodSpace
	     message: M(putValue:atX:Y:):1:x:y];

  return self;
}

The ModelSwarm also can create two different types of bugs, a regular bug and a "thinking bug" depending on whether the variable makeThinkingBugs is set to one or not, (from the buildObjects method:)

   if(makeThinkingBugs)
     aBug = [Bug createBegin: [self getZone]];
   else 
     aBug = [ThinkingBug createBegin: [self getZone]];

There is also a new method and probe associated with this to switch between the two modes

Changes in FoodSpace

The bugs now call the following method, instead of simply setting the value of the food location to 0

-eatX: (int) x Y: (int) y {
  
  [self putValue: 0 atX: x Y: y];
  [model scheduleGrowthAtX: x Y: y];

  return self;
}

Changes in the Bugs

There are now two classes of bugs, the regular Bug and the ThinkingBug. Both bugs have a new variable, lifetime. For each period that the bug can't eat lifetime decreases by one. When the bug finds food lifetime is extended by one unit.

The thinking bug also has a small amount of intellingence, he remembers the direction he was going in and follows that gradient if he found food last time (from the step method:)

  if(haveEaten!=1) {
    xDir= [uniformIntRand getIntegerWithMin: -1 withMax: 1];
    yDir= [uniformIntRand getIntegerWithMin: -1 withMax: 1];
  } 

Benedikt Stefansson <benedikt@ucla.edu>