diff --git a/src/cats/threading/threading-helpers.c b/src/cats/threading/threading-helpers.c index 0160f610d0f5a991342862f8bacdf688a7e2555f..b0e88c2302329f888de1c490d0698a8fe7c0e70b 100644 --- a/src/cats/threading/threading-helpers.c +++ b/src/cats/threading/threading-helpers.c @@ -50,9 +50,6 @@ initialize_thread(struct cats_thread_info *thread, struct cats_grid *grid, struc zero_statistics_stats(&thread->stats[i]); } - thread->rw_debug_cells_with_adults = 0; - thread->rw_debug_random_walks = 0; - thread->rw_debug_deposits = 0; thread->seed = get_random_seed(false); for (int i = 0; i < 4; i++) { diff --git a/src/cats/threading/threading.h b/src/cats/threading/threading.h index b34f2a2a9e462b4db9f15a0198218b4a8c2f1b3b..2dceb0c2513e8a459fa058e28c442f604e41ad65 100644 --- a/src/cats/threading/threading.h +++ b/src/cats/threading/threading.h @@ -50,9 +50,6 @@ struct cats_thread_info { struct cats_configuration *conf; gsl_rng *rng; unsigned int rng_seed; - int64_t rw_debug_cells_with_adults; - int64_t rw_debug_random_walks; - int64_t rw_debug_deposits; char *rng_state_buffer; int32_t rng_buf_size; struct random_data *rng_state; diff --git a/src/modules/butterflies/butterflies_actions.c b/src/modules/butterflies/butterflies_actions.c index 4ce07bee845a5f15064bc28020a6b691ba213199..8aa296c4ac92134e0f3362457b2c15c4b2445ffd 100644 --- a/src/modules/butterflies/butterflies_actions.c +++ b/src/modules/butterflies/butterflies_actions.c @@ -112,7 +112,6 @@ void grid_butterflies_maturation(struct cats_grid *grid, struct cats_thread_info const cats_dt_coord start_col = ts->area.start_col; const cats_dt_coord end_col = ts->area.end_col; - ts->rw_debug_cells_with_adults = 0; for (cats_dt_coord row = start_row; row < end_row; row++) { for (cats_dt_coord col = start_col; col < end_col; col++) { @@ -174,11 +173,6 @@ void butterflies_area_dispersal(struct cats_grid *grid, struct cats_thread_info const cats_dt_coord start_col = ts->area.start_col; const cats_dt_coord end_col = ts->area.end_col; - ts->rw_debug_cells_with_adults = 0; - ts->rw_debug_random_walks = 0; - ts->rw_debug_deposits = 0; - - 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) @@ -256,12 +250,11 @@ enum action_status bf_action_dispersal(struct cats_grid *grid, struct cats_confi threaded_action(&butterflies_area_dispersal, grid, conf, TS_DISPERSAL); struct conf_data_butterflies *module_conf = CATS_MODULE_DATA; - for (enum butterfly_stats which = BF_POPULATED_AT_DISPERSAL; which < BF_STAT_MAX; which++) { + for (enum butterfly_stats which = BF_RANDOM_WALK_DEPOSIT_COUNT; which < BF_STAT_MAX; which++) { int64_t stat_id = module_conf->stat_ids[which]; log_message(LOG_INFO, "STAT %s: %ld", bf_get_stats_field_name(which), grid->stats.stats[stat_id]); } - return ACTION_RUN; } @@ -319,15 +312,14 @@ enum action_status bf_action_overlay_update(struct cats_grid *grid, struct cats_ } + enum action_status bf_action_generation_finish(struct cats_grid *grid, struct cats_configuration *conf) { const int module_id = CATS_MODULE_ID; struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; - threaded_action(&bf_area_kill_adults, grid, conf, TS_DEFAULT); - data->generation_current--; assert(data->generation_current >= 0); // struct conf_data_butterflies *data = CATS_MODULE_DATA; diff --git a/src/modules/butterflies/butterflies_actions_setup.c b/src/modules/butterflies/butterflies_actions_setup.c index 9258f0ffaa45de1ff829a6faeab1329470d4db84..efffb9b7b07373ad1076b5c1266bb24a67a0f4d3 100644 --- a/src/modules/butterflies/butterflies_actions_setup.c +++ b/src/modules/butterflies/butterflies_actions_setup.c @@ -72,7 +72,8 @@ void bf_add_actions(struct cats_configuration *conf) bf_add_generation_action(conf, bf_action_stats_gather, "gather stats", generation); bf_add_generation_action(conf, bf_action_dispersal, "dispersal", generation); bf_add_generation_action(conf, bf_action_save_eggs_grid, "output eggs", generation); - bf_add_generation_action(conf, bf_action_generation_finish, "finish generation", generation); bf_add_generation_action(conf, bf_action_stats_write, "write stats", generation); + bf_add_generation_action(conf, bf_action_generation_finish, "finish generation", generation); + } } \ No newline at end of file diff --git a/src/modules/butterflies/butterflies_dispersal.c b/src/modules/butterflies/butterflies_dispersal.c index 6c7807149c158be70dfeb07dfe869ed096999845..fd67848d076b8c0f7e8b9bcdcd9371a0b69604e8 100644 --- a/src/modules/butterflies/butterflies_dispersal.c +++ b/src/modules/butterflies/butterflies_dispersal.c @@ -42,7 +42,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; const struct conf_data_butterflies *module_conf = CATS_MODULE_DATA; const bool debug_rw = module_conf->debug_rw; - + const int64_t stat_id_deposits = module_conf->stat_ids[BF_RANDOM_WALK_DEPOSIT_COUNT]; int32_t eggs_left = eggs; const cats_dt_coord max_steps = module_conf->animal_dispersal_max_radius; @@ -96,8 +96,8 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g eggs_left -= eggs_to_deposit; butterflies_add_eggs(data, row, col, (float) eggs_to_deposit); + increase_custom_stat(ts->stats, stat_id_deposits, 1); - ts->rw_debug_deposits++; if (debug_rw) { fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, step + 1, module_conf->animal_dispersal_max_radius - step - 1, eggs_to_deposit, eggs_left); @@ -130,7 +130,6 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts, const cats_dt_population total_adults = get_adult_population(grid, row, col); if (total_adults == 0) return; - ts->rw_debug_cells_with_adults++; 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 // can be safely cast, because gsl_ran_binomial will return a number <= total_adults @@ -167,7 +166,7 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts, assert(stationary_females >= 0); assert(wandering_females >= 0); - + const int64_t stat_id_rw = module_conf->stat_ids[BF_RANDOM_WALK_COUNT]; const int module_id = CATS_MODULE_ID; struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; const bool debug_rw = module_conf->debug_rw; @@ -221,7 +220,8 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts, single_random_walk(ts, grid, row, col, eggs_to_disperse_per_female, egg_fraction_step, rw_number); - ts->rw_debug_random_walks++; + increase_custom_stat(ts->stats, stat_id_rw, 1); + } if (debug_rw) { fflush(module_conf->debug_rw_file); diff --git a/src/modules/butterflies/butterflies_generations.c b/src/modules/butterflies/butterflies_generations.c index 89cedd8e6ccbb38cfb6d42f6b7d4b91d2901d163..116c98f346888edeee7bf9787c2801524909afaf 100644 --- a/src/modules/butterflies/butterflies_generations.c +++ b/src/modules/butterflies/butterflies_generations.c @@ -24,7 +24,7 @@ void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info * const cats_dt_coord end_col = ts->area.end_col; struct statistics *stats = &ts->stats[grid->id]; - const cats_dt_rates ot = grid->param.OT; + const cats_dt_rates suit_ts = module_conf->butterfly_generations.suitability_cutoff; const int64_t egg_cells_id = module_conf->stat_ids[BF_CELLS_WITH_EGGS]; const int64_t egg_cells_removed_id = module_conf->stat_ids[BF_CELLS_WITH_EGGS]; @@ -35,13 +35,13 @@ void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info * for (cats_dt_coord col = start_col; col < end_col; col++) { float eggs = butterflies_get_eggs(data, row, col); - if (get_suitability(grid, row, col) < ot) + + if (get_suitability(grid, row, col) < suit_ts) { if (eggs > 0) cells_with_eggs_removed += 1; butterflies_set_eggs(data, row, col, 0.0f); butterflies_set_generations(data, row, col, 0.0f); set_population_ignore_cc(grid, row, col, 0); - continue; } diff --git a/src/modules/butterflies/butterflies_initial_population.c b/src/modules/butterflies/butterflies_initial_population.c index 37825c033558962610dd612ad24f34416a5be349..9e8bc727191cd541e83307666282f894576711c4 100644 --- a/src/modules/butterflies/butterflies_initial_population.c +++ b/src/modules/butterflies/butterflies_initial_population.c @@ -61,9 +61,6 @@ void bf_initial_population_adjustment(struct cats_configuration *conf, struct ca printf("DEBUG::row %d col %d, suit %Lf, cc multi %Lf, cc raw %Lf, cc %d\n", row, col, suit, multiplier, cc_raw, cc); } } - - - #endif increase_initial_population_to_cc(grid, conf); diff --git a/src/modules/butterflies/butterflies_populations.c b/src/modules/butterflies/butterflies_populations.c index dbbe83b1befbd2f8676f62c88d320198f8eff493..a2654ed81834797d52489fc246cc25b2a609063c 100644 --- a/src/modules/butterflies/butterflies_populations.c +++ b/src/modules/butterflies/butterflies_populations.c @@ -109,6 +109,8 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat const int module_id = CATS_MODULE_ID; struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; + + const float all_eggs = butterflies_get_eggs(data, row, col); if (all_eggs == 0) return; if (all_eggs < 0) { @@ -158,8 +160,9 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat cats_dt_environment suit = get_suitability(grid, row, col); cats_dt_rates reproduction_rate = calculate_rate(&module_conf->reproduction_rate, NAN, &grid->param, grid, row, col, NULL); - if (suit < grid->param.OT && reproduction_rate > 0) { - log_message(LOG_ERROR, "Suitability %f under OT %Lf, but adults per female = %Lf", suit, grid->param.OT, + cats_dt_rates suit_ts = module_conf->reproduction_rate.suitability_cutoff; + if (suit_ts < suit_ts && reproduction_rate > 0) { + log_message(LOG_ERROR, "Suitability %f under threshold %Lf, but adults per female = %Lf", suit, suit_ts, reproduction_rate); exit_cats(EXIT_FAILURE); } diff --git a/src/modules/butterflies/butterflies_stats.c b/src/modules/butterflies/butterflies_stats.c index 20925e9467b81c86abd65d121e3b86430ea1150f..3a866172ba742ed7c2a694e9a6fce3fee392bccb 100644 --- a/src/modules/butterflies/butterflies_stats.c +++ b/src/modules/butterflies/butterflies_stats.c @@ -12,6 +12,7 @@ #include "temporal/phase_names.h" #include "temporal/years.h" + const char *bf_get_stats_field_name(enum butterfly_stats which) { switch (which) { @@ -25,11 +26,9 @@ const char *bf_get_stats_field_name(enum butterfly_stats which) return "unpopulated_unfit"; case BF_STAT_EXCLUDED: return "excluded"; - case BF_STAT_GENERATION_ACTIVE: - return "generation_active"; - case BF_POPULATED_AT_DISPERSAL: - return "populated_at_dispersal"; + case BF_RANDOM_WALK_DEPOSIT_COUNT: + return "random_walk_deposit_count"; case BF_RANDOM_WALK_COUNT: return "random_walk_count"; @@ -37,7 +36,6 @@ const char *bf_get_stats_field_name(enum butterfly_stats which) return "random_walk_step_count"; case BF_OUTPUT_STAT_MAX: return "<guard value>"; - case BF_STAT_MAX: break; case BF_CELLS_WITH_EGGS: @@ -51,6 +49,7 @@ const char *bf_get_stats_field_name(enum butterfly_stats which) exit_cats(EXIT_FAILURE); } + struct string_array *bf_assemble_stats(struct cats_configuration *conf, struct cats_grid *grid, bool header) { struct conf_data_butterflies *module_conf = CATS_MODULE_DATA; @@ -125,6 +124,7 @@ void bf_stats_write(struct cats_configuration *conf, struct cats_grid *grid) free_string_array(&data); } + void bf_area_stats_gather(struct cats_grid *grid, struct cats_thread_info *ts) { struct conf_data_butterflies *module_conf = CATS_MODULE_DATA; @@ -138,7 +138,6 @@ void bf_area_stats_gather(struct cats_grid *grid, struct cats_thread_info *ts) const int64_t id_unpop_unfit = module_conf->stat_ids[BF_STAT_UNPOPULATED_UNFIT]; const int32_t grid_id = grid->id; - //const cats_dt_rates zt = grid->param.ZT; const cats_dt_rates ot = grid->param.OT; struct statistics *stats = &ts->stats[grid_id]; diff --git a/src/modules/butterflies/butterflies_stats.h b/src/modules/butterflies/butterflies_stats.h index 09223497053184c8829e09838263aa2431d1a5f8..7537718b98f3fa814ef15682b0911277624ef51e 100644 --- a/src/modules/butterflies/butterflies_stats.h +++ b/src/modules/butterflies/butterflies_stats.h @@ -13,13 +13,12 @@ enum butterfly_stats { BF_STAT_UNPOPULATED_FIT, BF_STAT_UNPOPULATED_UNFIT, BF_STAT_EXCLUDED, - BF_STAT_GENERATION_ACTIVE, - BF_OUTPUT_STAT_MAX, - BF_POPULATED_AT_DISPERSAL, + BF_RANDOM_WALK_DEPOSIT_COUNT, BF_RANDOM_WALK_COUNT, BF_RANDOM_WALK_STEP_COUNT, BF_CELLS_WITH_EGGS, BF_CELLS_WITH_EGGS_REMOVED, + BF_OUTPUT_STAT_MAX, BF_STAT_MAX };