//Marcus Daniels, June 6, 1999, Swarm-support list //Dynamic scheduling. #import #import #import #import @interface Market: SwarmObject - step; @end @implementation Market - step { printf ("[market] step (%lu)\n", getCurrentTime ()); return self; } @end @interface AgentSwarm: Swarm { id updateSchedule; } + createBegin: aZone; - activateIn: swarmContext; - update; @end @implementation AgentSwarm + createBegin: aZone { AgentSwarm *obj = [super createBegin: aZone]; obj->updateSchedule = [Schedule create: aZone]; return obj; } - activateIn: swarmContext { [super activateIn: swarmContext]; [updateSchedule activateIn: self]; return [self getActivity]; } - update { printf ("[agents] update (%lu)\n", getCurrentTime ()); [updateSchedule at: getCurrentTime () + 1 createActionTo: self message: M(update)]; return self; } @end @interface Controller: Swarm { id marketSchedule; id startUpdateSchedule; } + createBegin: aZone; - createEnd; - activateIn: swarmContext; - startUpdates; @end @implementation Controller + createBegin: aZone { Controller *obj = [super createBegin: aZone]; { id market = [Market create: aZone]; id s = [Schedule createBegin: aZone]; [s setRepeatInterval: 1]; s = [s createEnd]; [s at: 0 createActionTo: market message: M(step)]; obj->marketSchedule = s; } obj->startUpdateSchedule = [Schedule create: aZone]; return obj; } - createEnd { [super createEnd]; [startUpdateSchedule at: 2 createActionTo: self message: M(startUpdates)]; return self; } - startUpdates { id agentSwarm = [AgentSwarm create: self]; printf ("[controller] startUpdates (%lu)\n", getCurrentTime ()); [agentSwarm update]; [agentSwarm activateIn: self]; return self; } - activateIn: swarmContext { [super activateIn: swarmContext]; [startUpdateSchedule activateIn: self]; [marketSchedule activateIn: self]; return [self getActivity]; } - run { [self activateIn: nil]; [[self getActivity] run]; return self; } @end int main (int argc, const char **argv) { initSwarmBatch (argc, argv); [[Controller create: globalZone] run]; return 0; } /* Local Variables: compile-command: "/opt/gnu/bin/gcc -o s3 -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 s3.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: */