// em application. #import "emBatchSwarm.h" static unsigned numJobs = 28; @implementation EmBatchSwarm +createBegin: (id) aZone { EmBatchSwarm * obj; // Superclass createBegin to allocate ourselves. obj = [super createBegin: aZone]; // Fill in the relevant parameters. obj->graphFrequency = 1; obj->experimentDuration = 5000; obj->typeModel = 1; return obj; } -setFileName: (char*) theFile Dir: (char*) theDir { fileExt = theFile; dirExt = theDir; if (dirExt!=NULL) dirExt = strcat(dirExt,"/"); if (fileExt==NULL) fileExt = "noname"; return self; } -buildObjects { id modelZone; // zone for model. char outDir[100]; char outFile[100]; int i; [super buildObjects]; modelZone = [Zone create: [self getZone]]; emModelSwarm = [EmModelSwarm create: modelZone]; [probeDisplayManager createProbeDisplayFor: self]; [probeDisplayManager createProbeDisplayFor: emModelSwarm]; [super buildObjects]; // create a zone for the model, create the model there. modelZone = [Zone create: [self getZone]]; emModelSwarm = [EmModelSwarm create: modelZone]; // Load in the set up files. [ObjectLoader load: self fromFileNamed: "D:/Emigrate.v18/setup/batch.setup"] ; [ObjectLoader load: emModelSwarm fromFileNamed: "setup/experiment.setup"] ; // Now, let the model swarm build its objects. [emModelSwarm buildObjects: typeModel]; // graphFrequency of 0 requires no result logging. if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); numSites = [[emModelSwarm getEnvironment] getNumSites]; observedWorkers = [emModelSwarm getWorkerList]; if(graphFrequency){ // Graph of cluster width. theGraph = [EZGraph createBegin: [self getZone]]; [theGraph setGraphics: 0] ; [theGraph setFileOutput: 1] ; theGraph = [theGraph createEnd] ; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); for (i=0;i<[emModelSwarm getNumAnts];i++) { if (fileExt!=NULL) sprintf(outFile, "%sind%d.%s",outDir,i,fileExt); else sprintf(outFile,"%sind%d.%s",outDir,i,fileExt); indFile[i] = fopen(outFile, "w"); /*fprintf(indFile[i],"Time Step, Worker ID, Job, Current Site, Former \\ Site, Carrying Item, Journey Time, Time Travelling, New Nest, Leader, Nest \\ Count, Threshold\n"); */ } timeStep=0; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sassess0.%s",outDir,fileExt); else sprintf(outFile, "%sassess0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAssess0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%satsite0.%s",outDir,fileExt); else sprintf(outFile, "%satsite0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAtsite0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%standem0.%s",outDir,fileExt); else sprintf(outFile, "%standem0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTandem0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%stransp0.%s",outDir,fileExt); else sprintf(outFile, "%stransp0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTransport0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sfollow0.%s",outDir,fileExt); else sprintf(outFile, "%sfollow0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getFollow0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssearch0.%s",outDir,fileExt); else sprintf(outFile, "%ssearch0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSearch0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssleep0.%s",outDir,fileExt); else sprintf(outFile, "%ssleep0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSleep0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sassess1.%s",outDir,fileExt); else sprintf(outFile, "%sassess1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAssess1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%satsite1.%s",outDir,fileExt); else sprintf(outFile, "%satsite1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAtsite1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%standem1.%s",outDir,fileExt); else sprintf(outFile, "%standem1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTandem1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%stransp1.%s",outDir,fileExt); else sprintf(outFile, "%stransp1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTransport1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sfollow1.%s",outDir,fileExt); else sprintf(outFile, "%sfollow1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getFollow1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssearch1.%s",outDir,fileExt); else sprintf(outFile, "%ssearch1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSearch1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssleep1.%s",outDir,fileExt); else sprintf(outFile, "%ssleep1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSleep1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sassess2.%s",outDir,fileExt); else sprintf(outFile, "%sassess2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAssess2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%satsite2.%s",outDir,fileExt); else sprintf(outFile, "%satsite2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getAtsite2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%standem2.%s",outDir,fileExt); else sprintf(outFile, "%standem2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTandem2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%stransp2.%s",outDir,fileExt); else sprintf(outFile, "%stransp2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getTransport2)]; if (fileExt!=NULL) sprintf(outFile, "%sfollow2.%s",outDir,fileExt); else sprintf(outFile, "%sfollow2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getFollow2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssearch2.%s",outDir,fileExt); else sprintf(outFile, "%ssearch2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSearch2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%ssleep2.%s",outDir,fileExt); else sprintf(outFile, "%ssleep2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getSleep2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sbrood0.%s",outDir,fileExt); else sprintf(outFile, "%sbrood0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getBrood0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%squeen0.%s",outDir,fileExt); else sprintf(outFile, "%squeen0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getQueen0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sworker0.%s",outDir,fileExt); else sprintf(outFile, "%sworker0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getWorker0)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sbrood1.%s",outDir,fileExt); else sprintf(outFile, "%sbrood1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getBrood1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%squeen1.%s",outDir,fileExt); else sprintf(outFile, "%squeen1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getQueen1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sworker1.%s",outDir,fileExt); else sprintf(outFile, "%sworker1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getWorker1)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sbrood2.%s",outDir,fileExt); else sprintf(outFile, "%sbrood2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getBrood2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%squeen2.%s",outDir,fileExt); else sprintf(outFile, "%squeen2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getQueen2)]; if (dirExt!=NULL) sprintf(outDir,"output/%s",dirExt); else sprintf(outDir,"output/"); if (fileExt!=NULL) sprintf(outFile, "%sworker2.%s",outDir,fileExt); else sprintf(outFile, "%sworker2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getWorker2)]; if (fileExt!=NULL) sprintf(outFile, "%scount0.%s",outDir,fileExt); else sprintf(outFile, "%scount0.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getNestCount0)]; if (fileExt!=NULL) sprintf(outFile, "%scount1.%s",outDir,fileExt); else sprintf(outFile, "%scount1.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getNestCount1)]; if (fileExt!=NULL) sprintf(outFile, "%scount2.%s",outDir,fileExt); else sprintf(outFile, "%scount2.",outDir); [theGraph createSequence: outFile withFeedFrom: self andSelector: M(getNestCount2)]; } return self; } // Create the actions necessary for the simulation. This is where // the schedule is built (but not run!) -buildActions { [super buildActions]; // First, let our model swarm build its own schedule. [emModelSwarm buildActions]; if(graphFrequency){ // Create an ActionGroup for display. displayActions = [ActionGroup create: [self getZone]]; // Update of the Graphs [displayActions createActionTo: self message: M(updateGraphs)]; [displayActions createActionTo: theGraph message: M(step)]; [displayActions createActionTo: self message: M(shouldStop)]; // the displaySchedule controls how often we write data out. displaySchedule = [Schedule createBegin: [self getZone]]; [displaySchedule setRepeatInterval: graphFrequency]; displaySchedule = [displaySchedule createEnd]; [displaySchedule at: 0 createAction: displayActions]; } // Stop the system at time "stopSchedule" stopSchedule = [Schedule create: [self getZone]]; [stopSchedule at: experimentDuration createActionTo: self message: M(stopRunning)]; return self; } // activateIn: - get the Swarm ready to run. -activateIn: (id) swarmContext { // First, activate ourselves (just pass along the context). [super activateIn: swarmContext]; // We need to activate the model swarm. [emModelSwarm activateIn: self]; // Now activate our schedules in ourselves. Note that we just activate // both schedules: the em library will merge them properly. [stopSchedule activateIn: self]; if(graphFrequency) [displaySchedule activateIn: self]; // Activate returns the swarm em - the thing that's ready to run. return [self getSwarmActivity]; } -go { printf( "****************************\n"); printf("%s",fileExt); [[self getActivity] run]; return [[self getActivity] getStatus]; } // And the termination method. When this fires we just terminate everything // that's running and close our output file(s) by dropping the EZGraph which // "owns" the sequence(s) we are logging. -shouldStop { //if ([self getActive]==0) [self stopRunning]; return self; } -stopRunning { [getTopLevelActivity() terminate]; // Terminate the simulation. if(graphFrequency) [theGraph drop] ; // Close the output file. return self; } -updateGraphs{ // Go through the list of workers calculating statistics. id index, aWorker, aLeader; int job,site,former; timeStep++; for(job=0;job