//Swarm-support mailing list 8-8-1999 //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. //MD> Collection's -beginPermuted: is one way to do this. #import // initSwarm #import // List #import // CreateDrop #import // 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 l; id 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: */