Ejemplo n.º 1
0
Archivo: city.c Proyecto: blt/hamurabi
resp step(city_st *cty) {
  uint16_t died = 0;
  died += starvation(cty);
  if (died > cty->population * 0.45)
    return ESTARVE;
  cty->avg_starved = 0.1*died + 0.9*cty->avg_starved; // EMA

  if (RAND(15) == 0)
    died += plague(cty);
  cty->tot_died += died;

  cty->population += births(cty);

  cty->migrated  = 0.1*RAND(cty->population);
  cty->trade_val = 17+RAND(10);
  cty->yield = RAND(10)+1;

  cty->bushels += cty->yield*cty->planted;
  rats(cty);
  return OKAY;
}
Ejemplo n.º 2
0
void Model::run(const std::string& output_file) {
	YoungSetter young_setter;
	int max_survival = Parameters::instance()->getIntParameter(MAX_SURVIVAL);
	float size_of_timestep = Parameters::instance()->getIntParameter(SIZE_OF_TIMESTEP);
	for (int t = 2; t < 26; ++t) {
		std::cout << " ---- " << t << " ---- " << std::endl;
		simulate(R, net, young_setter, t);
		births(t);
		runTransmission(t);
		updateVitals(size_of_timestep, max_survival);

		NumericVector theta_form = as<NumericVector>((*R)["theta.form"]);
		std::cout << "pop sizes: " << popsize[t - 2] << ", " << popsize[t - 1] << std::endl;
		theta_form[0] = theta_form[0] + std::log(popsize[t - 2]) - std::log(popsize[t - 1]);
		((*R)["theta_form"]) = theta_form;

		std::cout << "edge count: " << net.edgeCount() << std::endl;
		stats.incrementCurrentEdgeCount(net.edgeCount());
		stats.incrementCurrentSize(net.vertexCount());
		stats.resetForNextTimeStep();
	}
	stats.writeToCSV(output_file);
}