コード例 #1
0
ファイル: cycle.c プロジェクト: KEggleston/newa
int run_disease_model(int *w_sday, int *w_shour, int *w_eday, int *w_ehour, int *w_duration, int *w_parms)
{
	int day;
	int hour;

	for (day=day_first; day<=day_last; day++) 
	{
		for (hour=0; hour<=23; hour++) 
		{
			if ((day == day_first && hour < hour_first) || 
				(day == day_last && hour > hour_last)) continue;
			sporulation(day,hour);
			survival(day,hour);
			infection(day,hour);
			calculate_warnings(day,hour);
			if (model_init) model_init = FALSE;
		}
	}

	for (day=0; day<=dmwarns; day++)
	{
		w_sday[day] = wrn[day].sday;
		w_shour[day] = wrn[day].shour;
		w_eday[day] = wrn[day].eday;
		w_ehour[day] = wrn[day].ehour;
		w_duration[day] = wrn[day].duration;
	}
	w_parms[0] = dmwarns;
	w_parms[1] = c[0].els12;
	w_parms[2] = c[0].primary_inf;
	w_parms[3] = c[0].incubation;

	return 0;

}
コード例 #2
0
void WeeklyDD(const std::vector<double> &TargetedEffort, const std::vector<double> &NontargetedEffort,  std::vector<double> &Biomass, const std::vector<double> &par){

  // Global variables
  extern int NIPY;
  extern double CatchabilityScalingFactor, BiomassScalingFactor,RecruitmentScalingFactor;
  extern double rho, wk, wk_1;//, M;

  assert(TargetedEffort.size() == Biomass.size());

  unsigned int max_timestep = TargetedEffort.size();

  // Define necessary containers
  std::vector< double > Rec(max_timestep, 0.0), survival(max_timestep, 0.0);

  // Remember that the optimizer work on parameters of the same order of magnitude
  double M = par[0];
  double Targeted_catchability = par[1] * CatchabilityScalingFactor;
  double Nontargeted_catchability = par[2] * CatchabilityScalingFactor;

  // Initialise the vector of biomass
  Biomass[0] = par[4] *  BiomassScalingFactor;
  Biomass[1] = par[5] *  BiomassScalingFactor;

  // von mises parameters
  double vm_mean = par[6]; // make sure it varies between -M_PI and +M_PI
  double vm_sigma = par[7]; // should be positive

  // Calculate survival given the vector of effort
  for(unsigned int i=0; i < max_timestep; i += 1) {
    survival[i] = exp(-(M + Targeted_catchability * TargetedEffort[i] + Nontargeted_catchability * NontargetedEffort[i]));
  }

  // Calculate the proportion of recruitment in each week 
  std::vector<double> RecDist(NIPY, 0.0);
  RecDist = vonMisesRecDist(vm_mean, vm_sigma);
  
  // Create the vector of recruitment
    for(unsigned int counter = 0; counter < max_timestep; counter++){
      Rec[counter] = par[8 + counter / NIPY] * RecruitmentScalingFactor * RecDist[counter % NIPY];
    }

  // Example how to print the vector of parameters
  //std::cout << "This is par[0] " << par[0] << "\n";
  //std::cout << "This is par[1] " << par[1] << "\n";
  //std::cout << "Number of parameters " << par.size() << "\n";

  // Recursive calculation of biomass
  for(unsigned int counter = 2; counter < max_timestep; counter++){

    // calculate biomass
    Biomass[counter] = survival[counter-1] * Biomass[counter-1] + rho * survival[counter-1] * Biomass[counter-1] - rho * survival[counter-1] *survival[counter -2] * Biomass[counter-2] - rho * survival[counter-1] * wk_1 *  Rec[counter-1] + wk * Rec[counter]; 

    if(Biomass[counter] < 0){Biomass[counter] = 0;} 
  }
}