예제 #1
0
void SpecialAgentAccumulateDataAction::fire(Data *d) {
//	cerr << "# inside specialAgentAccumulatedata" << endl;
	if (this->agent == NULL)
		throw HiveException("action was not assigned to an agent", "SpecialAgentAccumulateDataAction::fire(Data *d)");
	if (d->getType().compare("tvectordata_double")!=0)
		throw HiveException("wrong data passed to action", "SpecialAgentAccumulateDataAction::fire(Data *d)");

	//	cerr << "INSIDE SPECIALAGENT FIRE" << endl;
	// convert data argument into correct format
	TVectorData<double> *c = (TVectorData<double> *) d;

	// get the databases from the agent ... do we really need the meta database ?! not really
	// one could do without ... i just thought it would be funny to have a meta database in a special agent
	// called fox mulder ... but i guess that we should remove this ...
	Database *meta = ((SpecialAgent *) agent)->getMetaDatabase();
	Database *db   = agent->getDatabase();
	// get some meta information
	IntegerData *num_adds =  (IntegerData* ) meta->getDataItem("number_of_adds");
	IntegerData *num_cells = (IntegerData* ) meta->getDataItem("total_number_of_cells");
	IntegerData *num_time_steps_between_outputs = (IntegerData* ) meta->getDataItem("number_between_outputs");
	IntegerData *counter = (IntegerData* ) meta->getDataItem("counter");

	// accumulate the data
	if (num_adds->getInteger() == 0) {
		// fill data
		TVectorData<double> *conc = (TVectorData<double> *) db->getDataItem("total_conc");
		for (int i=1; i<c->size(); i++)
			conc->at(i-1) = c->at(i);
	} else {
		TVectorData<double> *conc = (TVectorData<double>*) db->getDataItem("total_conc");
		for (int i=1; i<c->size(); i++)
			conc->at(i-1) = conc->at(i-1) + c->at(i);
	}
	num_adds->setInteger(num_adds->getInteger()+1);
	// check whether output has to be generated
	if (num_adds->getInteger() == num_cells->getInteger() &&
		counter->getInteger() == num_time_steps_between_outputs->getInteger()-1) {
	//	cerr << "JETZT BIN ICH HIER DIRIN UND SOLLTE ETWAS AUSGEBEN!!!" << endl;
		TVectorData<double> *conc = (TVectorData<double>*) db->getDataItem("total_conc");
		DoubleData *gt = (DoubleData* ) meta->getDataItem("global_time");
		DoubleData *dt = (DoubleData* ) meta->getDataItem("time_step");
		// output time;
		*this->out << setw(12) << setfill(' ') << gt->getDouble()*num_time_steps_between_outputs->getInteger();
		// update time
		gt->setDouble(gt->getDouble() + dt->getDouble());
		// output conc vector
		for (int i=0; i<conc->size(); i++)
			*this->out << setw(12) << setfill(' ') << conc->at(i)/num_cells->getInteger();
		*this->out << endl;
		// reset num_adds
		num_adds->setInteger(0);
		// reset counter
		counter->setInteger(0);
	} else if (num_adds->getInteger() == num_cells->getInteger()){
	//	cerr << "hier drin" << endl;
		num_adds->setInteger(0);
		counter->setInteger(counter->getInteger()+1);
	}

}
예제 #2
0
void UpdateLigandConcentration::fire (Data *d) {
	// do the correct cast of the data
	DoubleData *conc = (DoubleData *) d;

	DoubleData *ligand = (DoubleData *) agent->getDatabase()->getDataItem("LigandConcentration");
	ligand->setDouble(conc->getDouble());

}
예제 #3
0
void CellNotifyLigandConcToNFsimMessageGenerator::placeMessage(int destID) {
	Message *msg = new Message();
	msg->setAction(ChemotaxisActionIDs::UPDATE_LIGAND_CONCENTRATION_ACTION_ID);
	msg->setDestinationID(destID);

	// provide argument for message
	DoubleData *parameter = new DoubleData("ligand_concentration", 0);

	// get chemicals out of cells database
	//if(this->db->existsDataItem("Chemical")) cout<<"got it chief"<<endl;
	//else cout<<"nopers"<<endl;
	DoubleVectorData *chem = (DoubleVectorData*) this->db->getDataItem("Chemical");
	parameter->setDouble(chem->getDouble(0));
	cerr << "i am the cell and i am sending " << parameter->getDouble() << " as lig. to nfsim" << endl;
	// get the chemoattractant
	msg->setArgument(parameter);

	// place message
	source->placeMessageInOutbox(msg);

}
예제 #4
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);

	}
}