예제 #1
0
void Cell::delta_ext(double e, const adevs::Bag<CellEvent>& xb) 
{
	// Update the count if living neighbors
	adevs::Bag<CellEvent>::const_iterator iter;
	for (iter = xb.begin(); iter != xb.end(); iter++)
	{
		if ((*iter).value == Dead) nalive--;
		else nalive++;
	}
}
void BottomQueue::delta_ext(double e, const adevs::Bag<QCell>& xb){
	QCell holder;
	
	if(!xb.empty()){
		adevs::Bag<QCell>::iterator iter = xb.begin();
		while(iter != xb.end()){
			holder = *iter;
			bottomlist.push_back(holder);
			iter++;
		}
	}
}
예제 #3
0
void Cell::output_func(adevs::Bag<CellEvent>& yb) 
{
	CellEvent e;
	// Assume we are dying
	e.value = Dead;
	// Check in case this in not true
	if (check_born_rule())
	{
		e.value = Alive;
	}
	// Set the initial visualization value
	if (vis_phase != NULL) *vis_phase = e.value;
	// Generate an event for each neighbor
	for (long int dx = -1; dx <= 1; dx++)
	{
		for (long int dy = -1; dy <= 1; dy++)
		{
			e.x = (x+dx)%w;
			e.y = (y+dy)%h;
			if (e.x < 0) e.x = w-1;
			if (e.y < 0) e.y = h-1;
			// Don't send to self
			if (e.x != x || e.y != y)
			{
				yb.insert(e);
			}
		}
	}
}
void FourZoneBuildingExt::external_event(double* q, double e,
	const adevs::Bag<OMC_ADEVS_IO_TYPE>& xb)
{
	bool updateValues = false;
	FourZoneBuilding::external_event(q,e,xb);
	Bag<OMC_ADEVS_IO_TYPE>::const_iterator iter = xb.begin();
	for (; iter != xb.end(); iter++)
	{
		if ((*iter).port == BuildingModelInterface::sample) takeSample = true;
		else if ((*iter).port == BuildingModelInterface::onOffCmd)
		{
			OnOffEvent* cmd = dynamic_cast<OnOffEvent*>((*iter).value);
			if (cmd->getItem() == HEATING_UNIT)
			{
				updateValues = true;
				if (cmd->getUnit() == 0)
					set_z1_heatStage(cmd->getMode());
				else if (cmd->getUnit() == 1)
					set_z2_heatStage(cmd->getMode());
				else if (cmd->getUnit() == 2)
					set_z3_heatStage(cmd->getMode());
				else if (cmd->getUnit() == 3)
					set_z4_heatStage(cmd->getMode());
				else if (cmd->getUnit() == 4)
					set_znoise_heatStage(cmd->getMode());
			}
			else if (cmd->getItem() == COOLING_UNIT)
			{
				updateValues = true;
				if (cmd->getUnit() == 0)
					set_z1_coolStage(cmd->getMode());
				else if (cmd->getUnit() == 1)
					set_z2_coolStage(cmd->getMode());
				else if (cmd->getUnit() == 2)
					set_z3_coolStage(cmd->getMode());
				else if (cmd->getUnit() == 3)
					set_z4_coolStage(cmd->getMode());
				else if (cmd->getUnit() == 4)
					set_znoise_coolStage(cmd->getMode());
			}
		}
	}
	if (updateValues)
		update_vars(q,true);
}
void FourZoneBuildingExt::output_func(const double *q, const bool* state_event,
	adevs::Bag<OMC_ADEVS_IO_TYPE>& yb)
{
	FourZoneBuilding::output_func(q,state_event,yb);
	update_vars(q,false);
	PortValue<BuildingEvent*> pv;
	pv.port = BuildingModelInterface::tempData;
	pv.value = new TemperatureEvent(OUTDOOR_THERMOMETER,0,get_outdoor_d1());
	yb.insert(pv);
	pv.value = new TemperatureEvent(THERMOSTAT_THERMOMETER,0,get_z1_t1());
	yb.insert(pv);
	pv.value = new TemperatureEvent(THERMOSTAT_THERMOMETER,1,get_z2_t1());
	yb.insert(pv);
	pv.value = new TemperatureEvent(THERMOSTAT_THERMOMETER,2,get_z3_t1());
	yb.insert(pv);
	pv.value = new TemperatureEvent(THERMOSTAT_THERMOMETER,3,get_z4_t1());
	yb.insert(pv);
	pv.port = extraTempData;
	pv.value = new TemperatureEvent(THERMOSTAT_THERMOMETER,4,get_znoise_t1());
	yb.insert(pv);
}
void SolutionQueue::output_func(adevs::Bag<QCell>& yb){
	yb.insert(solutionlist.front());
}
void FourZoneBuildingExt::gc_output(adevs::Bag<OMC_ADEVS_IO_TYPE>& gb)
{
	Bag<OMC_ADEVS_IO_TYPE>::iterator iter = gb.begin();
	for (; iter != gb.end(); iter++)
		delete ((*iter).value);
}
void Cell::output_func(adevs::Bag<vec>& yb){
/* EXPERIMENTAL BEHAVIOR CODE */
//	// If the cell hasn't attached
//	if(getTimeAttached() == 0.0){
//		// check to see if the cell could attach
//		vec dist = p + ta()*v;
//		
//		if(dist[2] < BioChem::getInstance()->getFilterTopPos()){
//			// see what would happen if the cell did attach
//			dist[2] = BioChem::getInstance()->getFilterTopPos();
//			
//			// look at all the other cells
//			CellPopulation* pop = CellPopulation::getInstance();
//			CellPopulation::iterator iter;
//			bool settled = false;
//			for(iter = pop->begin(); iter != pop->end(); iter++){
//				vec position = (*iter)->getPos();
//				do{
//					// could this cell collide?
//					if(getDistance(position, dist) < 1.0){
//						// avoid collision by stacking
//						vec stackem;
//						stackem[0] = r.uniform(-1.0,1.0);
//						stackem[1] = r.uniform(-1.0,1.0);
//						stackem[2] = 0.0;
//						dist = position + stackem;
//					}
//				} while (!settled);
//			}
//			
//			p += ta()*v;
//			p[2] = BioChem::getInstance()->getFilterTopPos();
//		} else {
//			// set the position to the new position
//			p = dist;
//		}
//	}
	
	
	/* Move in current direction */
	if (getTime() >= getTimeAttached()) p += ta()*v;
//	if (getTime() >= 3.0) p += ta()*v;
	
	// Don't go below 0.0
	if (p[0] < (double)0.3)
		p[0] = (double)0.3;
	if (p[1] < (double)0.3)
		p[1] = (double)0.3;
	
	// Don't go above Width or Depth
	if (p[0] > BioChem::getInstance()->getDomain()[0]-(double)0.3)
		p[0] = BioChem::getInstance()->getDomain()[0]-(double)0.3;
	if (p[1] > BioChem::getInstance()->getDomain()[1]-(double)0.3)
		p[1] = BioChem::getInstance()->getDomain()[1]-(double)0.3;
	
	// Don't go above or below the filter
	if (p[2] < BioChem::getInstance()->getFilterBottomPos())
		p[2] = BioChem::getInstance()->getFilterBottomPos();
	if (p[2] > BioChem::getInstance()->getFilterTopPos())
		p[2] = BioChem::getInstance()->getFilterTopPos();
	/* Output new position */
	yb.insert(p);
}