Beispiel #1
0
Agent* BugFactory::createAgent() {
	// create agent and get his database
	Agent *bond  = new Agent();
	Database *db = bond->getDatabase();

	// --- fill database with data ---
	// time of bug
	DoubleData *bugtime = new DoubleData("bug_time",0.0);
	db->addData(bugtime);

	// dt
	DoubleData *dt = new DoubleData("dt",1.0);
	db->addData(dt);

	// PythonProgram
	StringData *pythonProgram = new StringData("pythonProgram",this->program);
	db->addData(pythonProgram);


	// temperature which the agent prefers to have
	DoubleData *pt = new DoubleData("preferred_temperature",3.0);
	db->addData(pt);

	// output interval
	DoubleData *oi = new DoubleData("output_interval", this->output_interval);
	db->addData(oi);

	// next output time
	DoubleData *noti = new DoubleData("next_output_time", 0);
	db->addData(noti);

	// vector in which the agent stores the temperatures in its local vivicinity
	TVectorData<DoubleData> *vec = new TVectorData<DoubleData> ("local_temperature_around_me", "tvector_doubledata");
	vec->reserveSize(5);
	db->addData(vec);

	// rate with which the bug produces heat
	DoubleData *heat_rate = new DoubleData("heat_rate",1.0);
	db->addData(heat_rate);

	// direction in which the bug desires to move
	IntegerData *move_direction = new IntegerData("move_direction", 0);
	db->addData(move_direction);

	/// finally add actions, simulators, and message generators to the bug
	this->addActionsToAgentsActionSet(bond);
	this->addSimulatorToAgent(bond);
	this->addMessageGeneratorsToAgent(bond);

	// return agent
	return bond;
}
Beispiel #2
0
Creator::Creator()
{
	//composing the world hierarchy(i havent figured out the composer yet)
	WorldFactory *WF = new WorldFactory();
	Agent *W = WF->createAgent();
	BacteriumFactory *BF = new BacteriumFactory();
	Agent *B = BF->createAgent();
	W->addChild(B->getAgentId());
	B->setParent(W->getAgentId());
	//dvorak could do better, I suppose

	//initializing the position, ligand_level,ligand and phosphorylation level
	srand(time(NULL));
	int position = rand()%3;
	int ligand_level = rand()%3;
	double phosph = 0;
	double ligand;
	switch (ligand_level) {
		case 0: ligand = 10; break;
		case 1: ligand = 1000; break;
		case 2: ligand = 100000; break;
	}
	cout << endl<<endl<<endl;
	cout << "Bacterium is in box "<<position<<endl;
	cout << "The ligand level is "<<ligand_level<<endl;
	cout << "The ligand conc is "<<ligand<<endl;
	cout << "The phosph conc is "<<phosph <<endl;

	//Initializing the Databases
	IntegerData *data1 = new IntegerData("Ligand Level",ligand_level);
	DoubleData *data2 = new DoubleData("Phosph Conc", phosph);
	W->getDatabase()->addData(data1->getName(),data1);
	W->getDatabase()->addData(data2->getName(),data2);
	DoubleData *data3 = new DoubleData("Ligand Conc",ligand);
	DoubleData *data4 = new DoubleData("Phosph Conc", phosph);
	B->getDatabase()->addData(data3->getName(),data3);
	B->getDatabase()->addData(data4->getName(),data4);
}
Beispiel #3
0
void SimpleCellDefaultParallelComposer::outputNow(double currentTime)
{
	// output format:
	// cellNumber, time, cellState, CheYp, motState[0], x,y,z


	//Create all of the SimpleCells
	for(unsigned int k=1; k<orchestra.size(); k++) {
		Agent *cellAgent = orchestra.at(k);
		Database *db = cellAgent->getDatabase();

		// cellNumber
		double kDouble = (double)k;
		outputFile.write((char *)&kDouble,sizeof(double));

		// time
		outputFile.write((char *)&currentTime,sizeof(double));


		//cell state
		double cellState = (double)((IntegerData *)db->getDataItem("CurrentCellState"))->getInteger();
		outputFile.write((char *)&cellState, sizeof(double));


		//cheYp
		double ypConc = ((DoubleVectorData *)db->getDataItem("CheYp"))->getDouble(0);
		outputFile.write((char *)&ypConc, sizeof(double));

		//cheYp
		double motState = (double)((IntVectorData *)db->getDataItem("MotorStates"))->getInt(0);
		outputFile.write((char *)&motState, sizeof(double));

		DoubleVectorData *curPos = ((DoubleVectorData *)db->getDataItem("Position"));
		double x = curPos->getDouble(1);
		double y = curPos->getDouble(2);
		double z = curPos->getDouble(3);

		outputFile.write((char *)&x, sizeof(double));
		outputFile.write((char *)&y, sizeof(double));
		outputFile.write((char *)&z, sizeof(double));


		double lig = ((DoubleVectorData *)db->getDataItem("Chemical"))->getDouble(0);
		outputFile.write((char *)&lig, sizeof(double));


	}

}
Beispiel #4
0
Agent *UniverseFactory::createAgent() {
	Agent *a = new Agent();
	GenerateUniverseMessageToWorld* msgGen = new GenerateUniverseMessageToWorld(a);
	a->addMessageGenerator(msgGen);
	GenerateUniverseFluxMessageToWorld* msgGenTwo = new GenerateUniverseFluxMessageToWorld(a);
	a->addMessageGenerator(msgGenTwo);
	UniverseDatabase* universityDB = new UniverseDatabase();
	a->getDatabase()->addData("univ", universityDB);
	addSimulatorToAgent(a);	
	SyncWorldToUniverse* universeAction = new SyncWorldToUniverse();
	a->addAction(universeAction);
	RecvFluxMessageFromWorld* fluxAction = new RecvFluxMessageFromWorld();
	a->addAction(fluxAction);
	return a;
};
Beispiel #5
0
Agent* OutputAgentFactory::createAgent() {
	// create new output agent
	Agent *shakespeare  = new Agent();
	Database *db        = shakespeare->getDatabase();

	// add number of bugs and length of output interval to shakespeare's database
	IntegerData *nb = new IntegerData("number_bugs",number_bugs);
	db->addData(nb);

	DoubleData *oi = new DoubleData("output_interval", output_interval);
	db->addData(oi);

	// we just need to add the actions to the agents.
	// the output-agent does not possess any message generators or simulators.
	this->addActionsToAgentsActionSet(shakespeare);

	return shakespeare;
}
Beispiel #6
0
Agent* WorldAgentFactoryI::createAgent() {
	// open up an inputstream
	ifstream input(this->inputname.c_str());

	// create world agent and get his database
	Agent *world = new Agent();
	Hive::Database *db = world->getDatabase();

	// add the time counter to the world
	DoubleData *localworldtime = new DoubleData("localworldtime",0.0);
	db->addData(localworldtime->getName(),localworldtime);

	DoubleData *eqTime         = new DoubleData("eqTime", 0);
	db->addData(eqTime->getName(), eqTime);

	DoubleData *dt = new DoubleData("dt", 1.0);
	db->addData(dt);

	IntegerData *numberofcells = new IntegerData("numberofcells", this->numbercells);
	db->addData(numberofcells->getName(), numberofcells);

	// data structure for knowing which cell is stored at which index in the various vectors
	// that the world agent has
	// maps agent_id (key) on to vector index (value)
	MapIntIntData *local_index_map = new MapIntIntData("local_index_map");
	for (int i=0; i<this->numbercells; i++) {
		//assume agent_ids start at 1 (because the world is agent zero)
		local_index_map->insert(i+1,i);
		//cout<<"adding to local index map: ["<<i+1<<"]: => "<<i<<endl;
	}
	db->addData(local_index_map->getName(),local_index_map);

	// maps vector_index (key) onto agent_id
	// this is needed for outputing the positions of the cells
	MapIntIntData *index_agentid_map = new MapIntIntData("indexagentidmap");
	for (int i=0; i<this->numbercells; i++) {
		// again, agent_ids = i+1
		index_agentid_map->insert(i,i+1);
	}
	db->addData(index_agentid_map->getName(), index_agentid_map);

	// ----------------- DATA STRUCTURES FOR CELL MOVEMENT ------------------------------
	// add data structure to the world in which it can store the cell positions
	TVectorData<TVectorData<double>* > *cell_positions = new TVectorData<TVectorData<double>* > ("cellpositions","tvectordata_double_matrix");
	cell_positions->reserveSize(this->numbercells);

	// add data_structure for direction and up vector of the individual cells
	TVectorData<TVectorData<double>* > *cell_dir_vecs = new TVectorData<TVectorData<double>* > ("celldirvecs", "tvectordata_doublematrix");
	cell_dir_vecs->reserveSize(this->numbercells);

	TVectorData<TVectorData<double>* > *cell_up_vecs  = new TVectorData<TVectorData<double>* > ("cellupvecs", "tvectordata_doublematrix");
	cell_up_vecs->reserveSize(this->numbercells);

	for (int i=0; i<this->numbercells;i++) {
		(*cell_positions)[i] = new TVectorData<double> ("position", "tvectordata_double");
		(*cell_positions)[i]->reserveSize(3);
		(*cell_dir_vecs)[i]  = new TVectorData<double> ("direction", "tvectordata_double");
		(*cell_dir_vecs)[i]->reserveSize(3);
		/// this needs to be a unit-vector.
		cell_dir_vecs->at(i)->at(0) = 1.; cell_dir_vecs->at(i)->at(1) = 0.; cell_dir_vecs->at(i)->at(2) = 0;
		(*cell_up_vecs)[i]   = new TVectorData<double> ("up", "tvectordata_double");
		(*cell_up_vecs)[i]->reserveSize(3);
		cell_up_vecs->at(i)->at(0) = 0; cell_up_vecs->at(i)->at(1) = 1; cell_up_vecs->at(i)->at(2) = 0;
	}
	db->addData(cell_positions->getName(), cell_positions);
	db->addData(cell_dir_vecs->getName(), cell_dir_vecs);
	db->addData(cell_up_vecs->getName(), cell_up_vecs);

	// cellspeeds
	TVectorData<double> *cellspeeds = new TVectorData<double>("cellspeeds", "tvector_double");
	cellspeeds->reserveSize(this->numbercells);
	for (int i=0; i<this->numbercells; i++)
		cellspeeds->at(i) = 20.0;
	db->addData(cellspeeds->getName(), cellspeeds);

	// DATA STRUCTURE FOR METABOLISM
	// data structure for storing how much a cell wishes to consume
	// we will also use it to store the actual concentration that gets consumed by the cells
	TVectorData<double> *desired_cell_consumption = new TVectorData<double>("desired_cell_consumption", "tvectordata_double");
	desired_cell_consumption->reserveSize(this->numbercells);
	db->addData(desired_cell_consumption->getName(), desired_cell_consumption);

	// DATA FOR OUTPUT
	DoubleData *output_interval = new DoubleData("output_interval",this->output_interval);
	db->addData(output_interval->getName(), output_interval);

	// SPECIFIC DATA FOR EITHER ECOLIs OR BLIND AGENTS
	// add data structures to the world that are unique to the E.coli model
	if(!this->isBlindAgent) {
		cerr << "# cells are of type: ECOLI" << endl;
		// add data structure to the world in which it can store the swimming states of all the cells
		TVectorData<int> *swimming_states = new TVectorData<int>("swimmingstates", "tvectordata_int");
		swimming_states->reserveSize(this->numbercells);
		db->addData(swimming_states->getName(), swimming_states);

		// add data structure to the world in whihc it stores the old swimming states of all the cells
		TVectorData<int> *last_swimming_states = new TVectorData<int>("lastswimmingstates", "tvectordata_int");
		last_swimming_states->reserveSize(this->numbercells);
		db->addData(last_swimming_states->getName(), last_swimming_states);

		// rotational diffusion constant of the cells
		DoubleData *rotdiffconst = new DoubleData("rotational_diffusion_constant",0.062);
		db->addData(rotdiffconst->getName(), rotdiffconst);
	} else { // add data object needed by the blind searcher, which is the
		cerr << "# cells are of type: BLIND" << endl;
		// next angle to use during turns.  Default to zero and must be overwritten by the agent
		TVectorData<double> *nextTurnAngles = new TVectorData<double>("cellnextturnangle", "tvector_double");
		nextTurnAngles->reserveSize(this->numbercells);
		for (int i=0; i<this->numbercells; i++)
			nextTurnAngles->at(i) = 0;
		db->addData(nextTurnAngles->getName(), nextTurnAngles);
	}


	// <------ DATA FOR ENVIRONMENT --------------
	// we read the environment from a file.
	BoolData *isGridEnv = new BoolData("is_grid_environment",false);
	db->addData(isGridEnv);

	// do the parsing of the system file. we can extend this later on if more information is needed.
	// not optimal, arose from our need to quickly change environements without having to change the code
	if(!input.is_open()) {
		cerr<<"did not open world file. quitting.";
		exit(1);
	}
	input.seekg(0,ios_base::beg);
	string line = "";
	istringstream iss;
	string environ_type;
	string cellpos_init_type;
	CellPositionInitialiser cpi;
	/// we need a vector of environments as we want to have multiple pointsources
	TVectorData<MathFunctionData* > *environments = new TVectorData<MathFunctionData*> ("environments", "tvector_mathfunctiondata");
	db->addData(environments);
	/// we need a vector of birth-times for the environments
	TVectorData<double> *birthtimes = new TVectorData<double> ("birthtimes_of_environments", "tvector_double");
	db->addData(birthtimes);

	/// we need the parameters for the simulator that randomly drops new pointsources into the environment.
	while (getline(input,line)) {
		if (line == "RANDOM DROP SIMULATOR") {   // reading parameters for the environment simulator
			// first we need to add the position of the ...
			this->hasEnvironmentSimulator = true;
			TVectorData<double> *lastposition = new TVectorData<double> ("last_pointsource_position","tvector_double");
			lastposition->reserveSize(3);
			lastposition->at(0) = 0; lastposition->at(1) = 0; lastposition->at(2) = 0;
			db->addData(lastposition);
			// add time of next drop event to environment.
			DoubleData *tone = new DoubleData("environment_time_of_next_drop", 0);
			db->addData(tone);
			while (getline(input, line) && line != "END") {
				if (line.substr(0,1)!="#" && line != "") {
					iss.clear();
					iss.str(line);
					/// parameters are read as follows from the file:
					/// timpe_parameter, space_parameter, mean_of_pointsource_initial_dist, sigma_of_....
					/// diff
					double	tp, sp, mi, sigma, diff;
					iss >> tp; iss >> sp; iss >> mi; iss >> sigma; iss >> diff;
					DoubleData *d1 = new DoubleData("environment_time_parameter",tp);
					db->addData(d1);
					DoubleData *d2 = new DoubleData("environment_space_parameter", sp);
					db->addData(d2);
					DoubleData *d3 = new DoubleData("mean_of_pointsource_initial_distribution", mi);
					db->addData(d3);
					DoubleData *d4 = new DoubleData("sigma_of_pointsource_initial_distribution", sigma);
					db->addData(d4);
					DoubleData *d5 = new DoubleData("diffusion_coeff_ligand", diff);
					db->addData(d5);
				}
			}
		}else if (line == "TYPE") {
Beispiel #7
0
Agent* WorldAgentFactoryII::createAgent() {
	cerr << "# creating worldagent" << endl;
	// create world agent and get his database
	Agent *world = new Agent();
	Hive::Database *db = world->getDatabase();

	/// this value will be overwritten by the parser if we read cell positions
	IntegerData *numberofcells = new IntegerData("numberofcells", this->numbercells);
	db->addData(numberofcells->getName(), numberofcells);

	// DATA FOR OUTPUT ... this is passed via the command line
	DoubleData *output_interval = new DoubleData("output_interval",this->output_interval);
	db->addData(output_interval->getName(), output_interval);

	// set up agent by using a parser
	// open the relevant inputstream
	ifstream input(this->inputname.c_str());
	// set up parser;  GWA = Garrit's World Agent
	GWAParser gwap;
	cerr << "# starting to invoke GWAParser for parsing the environment" << endl;
	cerr << "# reading from file:    '" << this->inputname <<"'"<< endl;
	gwap.setInputfile(input);
	gwap.setAgent(world);
	gwap.parse();
	this->equilibration_time = gwap.getEquilibrationTime();
	cerr << "# done parsing input file" << endl;

	// get some information from the database
	// first the cell number such that the registrar can be initialised correctly
	this->numbercells = ((IntegerData*) db->getDataItem("numberofcells"))->getInteger();
	// set the timestep for initialising the simulators
	this->dt = ((DoubleData*) db->getDataItem("dt"))->getDouble();

	// ------------------ Data Structures for the registrar --------------------------------
	// data structure for knowing which cell is stored at which index in the various vectors
	// that the world agent has
	// maps agent_id (key) on to vector index (value)
	MapIntIntData *local_index_map = new MapIntIntData("local_index_map");
	for (int i=0; i<this->numbercells; i++) {
		//assume agent_ids start at 1 (because the world is agent zero)
		local_index_map->insert(i+1,i);
	}
	db->addData(local_index_map->getName(),local_index_map);

	// maps vector_index (key) onto agent_id
	// this is needed for outputing the positions of the cells
	MapIntIntData *index_agentid_map = new MapIntIntData("indexagentidmap");
	for (int i=0; i<this->numbercells; i++) {
		// again, agent_ids = i+1
		index_agentid_map->insert(i,i+1);
	}
	db->addData(index_agentid_map->getName(), index_agentid_map);


	/// now we add the remaining things to the world agent
	/// add simulators to agent
	this->addSimulatorToAgent(world);
	cerr << "# added simulators to the world agent" << endl;

	/// add actions to agents action set
	this->addActionsToAgentsActionSet(world);
	cerr << "# added actions to the world agent" << endl;

	/// add message generators to action set
	this->addMessageGeneratorsToAgent(world);
	cerr << "# added message generators to the world agent" << endl;

	cerr<<"# done creating world"<<endl;
	return world;
}
Beispiel #8
0
Agent* WorldAgentFactoryI::createAgent() {
	// open up an inputstream
//	cerr << this->inputname << endl;
	ifstream input(this->inputname.c_str());

	// create world agent and get his database
	Agent *world = new Agent();
	Hive::Database *db = world->getDatabase();

	// add the time counter to the world
	DoubleData *localworldtime = new DoubleData("localworldtime",0.0);
	db->addData(localworldtime->getName(),localworldtime);

	DoubleData *eqTime         = new DoubleData("eqTime", 0);
	db->addData(eqTime->getName(), eqTime);

	DoubleData *dt = new DoubleData("dt", 0);
	db->addData(dt);

	IntegerData *numberofcells = new IntegerData("numberofcells", this->numbercells);
	db->addData(numberofcells->getName(), numberofcells);

	// data structure for knowing which cell is stored at which index in the various vectors
	// that the world agent has
	// maps agent_id (key) on to vector index (value)
	MapIntIntData *local_index_map = new MapIntIntData("local_index_map");
	for (int i=0; i<this->numbercells; i++) {
		//assume agent_ids start at 1 (because the world is agent zero)
		local_index_map->insert(i+1,i);

		//cout<<"adding to local index map: ["<<i+1<<"]: => "<<i<<endl;
	}
	db->addData(local_index_map->getName(),local_index_map);

	// maps vector_index (key) onto agent_id
	// this is needed for outputing the positions of the cells
	MapIntIntData *index_agentid_map = new MapIntIntData("indexagentidmap");
	for (int i=0; i<this->numbercells; i++) {
		// again, agent_ids = i+1
		index_agentid_map->insert(i,i+1);
	}
	db->addData(index_agentid_map->getName(), index_agentid_map);

	// add data structure to the world in which it can store the cell positions
	TVectorData<TVectorData<double>* > *cell_positions = new TVectorData<TVectorData<double>* > ("cellpositions","tvectordata_double_matrix");
	cell_positions->reserveSize(this->numbercells);

	// add data_structure for direction and up vector of the individual cells
	TVectorData<TVectorData<double>* > *cell_dir_vecs = new TVectorData<TVectorData<double>* > ("celldirvecs", "tvectordata_doublematrix");
	cell_dir_vecs->reserveSize(this->numbercells);

	TVectorData<TVectorData<double>* > *cell_up_vecs  = new TVectorData<TVectorData<double>* > ("cellupvecs", "tvectordata_doublematrix");
	cell_up_vecs->reserveSize(this->numbercells);

	for (int i=0; i<this->numbercells;i++) {
		(*cell_positions)[i] = new TVectorData<double> ("position", "tvectordata_double");
		(*cell_positions)[i]->reserveSize(3);
		(*cell_dir_vecs)[i]  = new TVectorData<double> ("direction", "tvectordata_double");
		(*cell_dir_vecs)[i]->reserveSize(3);
		/// this needs to be a unit-vector.
		cell_dir_vecs->at(i)->at(0) = 1.; cell_dir_vecs->at(i)->at(1) = 0.; cell_dir_vecs->at(i)->at(2) = 0;
		(*cell_up_vecs)[i]   = new TVectorData<double> ("up", "tvectordata_double");
		(*cell_up_vecs)[i]->reserveSize(3);
		cell_up_vecs->at(i)->at(0) = 0; cell_up_vecs->at(i)->at(1) = 1; cell_up_vecs->at(i)->at(2) = 0;
	}
	db->addData(cell_positions->getName(), cell_positions);
	db->addData(cell_dir_vecs->getName(), cell_dir_vecs);
	db->addData(cell_up_vecs->getName(), cell_up_vecs);

	// data structure storing how much a cell wishes to consume
	// we will also use it to store the actual concentration that gets consumed by the cells
	TVectorData<double> *desired_cell_consumption = new TVectorData<double>("desired_cell_consumption", "tvectordata_double");
	desired_cell_consumption->reserveSize(this->numbercells);
	db->addData(desired_cell_consumption->getName(), desired_cell_consumption);

	// time step for movement of the cells
	DoubleData *movement_dt = new DoubleData("movement_dt",1.);
	db->addData(movement_dt->getName(), movement_dt);

	/// speed of cells (is that the same for all the cells?)
	//	DoubleData *cellspeed = new DoubleData("cellspeed",0.1);
	//	db->addData(cellspeed->getName(), cellspeed);

	TVectorData<double> *cellspeeds = new TVectorData<double>("cellspeeds", "tvector_double");
	cellspeeds->reserveSize(this->numbercells);
	for (int i=0; i<this->numbercells; i++)
		cellspeeds->at(i) = 20.0;
	db->addData(cellspeeds->getName(), cellspeeds);

	TVectorData<int> *cell_wants_to_move = new TVectorData<int>("cell_wants_to_move", "tvector_bool");
	cell_wants_to_move->reserveSize(this->numbercells);
	for (int i=0; i<this->numbercells; i++)
		cell_wants_to_move->at(i) = (int)true;
	db->addData(cell_wants_to_move->getName(), cell_wants_to_move);

	DoubleData *output_interval = new DoubleData("output_interval",this->output_interval);
	db->addData(output_interval->getName(), output_interval);


	BoolData *isGridEnv = new BoolData("is_grid_environment",false);
	db->addData(isGridEnv);



	if(!this->isBlindAgent) {
		cerr << "# cells are of type: ECOLI" << endl;
		// add data structures to the world that are unique to the E.coli model

		// add data structure to the world in which it can store the swimming states of all the cells
		TVectorData<int> *swimming_states = new TVectorData<int>("swimmingstates", "tvectordata_int");
		swimming_states->reserveSize(this->numbercells);
		db->addData(swimming_states->getName(), swimming_states);

		// add data structure to the world in whihc it stores the old swimming states of all the cells
		TVectorData<int> *last_swimming_states = new TVectorData<int>("lastswimmingstates", "tvectordata_int");
		last_swimming_states->reserveSize(this->numbercells);
		db->addData(last_swimming_states->getName(), last_swimming_states);

		// rotational diffusion constant of the cells
		DoubleData *rotdiffconst = new DoubleData("rotational_diffusion_constant",0.062);
		db->addData(rotdiffconst->getName(), rotdiffconst);
	} else {
		cerr << "# cells are of type: BLIND" << endl;

		// add data object needed by the blind searcher, which is the
		// next angle to use during turns.  Default to zero and must be
		// overridden by the agent
		TVectorData<double> *nextTurnAngles = new TVectorData<double>("cellnextturnangle", "tvector_double");
		nextTurnAngles->reserveSize(this->numbercells);
		for (int i=0; i<this->numbercells; i++)
			nextTurnAngles->at(i) = 0;
		db->addData(nextTurnAngles->getName(), nextTurnAngles);
	}



	// do the parsing of the system file. we can extend this later on if more information is needed.

	if(!input.is_open()) {
		cerr<<"did not open world file. quitting.";
		exit(1);
	}

	input.seekg(0,ios_base::beg);
	string line = "";
	istringstream iss;
	string environ_type;
	string cellpos_init_type;
	CellPositionInitialiser cpi;
	while (getline(input,line)) {
		if (line == "TYPE") {
			while (getline(input,line) && line != "END") {
				if (line.substr(0,1)!="#" && line != "") {
					iss.clear();
					iss.str(line);
					iss >> environ_type;
					if (environ_type == "linear") {
						cerr << "# creating linear environment" << endl;
						OneDLinearMathFunctionData *environ1 = new OneDLinearMathFunctionData("environment");
						double s, yi;
						iss >> s; iss >> yi;
						environ1->setSlope(s);
						environ1->setYIntercept(yi);
						db->addData(environ1->getName(), environ1);
					} else if (environ_type == "exponential") {
						cerr << "# creating exponential environment" << endl;
						OneDExponentialMathFunctionData *environ2 = new OneDExponentialMathFunctionData("environment");
						double o, p;
						iss >> o, iss >> p;
						environ2->setOffset(o);
						environ2->setParameter(p);
						db->addData(environ2->getName(), environ2);
					} else if (environ_type == "pointsource") {
Beispiel #9
0
Agent* WorldFactory::createAgent() {
	// create the agent and get its datbase

	Agent *bond = new Agent();
	Database *db = bond->getDatabase();
	Py_Initialize();
	// create the data items that are needed for this agent and add
	// the data items to the agent's database

	// clock
	DoubleData *celltime = new DoubleData("worldtime", 0.0);
	db->addData(celltime);

	// time interval
	DoubleData *dt = new DoubleData("dt",0.1);
	db->addData(dt);

	// output interval
	DoubleData *oi = new DoubleData("output_interval", this->output_interval);
	db->addData(oi);

	DoubleData *noti = new DoubleData("next_output_time", this->output_interval);
	db->addData(noti);

	// diffusion coefficient
	DoubleData *diff = new DoubleData("diffusion_coeff", 0.25);
	db->addData(diff);

	// dissipation rate
	DoubleData *dis = new DoubleData("dissipation_rate", 0.1);
	db->addData(dis);

	// size of the grids in the system. all grids will be quadratic.
	int grid_size = 100;
	IntegerData *gs = new IntegerData("grid_size", grid_size);
	db->addData(gs);

	// number_bugs
	IntegerData *bn = new IntegerData("number_bugs", number_bugs);
	db->addData(bn);

	int i_number_of_elements = 4;
	IntegerData *number_of_elements = new IntegerData("number_of_elements",i_number_of_elements);
	db->addData(number_of_elements);

	// elemetNames
	TVectorData<StringData> *element_names = new TVectorData<StringData>("element_names","tvectordata_string");
	element_names->reserveSize(4);


	string elements[] = {"A", "B", "C", "D"};
	float coeffs[]={0.1,0.2,0.3,0.4};
	float diss[]={0.4,0.3,0.2,0.1};
	for(int a=0; a<i_number_of_elements; a++){
		element_names->at(a).setString(elements[a]);
		// diffusion coefficient
		cout<<"diffusion_"+elements[a]+"_coeff"<<"  "<<coeffs[a]<<endl;
		DoubleData *diff = new DoubleData("diffusion_"+elements[a]+"_coeff"+elements[a],coeffs[a]);
		db->addData(diff);

		// dissipation rate
		DoubleData *dis = new DoubleData("dissipation_"+elements[a]+"_rate"+elements[a],diss[a]);
		db->addData(dis);

		TVectorData<TVectorData<DoubleData>* > *element_grid;
		element_grid = new TVectorData<TVectorData<DoubleData>* >("element_"+elements[a]+"_grid","tvectordata_double");
		cout<<"element_"+elements[a]+"_grid"<<endl;
		element_grid->reserveSize(grid_size);
		for (int i=0; i<grid_size; i++) {
			element_grid->at(i) = new TVectorData<DoubleData>("grid_row", "tvectordata_double");
			element_grid->at(i)->reserveSize(grid_size);
			/// initialise the temperature to zero.
			for (int j=0; j<grid_size; j++)
				element_grid->at(i)->at(j).setDouble(0);
		}
		// add data to agent's database
		db->addData(element_grid);
	}
	db->addData(element_names);

	// temperature grid.
	TVectorData<TVectorData<DoubleData>* > *temperature_grid = new TVectorData<TVectorData<DoubleData>* >("temperature_grid","tvectordata_double");
	temperature_grid->reserveSize(grid_size);
	for (int i=0; i<grid_size; i++) {
		temperature_grid->at(i) = new TVectorData<DoubleData>("grid_row", "tvectordata_double");
		temperature_grid->at(i)->reserveSize(grid_size);
		/// initialise the temperature to zero.
		for (int j=0; j<grid_size; j++)
			temperature_grid->at(i)->at(j).setDouble(0);
	}
	// add data to agent's database
	db->addData(temperature_grid);

	// bug grid: bug_grid[i][j] returns the id of the bug-agent that is lives on grid position i,j.
	// if position i/j is empty, bug_grid[i][j] returns zero
	TVectorData<TVectorData<IntegerData>* > *bug_grid = new TVectorData<TVectorData<IntegerData>* >("bug_grid", "tvectordata_int");
	bug_grid->reserveSize(grid_size);
	for (int i=0; i<grid_size; i++) {
		// the name of this data item will not be used
		bug_grid->at(i) = new TVectorData<IntegerData>("grid_row","tvectordata_int");
		bug_grid->at(i)->reserveSize(grid_size);
		/// initialise the temperature to zero.
		for (int j=0; j<grid_size; j++)
			bug_grid->at(i)->at(j).setInteger(0);
	}
	// add data to agent's database
	db->addData(bug_grid);

	// bug-positions. vector storing the x and y index of where bug i lives.
	TVectorData<TVectorData<IntegerData>* > *bug_positions = new TVectorData<TVectorData<IntegerData>* >("bug_positions", "tvectordata_int");
	bug_positions->reserveSize(number_bugs);
	// reserve size
	for (int i=0; i<number_bugs; i++) {
		bug_positions->at(i) = new TVectorData<IntegerData> ("bug_position", "tvectordata_int");
		bug_positions->at(i)->reserveSize(2);
	}
	// add data to agent's database
	db->addData(bug_positions);

	// temporary matrix storing the desired bug positions.
	TVectorData<TVectorData<TVectorData<IntegerData>* >* > *desired_bug_grid = new TVectorData<TVectorData<TVectorData<IntegerData>* >* > ("desired_bug_grid", "no_type_given");

	desired_bug_grid->reserveSize(grid_size);
	for (int i=0; i<grid_size; i++) {
		desired_bug_grid->at(i) = new TVectorData<TVectorData<IntegerData>* >("grid_row", "no_type_given");
		desired_bug_grid->at(i)->reserveSize(grid_size);
		for (int j=0; j<grid_size; j++)
			desired_bug_grid->at(i)->at(j) = new TVectorData<IntegerData> ("no_name_given", "no_type_given");
	}
	db->addData(desired_bug_grid);

	// vector for temporary storage
	TVectorData<TVectorData<IntegerData>* > *desired_bug_positions = new TVectorData<TVectorData<IntegerData>* >("desired_bug_positions", "tvectordata_int");
	desired_bug_positions->reserveSize(number_bugs);
	for (int i=0; i<number_bugs; i++) {
		desired_bug_positions->at(i) = new TVectorData<IntegerData> ("bug_position", "tvectordata_int");
		desired_bug_positions->at(i)->reserveSize(2);
	}
	db->addData(desired_bug_positions);

	// we will randomly initialise the positions of the bugs here. in general, it would be a lot nicer to have
	// an initialiser class with which one could choose between different initialisation methods. however, since this
	// is only an example on how to do agent/rule-based simulations in the hive, i do not want to spend too much time
	// implementing this. hence i do it this way!
	int x,y;
	for (int i=0; i<number_bugs; i++) {
		// randomly select a position
		do {
			x = Util::RANDOM_INT(0,99);
			y = Util::RANDOM_INT(0,99);
		} while (bug_grid->at(x)->at(y).getInteger() != 0);
		// update bug_grid
		bug_grid->at(x)->at(y).setInteger(i+1);
		// update bug_positions
		bug_positions->at(i)->at(0).setInteger(x);
		bug_positions->at(i)->at(1).setInteger(y);
	}


	// finally add actions, simulators and message generators to the world agent
	this->addActionsToAgentsActionSet(bond);
	this->addSimulatorToAgent(bond);
	this->addMessageGeneratorsToAgent(bond);

	return bond;
}
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);

	}
}
Beispiel #11
0
Agent* BlindAgentFactory::createAgent()
{
	//Create the agent and the Database
	Agent *bond = new Agent();
	Hive::Database *db = bond->getDatabase();

	// //////////////////////////////////////////////////////////////////
	// Create the base Data objects that are needed by the blind agent
	/////////////////////////////////////////////////////////////////////

	// type name
	StringData *mytypename = new StringData("mytypename", "hans");
	db->addData(mytypename->getName(), mytypename);

	// Internal clock
	DoubleData *celltime = new DoubleData("celltime", 0.0);
	db->addData(celltime->getName(), celltime);

	// record the last dt
	DoubleData *dt = new DoubleData("dt", 0);
	db->addData(dt);

	DoubleData *noutt = new DoubleData("nextOutputTime", 0.0);
	db->addData(noutt->getName(), noutt);

	// Equilibration Time  used by chemotaxis model
	DoubleData *eqtime = new DoubleData("eqtime", cpi->getEqTime());
	db->addData(eqtime->getName(), eqtime);

	// Output frequency of data from the cell may or may not be used
	DoubleData *outputinterval_Data = new DoubleData("outputinterval",this->output_interval);
	db->addData(outputinterval_Data->getName(), outputinterval_Data);

	// at the present the world as well as the metabolism simulatots can only handle one ligand profile
	TVectorData<double> *ligands = new TVectorData<double> ("ligands","tvector_double");
	ligands->reserveSize(1);
	ligands->at(0) = 0;
	db->addData(ligands->getName(),ligands);

	// this stores how much  nutrient a cell would like to get from the world
	TVectorData<double> *appetite = new TVectorData<double> ("appetite", "tvector_double");
	appetite->reserveSize(1);
	appetite->at(0) = 0;
	db->addData(appetite->getName(), appetite);


	// parameter that sets the base effeciency at which nutrient is removed and added to energy
	DoubleData *effeciency = new DoubleData("base_effeciency_of_conversion", 1);
	db->addData(effeciency);

	DoubleData *r1 = new DoubleData("r1", 1);
	db->addData(r1);

	// Marker of the generation of the cell
	IntegerData *generationData = new IntegerData("generation",0);
	db->addData(generationData);


	/// flag that will be set by the death simulator, if the cell has to die
	BoolData *death_flag = new BoolData("death_flag", false);
	db->addData(death_flag->getName(), death_flag);

	/// flag that will be set by the birth simulator, if the cell gives rise to offspring
	BoolData *birth_flag = new BoolData("birth_flag", false);
	db->addData(birth_flag->getName(), birth_flag);

	// UPDATED METABOLISM / BIRTH / DEATH SIMULATOR
	// starting or default values, same for all cells
	double starting_essence = 0.5;
	double default_kcat = 5;
	double default_Km   = 0.1;
	double default_essence_cost_for_movement = 0.025;
	double default_mass_threshold_for_birth = 1;
	double default_essence_threshold_for_death = 0.000001;
	double default_background_death_rate_per_unit_time = 0; // not sure whether it is a good idea to have this in the cell.
    double default_yield = 1;
    bool   default_is_levy = false;
    double default_parameter_for_steplength_dist = 1;
    double default_rho = 0.3;
    double default_velocity = 2;
    double default_current_angle = 2.0;
    double default_distance_desired_to_travel = 0.0;
    double default_traveled_distance = 0.0;

	// create the data items storing these parameters
	DoubleData *essence = new DoubleData("essence",starting_essence);
	// kcat and Km are the rescaled variables
	DoubleData *kcat = new DoubleData("kcat",default_kcat);
	DoubleData *Km = new DoubleData("Km",default_Km);
	// this is the parameter alpha
	DoubleData *essence_cost_for_movement = new DoubleData("essence_cost_for_movement",default_essence_cost_for_movement);
	DoubleData *background_death_rate_per_unit_time = new DoubleData("background_death_rate_per_unit_time",default_background_death_rate_per_unit_time);
	// the user will not be able to set the birth threshold it  is always equal to one
	DoubleData *essence_threshold_for_birth = new DoubleData("essence_threshold_for_birth",default_mass_threshold_for_birth);
	DoubleData *essence_threshold_for_death = new DoubleData("essence_threshold_for_death",default_essence_threshold_for_death);
	DoubleData *velocity = new DoubleData("velocity",default_velocity);
	DoubleData *yield = new DoubleData("yield", default_yield);
	BoolData   *is_levy = new BoolData("is_levy", default_is_levy);
	DoubleData *rho = new DoubleData("rho", default_rho);
	DoubleData *parameter_for_steplength_dist =new DoubleData("parameter_for_steplength_dist", default_parameter_for_steplength_dist);

	// variables needed for the movement simulator to operate correctly
	DoubleData *current_angle = new DoubleData("current_angle", default_current_angle);
	DoubleData *distance_desired_to_travel = new DoubleData("distance_desired_to_travel", default_distance_desired_to_travel);
	DoubleData *traveled_distance = new DoubleData("traveled_distance", default_traveled_distance);

	// add the data items to the database
	db->addData(essence);
	db->addData(kcat);
	db->addData(Km);
	db->addData(essence_cost_for_movement);
	db->addData(background_death_rate_per_unit_time);
	db->addData(essence_threshold_for_birth);
	db->addData(essence_threshold_for_death);
	db->addData(velocity);
	db->addData(yield);
	db->addData(current_angle);
	db->addData(distance_desired_to_travel);
	db->addData(traveled_distance);
	db->addData(is_levy);
	db->addData(rho);
	db->addData(parameter_for_steplength_dist);


	this->cpi->setNextCellParameters(bond);



	// ///////////////////////////////////////////////////////////////////
	// add simulators to agent
	//////////////////////////////////////////////////////////////////////
	this->addSimulatorToAgent(bond);

	//////////////////////////////////////////////////////////////////////
	// add actions to agents action set
	//////////////////////////////////////////////////////////////////////
	this->addActionsToAgentsActionSet(bond);

	//////////////////////////////////////////////////////////////////////
	// add message generators to action set
	//////////////////////////////////////////////////////////////////////
	this->addMessageGeneratorsToAgent(bond);


	return bond;
}