swarm-support
[Top][All Lists]
Advanced

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

Death In Swarm


From: Manor Askenazi
Subject: Death In Swarm
Date: Wed, 16 Oct 1996 10:54:42 -0600


                        Safe Death In Swarm
                        -------------------

Hi Tomas,
 
  ... and all other Swarm users who plan to introduce death into their 
  currently idyllic and carefree worlds!

Death, as you may know, is a serious matter not to be rushed into lightly.
Now, I understand that in the heat of passionate modeling you may want to 
simply have your objects terminate themselves smack in the middle of a 
forEach: step, as in:

  [modelActions createActionForEach: objectList message: M(step)] ;

but this, as we shall see, causes trouble - which is why you need to use 
a ReaperQueue. This is how it works...

Take any ol' Banana agent:

-----------------------[ Melodramatic Banana ]---------------------------

-step {

  if([self inDespair])
    [self Suicide] ;
  else
    [self lifeGoesOn] ;

  return self ;
}

-Suicide {

  //Note: I am *not* dropping myself yet, because somewhere there is a list
  //on which I appear where a forEach: step method was called, if I drop 
  //myself now, I will completely perturb the work of that list (it doesn't 
  //expect bananas to off themselves in the middle of a forEach call)!

  [reaperQueue addLast: self] ;

  return self ;
}

-------------------------------------------------------------------------

Now, in the Model object you have the following:

-------------------------[ Kevorkian Swarm ]-----------------------------

-endTheirSuffering {
  
  //Note: I do *not* use a forEach: drop call because otherwise we are in 
  //the same trouble we were in earlier (a list being traversed where the 
  //objects are removing themselves)!!!
 
  id index, suicidalBanana ;

  index = [reaperQueue begin: [self getZone]] ;

  while( (suicidalBanana = [index next]) ){
    [index remove] ;        //remove the Banana from the reaperQueue.
    [suicidalBanana drop] ; //remove the Banana from the world.
  }

  [index drop] ;

  return self ;
}

// So, the overall schedule looks like this:

-buildActions {
  
//    -------------[A Day In The Life Of Mr Banana]------------------

  modelActions = [ActionGroup create: [self getZone]] ;
  [modelActions createActionForEach: bananaList message:   M(step)] ;
  [modelActions createActionTo: self message: M(endTheirSuffering)] ;

  return self ;
}

-------------------------------------------------------------------------

Conclusion: 
-----------

The Swarm simulation software takes a Catholic stance on the issue 
of suicide. In other words, objects which appear on a schedule or a 
collection of any sort, are not allowed to off themselves, they must 
ask some other agent to do it for them (God, the ModelSwarm, whatever)
by manually going over a collection (i.e. without using a forEach call) 
and calling the drop method on the suicidal objects within that collection.

Hope this helps,

Manor.

Note: having a reaperQueue has some additional benefits -> you can
easily keep track of the number of deaths in your system by simply
doing a [reaperQueue getCount] at the appropriate time.

You can also collect statistics over some parameter, which all the 
dying objects had, which you think may be relevant to their being 
less successful in your simulation etc. (it may have been foul play)!


reply via email to

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