Skip to content
Snippets Groups Projects
Commit 82d32be3 authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

butterflies: make female fraction configurable

parent be26a9ad
Branches
Tags
No related merge requests found
...@@ -120,10 +120,10 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts, ...@@ -120,10 +120,10 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
const cats_dt_population total_adults = get_adult_population(grid, row, col); const cats_dt_population total_adults = get_adult_population(grid, row, col);
if (total_adults == 0) return; if (total_adults == 0) return;
ts->temp++; ts->temp++;
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
// total females: how many of the total adults are female, as drawn from a binomial distribution with p = 0.5 // total females: how many of the total adults are female, as drawn from a binomial distribution with p = 0.5
// can be safely cast, because gsl_ran_binomial will return a number <= total_adults // can be safely cast, because gsl_ran_binomial will return a number <= total_adults
const cats_dt_population total_females = (cats_dt_population) gsl_ran_binomial(ts->rng, 0.5, total_adults); const cats_dt_population total_females = (cats_dt_population) gsl_ran_binomial(ts->rng, (double) module_conf->female_fraction, total_adults);
assert(total_females >= 0 && total_females <= total_adults); assert(total_females >= 0 && total_females <= total_adults);
// total males: the rest // total males: the rest
...@@ -133,7 +133,7 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts, ...@@ -133,7 +133,7 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
if (total_females == 0 || total_males == 0) return; if (total_females == 0 || total_males == 0) return;
// here we calculate the number of eggs per female, so we can return early if the cell is unsuitable // here we calculate the number of eggs per female, so we can return early if the cell is unsuitable
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
cats_dt_rates eggs_per_f = calculate_rate(&module_conf->eggs_per_female, total_adults, &grid->param, grid, row, cats_dt_rates eggs_per_f = calculate_rate(&module_conf->eggs_per_female, total_adults, &grid->param, grid, row,
col, NULL); col, NULL);
int32_t eggs_per_female = (int32_t) ceill(eggs_per_f); int32_t eggs_per_female = (int32_t) ceill(eggs_per_f);
......
...@@ -15,7 +15,8 @@ struct cats_global global; ...@@ -15,7 +15,8 @@ struct cats_global global;
struct cats_debug_options cats_debug; struct cats_debug_options cats_debug;
void *butterfly_grid_init(__attribute__((unused)) struct cats_configuration *conf, struct cats_grid *grid, __attribute__((unused)) void *ignored) void *butterfly_grid_init(__attribute__((unused)) struct cats_configuration *conf, struct cats_grid *grid,
__attribute__((unused)) void *ignored)
{ {
log_message(LOG_INFO, "%s: %s: grid init", module_name, __func__); log_message(LOG_INFO, "%s: %s: grid init", module_name, __func__);
printf("%d %d\n", grid->dimension.cols, grid->dimension.rows); printf("%d %d\n", grid->dimension.cols, grid->dimension.rows);
...@@ -40,7 +41,8 @@ void *butterfly_grid_init(__attribute__((unused)) struct cats_configuration *con ...@@ -40,7 +41,8 @@ void *butterfly_grid_init(__attribute__((unused)) struct cats_configuration *con
} }
void *butterfly_grid_cleanup(__attribute__((unused)) struct cats_configuration *conf, struct cats_grid *grid, void *data) void *
butterfly_grid_cleanup(__attribute__((unused)) struct cats_configuration *conf, struct cats_grid *grid, void *data)
{ {
log_message(LOG_INFO, "%s: grid cleanup", module_name); log_message(LOG_INFO, "%s: grid cleanup", module_name);
assert(grid != NULL); assert(grid != NULL);
...@@ -56,7 +58,6 @@ void *butterfly_grid_cleanup(__attribute__((unused)) struct cats_configuration * ...@@ -56,7 +58,6 @@ void *butterfly_grid_cleanup(__attribute__((unused)) struct cats_configuration *
} }
void load_butterflies_species_params(struct cats_configuration *conf, struct cats_ini *ini, const char *section_name, void load_butterflies_species_params(struct cats_configuration *conf, struct cats_ini *ini, const char *section_name,
struct cats_species_param *param) struct cats_species_param *param)
{ {
...@@ -68,22 +69,39 @@ void load_butterflies_species_params(struct cats_configuration *conf, struct cat ...@@ -68,22 +69,39 @@ void load_butterflies_species_params(struct cats_configuration *conf, struct cat
load_conf_vital_rate(&data->butterfly_egg_to_adult_survival, conf, ini, section_name, param); load_conf_vital_rate(&data->butterfly_egg_to_adult_survival, conf, ini, section_name, param);
load_conf_value(true, ini, section_name, "butterflies random walk steps maximum", &data->animal_dispersal_max_radius); load_conf_value(true, ini, section_name, "butterflies random walk steps maximum",
&data->animal_dispersal_max_radius);
load_conf_value(true, ini, section_name, "butterflies egg fraction source", &data->egg_fraction_source); load_conf_value(true, ini, section_name, "butterflies egg fraction source", &data->egg_fraction_source);
bool l = load_conf_value(false, ini, section_name, "butterflies egg fraction step", &data->egg_fraction_step); bool l = load_conf_value(false, ini, section_name, "butterflies egg fraction step", &data->egg_fraction_step);
if (!l) { if (!l) {
data->egg_fraction_step = 0.5; data->egg_fraction_step = 0.5;
log_message(LOG_INFO, "using default value for butterflies egg fraction step: %Lf\n", data->egg_fraction_step); log_message(LOG_INFO, "using default value for butterflies egg fraction step: %Lf\n",
data->egg_fraction_step);
}
l = load_conf_value(false, ini, section_name, "butterflies female fraction", &data->female_fraction);
if (!l) {
data->female_fraction = 0.5;
log_message(LOG_INFO, "using default value for butterflies female fraction: %Lf\n",
data->female_fraction);
}
if (data->female_fraction <= 0.0 || data->female_fraction >= 1.0) {
log_message(LOG_ERROR, "butterflies female fraction must be in (0, 1), is %Lf", data->female_fraction);
exit_cats(EXIT_FAILURE);
} }
if (data->egg_fraction_step <= 0.0 || data->egg_fraction_step > 1.0) { if (data->egg_fraction_step <= 0.0 || data->egg_fraction_step > 1.0) {
log_message(LOG_ERROR, "butterflies egg fraction step must be in (0, 1], is %Lf", data->egg_fraction_step); log_message(LOG_ERROR, "butterflies egg fraction step must be in (0, 1], is %Lf",
data->egg_fraction_step);
exit_cats(EXIT_FAILURE); exit_cats(EXIT_FAILURE);
} }
if (data->animal_dispersal_max_radius <= 0) { if (data->animal_dispersal_max_radius <= 0) {
log_message(LOG_ERROR, "butterflies random walk steps maximum must be > 0, is %d", data->animal_dispersal_max_radius); log_message(LOG_ERROR, "butterflies random walk steps maximum must be > 0, is %d",
data->animal_dispersal_max_radius);
exit_cats(EXIT_FAILURE); exit_cats(EXIT_FAILURE);
} }
......
...@@ -47,7 +47,7 @@ struct conf_data_butterflies { ...@@ -47,7 +47,7 @@ struct conf_data_butterflies {
struct cats_vital_rate eggs_per_female; struct cats_vital_rate eggs_per_female;
struct cats_vital_rate butterfly_egg_to_adult_survival; struct cats_vital_rate butterfly_egg_to_adult_survival;
struct cats_vital_rate butterfly_generations; struct cats_vital_rate butterfly_generations;
cats_dt_rates female_fraction;
bool actions_added; bool actions_added;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment