コード例 #1
0
void Population::doOutput()
{
	// Llama a cada output interno
	for (vector<Output *>::size_type n = 0;
				n < _outputs.size(); n++)
	{
		// Va población por población iterando por
		// sus agentes y llamando a los aspects
		// que corresponda...
		// 1. Cheque si le toca...
		Output *out = _outputs[n];
		//time_t t; time(&t);
		double t = get_time();
		if (_history % out->Loops == 0 ||  (t - out->lastTime) > out->Timespan)
		{
			// Le toca...
			out->lastTime = t;
			int size = ((Population::SubPopulation *) out->SubPopulation)->GetSize();
			// Se fija si tiene que abrir el archivo
			out->CheckFileOpen();
			// Write headers if it overwrites everytime
			out->CheckFileHeaders();
			// Hace el for de 1 a size de esa población
			for (int i = 0; i < size; i++)
			{
				key agentId = MAKE_AGENT_ID(out->SubPopulationId, i);
				if (out->IsAggregate == false)
					OutputAggregation::BeginLine(out->File, this->_history, agentId);

				// Se mueve por los fieldGroups
				for (vector <FieldGroup *>::size_type g = 0;
					g < out->FieldGroups.size(); g++)
				{
					FieldGroup *fg = out->FieldGroups[g];
					// Le pide los valores de los fields al aspect
					// para ese agentid
					vector <varValue> retValues;
					fg->Aspect->ShowValues(agentId, fg->FieldNames, retValues);
					// Keeps values
					fg->OutputAggregationManager.ProcessValues(retValues);
					// Si no hace aggregate, las muestra
					if (out->IsAggregate == false)
						fg->OutputAggregationManager.ShowValues(out->File);
				}
				if (out->IsAggregate == false)
					OutputAggregation::EndLine(out->File);

			}
			if (out->IsAggregate == true)
			{
				OutputAggregation::BeginLine(out->File, this->_history);
				for (vector <FieldGroup *>::size_type g = 0;
								g < out->FieldGroups.size(); g++)
				{
					// Los muestra...
					FieldGroup *fg = out->FieldGroups[g];
					fg->OutputAggregationManager.ShowValues(out->File);
				}
				OutputAggregation::EndLine(out->File);
			}
			// Check close
			out->CheckFileClose();
		}
	}
}