void GasManager::update() { AgentSet refineries(getAgentsOfType(UnitTypes::Terran_Refinery)); if( refineries.empty() && agents.size() ) { // TODO: HACK. Fix me static bool planned = false; if (!planned) { planned = true; Strategizer::instance().buildManager.build(UnitTypes::Terran_Refinery, 1, 1); } } // Get our workers gathering from our refineries AgentSet workers = agents; for(AgentSetIter worker = workers.begin(); worker != workers.end(); ++worker) { Unit& unit = (*worker)->getUnit(); if( !unit.isGatheringGas() && !unit.isConstructing() ) { for(AgentSetIter refinery = refineries.begin(); refinery != refineries.end(); refinery++) { Unit& refineryUnit = (*refinery)->getUnit(); (*worker)->setState(GatherState); (*worker)->setUnitTarget(&refineryUnit); (*worker)->setUnitTypeTarget(UnitTypes::Terran_Refinery); (*worker)->setPositionTarget(refineryUnit.getPosition()); } } } // Update all agents, very important! Manager::update(); }
void Zombie::step() { Patch* p = patchHere<Patch>(); AgentSet<Patch> nghs = patchHere<Patch>()->neighbors<Patch>(); Patch* winningPatch = nghs.maxOneOf(CountHumansOnPatch()); face(winningPatch); move(.5); AgentSet<Human> humans; turtlesHere(humans); if (humans.size() > 0) { Human* human = humans.oneOf(); infect(human); } }
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++; } }
void ZombieObserver::gatherPopulation(std::vector<Patch*>& patchSet, T *io_data) { GridDimensions dim = grid()->dimensions(); int horizontal_run = dim.extents(0); std::vector<Patch*>::iterator iter = patchSet.begin(); int lxmin = minPxcor(); int lymin = minPycor(); while ( iter != patchSet.end() ) { int i = (*iter)->pxCor() - lxmin; int j = (*iter)->pyCor() - lymin; AgentSet<AgentType> set; (*iter)->turtlesOn(set); io_data[i + j * horizontal_run] = int(set.size()); iter++; } }
void ZombieObserver::go() { if (_rank == 0) { Log4CL::instance()->get_logger("root").log(INFO, "TICK BEGINS: " + boost::lexical_cast<string>(RepastProcess::instance()->getScheduleRunner().currentTick())); } synchronize<AgentPackage>(*this, *this, *this, RepastProcess::USE_LAST_OR_USE_CURRENT); AgentSet<Zombie> zombies; get(zombies); zombies.ask(&Zombie::step); AgentId id(0,0,2); Zombie* z = who<Zombie>(id); AgentSet<Human> humans; get(humans); humans.ask(&Human::step); if (_rank == 0) { Log4CL::instance()->get_logger("root").log(INFO, "TICK ENDS: " + boost::lexical_cast<string>(RepastProcess::instance()->getScheduleRunner().currentTick())); } }
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::go() { if (_rank == 0) { Log4CL::instance()->get_logger("root").log(INFO, "TICK BEGINS: " + boost::lexical_cast<string>(RepastProcess::instance()->getScheduleRunner().currentTick())); } synchronize<AgentPackage>(*this, *this, *this, RepastProcess::USE_LAST_OR_USE_CURRENT); AgentSet<Zombie> zombies; AgentSet<Human> humans; if (work_per_rank > OMP_TASK_THRESHOLD) { #pragma omp parallel num_threads(2) { #pragma omp single nowait { #pragma omp task { get(zombies); } #pragma omp task { get(humans); } #pragma omp taskwait zombies.ask(&Zombie::step); AgentId id(0,0,2); Zombie* z = who<Zombie>(id); humans.ask(&Human::step); } } } else { AgentSet<Zombie> zombies; AgentSet<Human> humans; get(zombies); get(humans); zombies.ask(&Zombie::step); AgentId id(0,0,2); Zombie* z = who<Zombie>(id); humans.ask(&Human::step); } if (_rank == 0) { Log4CL::instance()->get_logger("root").log(INFO, "TICK ENDS: " + boost::lexical_cast<string>(RepastProcess::instance()->getScheduleRunner().currentTick())); } }
double operator()(const Patch* patch) const { AgentSet<Human> set; patch->turtlesOn(set); return set.size(); }