/** * Returns a text representation of this model. * * @param self the model. * @return a string. */ char * to_string (struct naadsm_model_t_ *self) { GString *s; gboolean already_names; unsigned int i; char *substring, *chararray; local_data_t *local_data; local_data = (local_data_t *) (self->model_data); s = g_string_new (NULL); g_string_append_printf (s, "<%s for ", MODEL_NAME); already_names = FALSE; for (i = 0; i < local_data->production_types->len; i++) if (local_data->production_type[i] == TRUE) { if (already_names) g_string_append_printf (s, ",%s", (char *) g_ptr_array_index (local_data->production_types, i)); else { g_string_append_printf (s, "%s", (char *) g_ptr_array_index (local_data->production_types, i)); already_names = TRUE; } } substring = PDF_dist_to_string (local_data->latent_period); g_string_sprintfa (s, "\n latent-period=%s\n", substring); g_free (substring); substring = PDF_dist_to_string (local_data->infectious_subclinical_period); g_string_sprintfa (s, " infectious-subclinical-period=%s\n", substring); g_free (substring); substring = PDF_dist_to_string (local_data->infectious_clinical_period); g_string_sprintfa (s, " infectious-clinical-period=%s\n", substring); g_free (substring); substring = PDF_dist_to_string (local_data->immunity_period); g_string_sprintfa (s, " immunity-period=%s", substring); g_free (substring); if (local_data->prevalence != NULL) { substring = REL_chart_to_string (local_data->prevalence); g_string_append_printf (s, "\n prevalence=%s", substring); g_free (substring); } g_string_append_c (s, '>'); /* don't return the wrapper object */ chararray = s->str; g_string_free (s, FALSE); return chararray; }
/** * Returns a text representation of this model. * * @param self the model. * @return a string. */ char * to_string (struct ergadm_model_t_ *self) { GString *s; local_data_t *local_data; unsigned int nprod_types, i, j; param_block_t *param_block; char *substring, *chararray; local_data = (local_data_t *) (self->model_data); s = g_string_new (NULL); g_string_printf (s, "<%s", MODEL_NAME); /* Add the parameter block for each to-from combination of production * types. */ nprod_types = local_data->production_types->len; for (i = 0; i < nprod_types; i++) if (local_data->param_block[i] != NULL) for (j = 0; j < nprod_types; j++) if (local_data->param_block[i][j] != NULL) { param_block = local_data->param_block[i][j]; g_string_append_printf (s, "\n for %s -> %s", (char *) g_ptr_array_index (local_data->production_types, i), (char *) g_ptr_array_index (local_data->production_types, j)); g_string_append_printf (s, "\n prob-spread-1km=%g", param_block->prob_spread_1km); g_string_append_printf (s, "\n wind-direction=(%g,%g)", param_block->wind_dir_start, param_block->wind_dir_end); g_string_append_printf (s, "\n max-spread=%g", param_block->max_spread); substring = PDF_dist_to_string (param_block->delay); g_string_append_printf (s, "\n delay=%s", substring); free (substring); } g_string_append_c (s, '>'); /* don't return the wrapper object */ chararray = s->str; g_string_free (s, FALSE); return chararray; }
/** * Computes the size factor for each herd. * * @param herds a list of herds. * @return an array containing the size factor for each herd. */ double * build_size_factor_list (HRD_herd_list_t * herds) { HRD_herd_t *herd; unsigned int nherds; /* number of herds */ unsigned int max_size = 0; /* size of largest herd */ gsl_histogram *histogram; PDF_dist_t *herd_size_dist; double *size_factor; unsigned int i; /* loop counter */ #if DEBUG char *s; #endif #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER build_size_factor_list"); #endif nherds = HRD_herd_list_length (herds); size_factor = g_new (double, nherds); /* Find the largest herd. */ for (i = 0; i < nherds; i++) { herd = HRD_herd_list_get (herds, i); if (herd->size > max_size) max_size = herd->size; } #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "largest herd = %u", max_size); #endif /* Build a histogram with one bin for each herd size. */ histogram = gsl_histogram_alloc (max_size); g_assert (histogram != NULL); gsl_histogram_set_ranges_uniform (histogram, 0.5, (double) max_size + 0.5); for (i = 0; i < nherds; i++) { herd = HRD_herd_list_get (herds, i); gsl_histogram_increment (histogram, (double) (herd->size)); } herd_size_dist = PDF_new_histogram_dist (histogram); g_assert (herd_size_dist != NULL); #if DEBUG s = PDF_dist_to_string (herd_size_dist); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "herd size distribution =\n%s", s); free (s); #endif /* Compute the herd size factors. */ for (i = 0; i < nherds; i++) { herd = HRD_herd_list_get (herds, i); size_factor[i] = PDF_cdf (herd->size, herd_size_dist) * 2; } #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "herd size factors"); for (i = 0; i < nherds; i++) { herd = HRD_herd_list_get (herds, i); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "herd #%u (size %u) = %g", i, herd->size, size_factor[i]); } #endif /* The following line also frees the histogram. */ PDF_free_dist (herd_size_dist); #if DEBUG g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT build_size_factor_list"); #endif return size_factor; }