[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on partitioning a set of agents.
From: |
Marcus G. Daniels |
Subject: |
Re: Question on partitioning a set of agents. |
Date: |
08 Aug 1999 09:24:07 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "JA" == Jason Alexander <address@hidden> writes:
JA> For one of my models I need to randomly partition a set of agents
JA> (stored as a list) into N disjoint classes, where each class is
JA> equiprobable.
Collection's -beginPermuted: is one way to do this.
#import <simtools.h> // initSwarm
#import <collections.h> // List
#import <defobj/Create.h> // CreateDrop
#import <misc.h> // sprintf
@interface Integer: CreateDrop
{
int value;
}
- setValue: (int)value;
- (int)getValue;
@end
@implementation Integer
- setValue: (int)theValue
{
value = theValue;
return self;
}
- (int)getValue
{
return value;
}
@end
#define INTEGER(value) \
[[[Integer createBegin: globalZone] setValue: value] createEnd]
#define PARTITION_SIZE 5
#define PARTITION_COUNT 10
int
main (int argc, const char **argv)
{
id <List> l;
id <Index> li;
id obj;
unsigned i;
initSwarm (argc, argv);
l = [List create: globalZone];
for (i = 0; i < PARTITION_SIZE * PARTITION_COUNT; i++)
[l addFirst: INTEGER (i)];
li = [l beginPermuted: globalZone];
for (i = 0; obj = [li next]; i++)
{
printf ("partition#: %u [%u] value: %u\n",
i / PARTITION_SIZE, i % PARTITION_SIZE, [obj getValue]);
}
[li drop];
[l deleteAll];
[l drop];
}
/*
Local Variables:
compile-command: "/opt/gnu/bin/gcc -o randomindex -g -Wno-import
-L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib
-R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib
-L/opt/SDGswarm/1.4.1/lib -L/opt/SDGzlib/1.1.3/lib -L/usr/local/X11/lib
-R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib
-L/opt/SDGhdf5/1.0.1/lib -I/opt/SDGswarm/1.4.1/include randomindex.m -lanalysis
-lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase -ldefobj
-lcollections -lmisc -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl
-L/usr/openwin/lib -lhdf5 -lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread
-lposix4"
End:
*/
==================================
Swarm-Modelling is for discussion of Simulation and Modelling techniques
esp. using Swarm. For list administration needs (esp. [un]subscribing),
please send a message to <address@hidden> with "help" in the
body of the message.
==================================