//Marcus Daniels, posted July 30, 1999 swarm-support list /* The addAgent:X:Y: method is an example of how you might update such a data structure. The data structure is a Map of Maps of Lists. Something like this might be useful if you had a very sparse space and you wanted to be able to look at the particular agents in a given row. (Below, ignore the code inside USE_HDF5 ifdefs unless you want to be able to store the output to a file. If you do set USE_HDF5, you can look at the output with the `h5dump' program that is installed with the HDF5 distribution. -isClass is defined due to a bug in Swarm 1.4.1.) */ #import // initSwarm #import // Map, List #import // uniformIntRand #import // CreateDrop @interface Agent: CreateDrop { unsigned serialNumber; } - setSerialNumber: (unsigned)serialNumber; @end @implementation Agent - setSerialNumber: (unsigned)theSerialNumber { serialNumber = theSerialNumber; return self; } @end @interface SparseSpace: CreateDrop { id ymap; } + createBegin: aZone; #ifdef USE_HDF5 - updateArchiver: archiver; #endif @end static id createIntMap (id aZone) { return [[[Map createBegin: aZone] setCompareFunction: compareIntegers] createEnd]; } @implementation SparseSpace + createBegin: aZone { SparseSpace *obj = [super createBegin: aZone]; obj->ymap = createIntMap (aZone); return obj; } - (void)addAgent: agent X: (unsigned)x Y: (unsigned)y { id xmap = [ymap at: (id) y]; id agentList; if (!xmap) { xmap = createIntMap ([self getZone]); [ymap at: (id) y insert: xmap]; } agentList = [xmap at: (id) x]; if (!agentList) { agentList = [List create: [self getZone]]; [xmap at: (id) x insert: agentList]; } [agentList addLast: agent]; } #ifdef USE_HDF5 - updateArchiver: archiver { [archiver putDeep: "ymap" object: ymap]; return self; } - (BOOL)isClass { return NO; } #endif @end int main (int argc, const char **argv) { unsigned i; id sparseSpace; initSwarm (argc, argv); sparseSpace = [SparseSpace create: globalZone]; for (i = 0; i < 10; i++) { unsigned x, y; id agent = [[[Agent createBegin: globalZone] setSerialNumber: i] createEnd]; x = [uniformIntRand getIntegerWithMin: 0 withMax: 100000]; y = [uniformIntRand getIntegerWithMin: 0 withMax: 100000]; [sparseSpace addAgent: agent X: x Y: y]; } #ifdef USE_HDF5 [hdf5Archiver registerClient: sparseSpace]; [hdf5Archiver save]; #endif } /* Local Variables: compile-command: "/opt/gnu/bin/gcc -o nestedmaps -g -DUSE_HDF5 -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 nestedmaps.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: */