Example #1
0
void ChemoPopComposer::setupAgentHierarchy() {
	// set children of maestro
	if (this->number_of_cells > 0) {
		for (int i=1;i<=this->number_of_cells; i++) {
			Agent *cell = orchestra.at(i);
			maestro->addChild(cell->getAgentId());
			cell->setParent(maestro->getAgentId());
			cell->addSpecialAgent(this->special_agents[0]->getAgentId());
		}
	}
	maestro->addSpecialAgent(this->special_agents[0]->getAgentId());
}
Example #2
0
void BlindAgentNotifyWorldThatNewAgentIsBorn::placeMessage(int destID) {
	//check if I have to give birth or not
	if(birthFlag->getBool())
	{
		birthFlag->setBool(false);

		// if the death simulator determined death, then do not create the birth message
		if(deathFlag->getBool()) return;

		//get the agentfactory, and use it to create an agent
		AgentFactory *af = Registrar::getSystemRegistrar()->getAgentFactory(1);
		Agent *a = af->createAgent();

		// has the same parent
		// NOTE: the parent is the top level agent in the hierarchy of agents,
		// not the agent that gave birth!
		a->setParent(source->getParentId());

		// has the same special agents
		for(unsigned int s=0; s<source->getNumOfSpecialAgents(); s++)
			a->addSpecialAgent(source->getSpecialAgentId(s));

		// needs the same communicator, of course, of course
		a->addCommunicator(source->getCommunicator());

		// set the other properties of agent 'a' based on the source exactly...
		a->copyDatabaseInformationFromExistingAgent(this->source);


		// CLEARLY A HACK!!  CHANGE THIS AT SOME POINT TO DUPLICATE SIMULATORS
		// replace the movement simulator with the correct one
		if (((BoolData*) a->getDatabase()->getDataItem("is_levy"))->getBool()) {
			LevyRunLengthSimulator *levy = new LevyRunLengthSimulator();
			a->replaceSimulator(0,levy);
		} else {
			ExponentialRunLengthSimulator *expo = new ExponentialRunLengthSimulator();
			a->replaceSimulator(0,expo);
		}



		// ANOTHER HACK !! TIME TO NEXT OUTPUT IS OFF WHEN WE GET HERE, SO WE MUST UPDATE
		DoubleData *t  = (DoubleData *) a->getDatabase()->getDataItem("celltime");
		//DoubleData *oi = (DoubleData *) a->getDatabase()->getDataItem("outputinterval");
		//DoubleData *no = (DoubleData*) a->getDatabase()->getDataItem("nextOutputTime");

		DoubleData *dt = (DoubleData *) a->getDatabase()->getDataItem("dt");
		t->setDouble(t->getDouble()-dt->getDouble());


		//register agent a
		Message *specialMssg = new Message();
		specialMssg->setAction(ChemoPopActionIDs::SPECIAL_AGENT_UPDATE_BLIND_AGENT_COUNT_ACTION_ID);
		specialMssg->setArgument(new IntegerData("ChangeInBlindAgentNumber",1));
		Registrar::getSystemRegistrar()->registerNewAgentAndSendMessageToSpecialAgent(a,specialMssg);

		// Now, send the message to the world!!
		Message *msg = new Message();
		msg->setAction(ChemoPopActionIDs::UPDATE_WORLD_BLIND_AGENT_BIRTH_ACTION_ID);
		msg->setDestinationID(destID);

		//pass my agentID (the mother) and the new agent ID (the baby)
		TVectorData<int> *info = new TVectorData<int>("new_cell_info","tvectordata_int");
		info->addElementToEnd(this->source->getAgentId());
		info->addElementToEnd(a->getAgentId()); // get new AgentID !!!
		msg->setArgument(info);

		source->placeMessageInOutbox(msg);

	}
}