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

butterflies: updates and cleanups

parent f28c299e
No related branches found
No related tags found
No related merge requests found
......@@ -7,45 +7,34 @@
#include "butterflies_generations.h"
#include "inline.h"
void grid_update_generations(struct cats_grid *grid, struct cats_thread_info *ts)
void area_update_generations(struct cats_grid *grid, struct cats_thread_info *ts)
{
struct cats_configuration *conf = ts->conf;
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
struct cats_vital_rate *rate = &module_conf->butterfly_generations;
//const bool sim_mode = conf->
struct cats_vital_rate *rate = &module_conf->butterfly_generations;
const cats_dt_coord start_row = ts->area.start_row;
const cats_dt_coord end_row = ts->area.end_row;
const cats_dt_coord start_col = ts->area.start_col;
const cats_dt_coord end_col = ts->area.end_col;
for (cats_dt_coord row = start_row; row < end_row; row++) {
for (cats_dt_coord col = start_col; col < end_col; col++) {
if (cell_excluded_by_overlay(conf, row, col)) {
data->eggs[row][col] = 0.0f;
set_population_ignore_cc(grid, row, col, 0);
data->generations[row][col] = 0.0f;
continue;
}
cats_dt_rates gen = calculate_rate(rate, 0, conf->param, grid, row, col, NULL);
cats_dt_environment suitability = get_suitability(grid, row, col);
if (suitability < grid->param.ZT) {
gen = 0.0;
} else if (suitability > grid->param.OT) {
gen = min_rates(1.0, gen);
}
data->generations[row][col] = (float) gen;
//printf("GENERATIONS::thread %03d:: %d %d %f\n", ts->id ,row, col, (float) gen);
}
}
}
\ No newline at end of file
......@@ -2,5 +2,5 @@
#define CATS_BUTTERFLIES_GENERATIONS_H
#include "data/cats_grid.h"
#include "threading/threading.h"
void grid_update_generations(struct cats_grid *grid, struct cats_thread_info *ts);
void area_update_generations(struct cats_grid *grid, struct cats_thread_info *ts);
#endif //CATS_BUTTERFLIES_GENERATIONS_H
......@@ -12,7 +12,7 @@
static inline bool cell_excluded_by_generation (const struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
{
const int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
const struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
if (data->generation_current > (int32_t) ceilf(data->generations[row][col])) return true;
return false;
}
......
......@@ -52,15 +52,17 @@ void *butterfly_grid_cleanup(struct cats_configuration *conf, struct cats_grid *
}
void load_butterflies_species_params(struct cats_configuration *conf, struct cats_ini *ini, const char *section_name,
struct cats_species_param *param)
{
struct conf_data_butterflies *data = CATS_MODULE_DATA;
load_conf_vital_rate(&data->eggs_per_female, conf, ini, section_name, param);
load_conf_vital_rate(&data->butterfly_generations, conf, ini, section_name, param);
load_conf_vital_rate(&data->butterfly_egg_to_adult_survival, conf, ini, section_name, param);
//bool _get_int32_config_value(const struct cats_ini *ini, const char *section, const char *key, bool required, int32_t *value);
cats_dt_rates female_percentage;
load_conf_value(true, ini, section_name, "butterflies random walk steps maximum", &data->animal_dispersal_max_radius);
......@@ -97,8 +99,5 @@ void cats_module_init(struct cats_configuration *conf)
for (enum butterfly_stats which = BF_STAT_MIN; which < BF_STAT_MAX; which++) {
data->stat_ids[which] = add_custom_stat(&conf->stats_registry, get_butterfly_stats_name(which));
}
}
......@@ -19,9 +19,11 @@ struct grid_data_butterflies {
enum butterfly_cell_info {
BF_CELL_CLEAR = 0,
BF_CELL_EXCLUDED = 1 << 0,
BF_CELL_HABITAT_OK = 1 << 1,
BF_CELL_RESOURCE_AVAILABLE = 1 << 2
BF_CELL_EXCLUDED = 1 << 1,
BF_CELL_HABITAT_OK = 1 << 2,
BF_CELL_RESOURCE_AVAILABLE = 1 << 3,
BF_CELL_VALID_DISPERSAL_TARGET = 1 << 4
};
......@@ -36,7 +38,14 @@ struct conf_data_butterflies {
int32_t animal_dispersal_max_radius; ///< maximal flight/dispersal distance
cats_dt_rates egg_to_adult_survival_rate_maximum;
cats_dt_rates egg_per_female_maximum;
cats_dt_rates probability_to_stay;
cats_dt_rates egg_fraction_source;
cats_dt_rates egg_fraction_step;
bool actions_added;
cats_dt_rates stationary_females;
struct cats_vital_rate eggs_per_female;
struct cats_vital_rate butterfly_egg_to_adult_survival;
struct cats_vital_rate butterfly_generations;
......
#include "modules/module_header.h"
#include "actions/cats_actions.h"
#include "butterflies_main.h"
#include "inline_overlays.h"
enum action_status butterflies_update_overlays(struct cats_configuration *conf, struct cats_grid *grid)
{
if (conf->overlays.have_overlays == false) {
return ACTION_NOT_RUN;
}
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
const cats_dt_coord rows = grid->dimension.rows;
const cats_dt_coord cols = grid->dimension.cols;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
data->info_layer[row][col] = BF_CELL_CLEAR;
if (cell_excluded_by_overlay(conf, row, col)) {
data->info_layer[row][col] |= BF_CELL_EXCLUDED;
}
if (conf->overlays.overlay[OL_HABITAT_TYPE_CC].enabled &&
conf->overlays.habitat_cc->data[row][col] > 0) {
data->info_layer[row][col] |= BF_CELL_HABITAT_OK;
}
if (conf->overlays.overlay[OL_RESOURCE].enabled &&
conf->overlays.resources->data[row][col] > 0) {
data->info_layer[row][col] |= BF_CELL_RESOURCE_AVAILABLE;
}
if (data->info_layer[row][col] & BF_CELL_HABITAT_OK &&
data->info_layer[row][col] & BF_CELL_RESOURCE_AVAILABLE) {
data->info_layer[row][col] |= BF_CELL_VALID_DISPERSAL_TARGET;
}
}
}
return ACTION_RUN;
}
\ No newline at end of file
//
// Created by andreas on 20/03/23.
//
#ifndef CATS_BUTTERFLIES_OVERLAYS_H
#define CATS_BUTTERFLIES_OVERLAYS_H
#include "configuration/configuration.h"
enum action_status butterflies_update_overlays(struct cats_configuration *conf, struct cats_grid *grid);
#endif //CATS_BUTTERFLIES_OVERLAYS_H
......@@ -7,8 +7,11 @@ void add_vital_rates(struct cats_configuration *conf, struct conf_data_butterfl
// generations
register_module_vital_rate(conf, &data->butterfly_generations,"butterflies generations");
set_vital_rate_name(&data->butterfly_generations, "butterflies generations");
set_vital_rate_suitability_cutoff_hint(&data->butterfly_generations, HYBRID_SUIT_TS_ZT);
set_vital_rate_link_hybrid_function(&data->butterfly_generations, conf, LINK_SUITABILITY_SIGMOID);
set_vital_density(&data->butterfly_generations, NO_DENSITY_DEP);
// eggs
register_module_vital_rate(conf, &data->eggs_per_female, "butterflies eggs per female");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment