📄 batchswarm.m
字号:
#import "BatchSwarm.h"#import "ModelSwarm.h"#import <simtools.h> // ObjectLoader#import <analysis.h> // EZGraph#include <misc.h> // printf@implementation BatchSwarm// createBegin: here we set up the default observation parameters.+ createBegin: aZone { BatchSwarm *obj; // Superclass createBegin to allocate ourselves. obj = [super createBegin: aZone]; // Fill in the relevant parameters. obj->loggingFrequency = 1; obj->experimentDuration = 100; return obj;}- buildObjects{ [super buildObjects]; // IMPORTANT!! // Create the model inside us - no longer create `Zone's explicitly. // The Zone is now created implicitly through the call to create the // `Swarm' inside `self'. modelSwarm = [ModelSwarm create: self]; // In HeatbugObserverSwarm, we'd build some probes and wait for a // user control event (this allows the user to fiddle with the // parameters of the experiment). But since we don't have any graphics, // we load the batch.setup parameter file (which should contain values // for such variables as experimentDuration and loggingFrequency) and // the model.setup parameter file (which contains values for the model // specific variables such as numBugs etc.). [ObjectLoader load: self fromAppDataFileNamed: "batch.setup"]; [ObjectLoader load: modelSwarm fromAppDataFileNamed: "experiment.setup"]; // Now, let the model swarm build its objects. [modelSwarm buildObjects];//printf ("ora inizializzo il file \n"); output = [Output create: [self getZone]]; [output setModel: modelSwarm]; [output prepareFirmOutputFile]; [output prepareHCOutputFile];//printf ("inizializzato il file \n"); 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. [modelSwarm buildActions]; if(loggingFrequency) { // Create an ActionGroup for display. This is pretty minimal in this // case. Note, there's no doTkEvents message - no control panel! displayActions = [ActionGroup create: self]; // Now schedule the update of the unhappyGraph, which will in turn // cause the fileI/O to occur... // [displayActions createActionTo: unhappyGraph message: M(step)]; [displayActions createActionTo: output message: M(writeDatas)]; // the displaySchedule controls how often we write data out. displaySchedule = [Schedule createBegin: self]; [displaySchedule setRepeatInterval: loggingFrequency]; displaySchedule = [displaySchedule createEnd]; [displaySchedule at: 0 createAction: displayActions]; } // We also add in a "stopSchedule", another schedule with an absolute // time event - stop the system at time . stopSchedule = [Schedule create: self]; [stopSchedule at: experimentDuration createActionTo: self message: M(stopRunning)]; return self;} // activateIn: - get the Swarm ready to run.- activateIn: swarmContext { // First, activate ourselves (just pass along the context). [super activateIn: swarmContext]; // We need to activate the model swarm. [modelSwarm activateIn: self]; // Now activate our schedules in ourselves. Note that we just activate // both schedules: the activity library will merge them properly. [stopSchedule activateIn: self]; if (loggingFrequency) [displaySchedule activateIn: self]; // Activate returns the swarm activity - the thing that's ready to run. return [self getActivity];}// the ObserverSwarm had a go method inherited from GUISwarm,// but we have to define our own here. It's pretty simple. There's also// a friendly message printed out here just in case someone is confused// when they run heatbugs and see no graphics.- go { printf ("You typed `coevo -b' or `coevo --batch', so we're runningwithout graphics.\n"); printf ("Coevo is running for %d timesteps.\n",experimentDuration) ; if (loggingFrequency) printf ("It is logging data every %d timesteps to a file.\n", loggingFrequency); [[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.- stopRunning { [getTopLevelActivity() terminate]; // Terminate the simulation. if(loggingFrequency) { // [output drop] ; // Close the output file. [output endSimulation]; } return self;}@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -