void ZombieObserver::setup(Properties& props) { // Observer::setup(props); // No longer need to call this (SimRunner calls _setup, which calls this after all initialization is done) repast::Timer initTimer; initTimer.start(); int humanCount = strToInt(props.getProperty(HUMAN_COUNT_PROP)); humanType = create<Human> (humanCount); int zombieCount = strToInt(props.getProperty(ZOMBIE_COUNT_PROP)); zombieType = create<Zombie> (zombieCount); work_per_rank = humanCount + zombieCount; AgentSet<Human> humans; get(humans); humans.apply(RandomMove(this)); AgentSet<Zombie> zombies; get(zombies); zombies.apply(RandomMove(this)); SVDataSetBuilder svbuilder("./output/data.csv", ",", repast::RepastProcess::instance()->getScheduleRunner().schedule()); InfectionSum* iSum = new InfectionSum(this); svbuilder.addDataSource(repast::createSVDataSource("number_infected", iSum, std::plus<int>())); addDataSet(svbuilder.createDataSet()); #ifndef _WIN32 // no netcdf under windows NCDataSetBuilder builder("./output/data.ncf", RepastProcess::instance()->getScheduleRunner().schedule()); InfectionSum* infectionSum = new InfectionSum(this); builder.addDataSource(repast::createNCDataSource("number_infected", infectionSum, std::plus<int>())); addDataSet(builder.createDataSet()); #endif long double t = initTimer.stop(); std::stringstream ss; ss << t; props.putProperty("init.time", ss.str()); }
void ZombieObserver::placeAgents(std::vector<Patch*> &patchSet, T *io_data) { GridDimensions dim = grid()->dimensions(); int horizontal_run = dim.extents(0); int lxmin = minPxcor(); int lymin = minPycor(); std::vector<repast::relogo::Patch*>::iterator iter = patchSet.begin(); while ( iter != patchSet.end() ) { int i = (*iter)->pxCor() - lxmin; int j = (*iter)->pyCor() - lymin; int count = io_data[i + j*horizontal_run]; AgentSet<AgentType> agentSet; int n = instantiate<AgentType>(count, agentSet); agentSet.apply(MoveToPatch(*iter)); iter++; } }