swarm-support
[Top][All Lists]
Advanced

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

Re: PermutedIndex behaviour


From: Marcus G. Daniels
Subject: Re: PermutedIndex behaviour
Date: 21 Jun 2000 11:33:37 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "FM" == famasce  <address@hidden> writes:

FM> will the behaviour of the PermutedIndex objects be correct,
FM> considering that all the agents (except the last one) have built
FM> their PermutedIndex object on an incomplete (not fully
FM> initialized) collection?

The index will reflect the contents of the collection as of the time
the index was created; the index creation should be delayed.

Say, like this:

#import <simtools.h> // initSwarm
#import <collections.h> // Array
#import <defobj/Create.h> // CreateDrop
#import <objectbase/Swarm.h> // Swarm
#import <defobj/defalloc.h> // getZone

#define COUNT 10

@interface Agent: CreateDrop
{
  id <Array> population;
  unsigned ID;
}
+ create: (id <Zone>)aZone setPopulation: (id <Array>)thePopulation setID: 
(unsigned)theID;
- (unsigned)getID;
- (void)permutePopulation;
@end

@implementation Agent
+ create: (id <Zone>)aZone setPopulation: (id <Array>)thePopulation setID: 
(unsigned)theID
{
  Agent *obj = [self createBegin: aZone];
  obj->population = thePopulation;
  obj->ID = theID;
  return [obj createEnd];
}

- (unsigned)getID
{
  return ID;
}

- (void)permutePopulation
{
  id <Index> index = [population beginPermuted: getZone (self)];
  id member;

  printf ("Agent: %u sees permutation:", ID);
  for (member = [index next]; [index getLoc] == Member; member = [index next])
    printf (" %u", [member getID]);
  printf ("\n");
  [index drop];
}
@end

@interface ModelSwarm: Swarm
{
  id <Array> population;
}
- buildObjects;
@end

@implementation ModelSwarm
- buildObjects
{
  unsigned i;

  [super buildObjects];
  population = [Array create: globalZone setCount: COUNT];

  for (i = 0; i < COUNT; i++)
    [population atOffset: i
                put: [Agent create: self setPopulation: population setID: i]];
  return self;
}

- (void)test
{
  [population forEach: M(permutePopulation)];
}
@end

int
main (int argc, const char **argv)
{
  initSwarmBatch (argc, argv);
  
  {
    id modelSwarm = [ModelSwarm create: globalZone];

    [modelSwarm buildObjects];
    [modelSwarm test];
  }
  return 0;
}

/*
Local Variables:
compile-command: "/opt/SDGswarm/2.1.1/bin/libtool-swarm --mode=link gcc -o 
arrayTest -Wall -Werror -g -Wno-import -I/opt/SDGswarm/2.1.1/include 
-L/opt/SDGswarm/2.1.1/lib arrayTest.m -lswarm -lobjc"
End:
*/

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