swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

adding new agents


From: Holger Perlt
Subject: adding new agents
Date: Mon, 10 Sep 2001 08:27:55 +0200

Hello,

I want to add at every simulation step a new agent to the list
(e.g. the famous buglist).
I did it inside the modelswarm.m file like:

- buildActions
{
  // Create the list of simulation actions. We put these in an action
  // group, because we want these actions to be executed in a specific
  // order, but these steps should take no (simulated) time. The
  // M(foo) means "The message called <foo>". You can send a message
  // To a particular object, or ForEach object in a collection.

  modelActions = [ActionGroup create: self];
  [modelActions createActionForEach: buggList    message: M(step::):
bugList :cbugList];
  [modelActions createActionTo: self message: M(reapAgents)];
  [modelActions createActionTo: self message: M(addNewRandomBug)];
  [modelActions createActionForEach: bugList    message: M(step:):
gralList];

//*******************  further source code

}

// Create a new agent at random and put it in the world.
- addNewRandomBug
{
  int x, y;
  Bug *aBug;

  // turn off these warnings.
  [world  setOverwriteWarnings: 0];

  // Create the agent object
  aBug = [Bug createBegin: [self getZone]];
  [aBug setModelSwarm: self];
  [aBug setWorld: world];
  aBug = [aBug createEnd];



  // Give the agent a random initial position and parameters.
  x = [uniformIntRand getIntegerWithMin: worldXSize/2 - 10 withMax:
worldXSize/2 + 10];
  y = [uniformIntRand getIntegerWithMin: worldYSize/2 - 10 withMax:
worldYSize/2 + 10];
  if([world getValueAtX: x Y: y] == 0){
        [aBug setX: x Y: y];
        [aBug setClusterNumber: 1];
        [aBug setClusterMode: 0];
        [world putValue: 2 atX: x Y: y];

  }

  [self BugBirth: aBug];

  // turn the warnings back on
  [world  setOverwriteWarnings: 1];
  return self;
}

// Methods to handle the birth and death of agents
- BugBirth: (Bug *)aBug
{

  [bugList addLast: aBug];
  return self;
}

But - as you guess this causes run time errors.
How can I do it better?

Holger



-- 
PD Dr. habil. Holger Perlt
Diplomphysiker/Geschäftsführer
Reinforcement Control GmbH
Karl-Heine-Str. 99
04229 Leipzig
Germany
Phone:  ++49 (0)341 9410370
Fax:    ++49 (0)341 9410372
http://www.reinforcement.de

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]