swarm-support
[Top][All Lists]
Advanced

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

Re: Dynamic agent list


From: Ken Cline
Subject: Re: Dynamic agent list
Date: Fri, 17 Apr 1998 00:09:44 -0400 (EDT)

On Thu, 16 Apr 1998, Mike Roth wrote:

> I was wondering if it was possible pass the Schedule object a list of
> agents that would 
>       + change in size 
>       + change contents
> and not have to worry about messages being sent to non-existant objects or
> other objects in the list not recieving any messages &c.

Yup!

You want to use one of `at:createActionForEach:message:'
methods the Schedule class provides; which one you use will
depend on how many arguments need to be sent with message.

The `at:createActionForEach:message:' methods create one
action whose target is the collection that's passed in.
Every time that action is executed by the scheduling
mechanism all the current objects in the collection will
receive the specified message (as I understand it).

There is one caveat: all objects in the collection, when the
action is executed, must respond to specified method.  I'm
pretty sure the program will exit if this rule is broken.
(More about this below...)

Finding the relevant portions of the documentation is a
little bit of a challenge in this case, however, after
you've been back and forth thru them a few dozen times you
start to know where to look. ;-)

>From the "ActionGroup" documentation:

   "...The createActionForEach: messages define a message
    to be sent in the same way as the createActionTo
    messages, but they assume that the object passed as the
    target argument is a collection object. They specify
    that each object available from that collection, using
    the standard messages of the Collection type in the 
    collections library, is to receive the specified 
    message. ..."

And from "Schedule" documentation:

   "...The messages to create actions within a schedule are
    essentially the same as those for ActionGroup, except
    for the presence of an initial at: argument indicating
    the time at which an action is to be performed. Except
    for the time associated with each action, meaning of the
    createAction messages is the same as for ActionGroup.
    ..."

(FYI: improved documentation is high on the Hive's priority
list.  It is my understanding that any suggestions about,
but especially contributions to, the documentation effort
will be greatly appreciated.)

I think there's an example of using `createActionForEach:'
method in Heatbugs and probably the other sample apps as
well.

BTW, there is another, less popular, way to get the same
result.  Instead of using:
   [ mySchedule at: 0 createActionForEach: myCollection
                                  message: M(foo)       ]
you could try:
   [ mySchedule at: 0 createActionTo: myCollection
                             message: M(ForEach:)
                                    : (id)M(foo)   ]

The latter could only be used with methods that require
2 or fewer arguments, whereas the former allows upto 3
arguments to be passed.


Filtering the collection... As I mentioned above all objects
on the target collection must respond to the specified
method.  If you want to remove that restriction then you
could implement some intermediate method which filters the
collection.  You could place this filtering method in you
ModelSwarm and then schedule a call to it instead of the
call to the collection.

For example:

   -(void) filterActionForEach: target message: aSel {
      id <Index> targetIndex  = NULL;
      id         targetMember = NULL;

      if ( ! target || ! aSel ) return;
      if ( ! [target conformsTo: Collection] )
         raiseEvent( WarningMessage, "Target is NOT a
                                      Collection!\n"  );
      if ( ! [target getCount] ) return;

      targetIndex = [ target begin: [self getZone] ];
      while ( targetMember = [targetIndex next] ) {
         if ( [targetMember respondsTo: aSel] )
            [ targetMember perform: aSel ];
      }
      [ targetIndex drop ];
   }

And then add a scheduled a call to that method:

   [ mySchedule createActionTo: self
                       message: M(filterActionForEach:message:)
                              : (id)target
                              : (id)M(foo)                      ]

I'm not sure why you'd actually what to use this though.

Anyway, I hope I answered your question.


Ken.


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427


                  ==================================
   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]