예제 #1
0
/**
 * Frees this model.  Does not free the production type names.
 *
 * @param self the model.
 */
void
local_free (struct naadsm_model_t_ *self)
{
  local_data_t *local_data;

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER free (%s)", MODEL_NAME);
#endif

  /* Free the dynamically-allocated parts. */
  local_data = (local_data_t *) (self->model_data);
  g_free (local_data->production_type);
  PDF_free_dist (local_data->latent_period);
  PDF_free_dist (local_data->infectious_subclinical_period);
  PDF_free_dist (local_data->infectious_clinical_period);
  PDF_free_dist (local_data->immunity_period);
  if (local_data->prevalence != NULL)
    REL_free_chart (local_data->prevalence);
  g_free (local_data);
  g_ptr_array_free (self->outputs, TRUE);
  g_free (self);

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT free (%s)", MODEL_NAME);
#endif
}
예제 #2
0
/**
 * Frees this model.  Does not free the production type names.
 *
 * @param self the model.
 */
void
local_free (struct ergadm_model_t_ *self)
{
  local_data_t *local_data;
  unsigned int nprod_types, i, j;
  GQueue *q;
  param_block_t *param_block;

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- ENTER free (%s)", MODEL_NAME);
#endif

  local_data = (local_data_t *) (self->model_data);

  /* Free each of the parameter blocks. */
  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];
              /* Free the dynamically-allocated parts of the parameter block. */
              PDF_free_dist (param_block->delay);
              /* Free the parameter block itself. */
              g_free (param_block);
            }
        /* Free this row of the 2D array. */
        g_free (local_data->param_block[i]);
      }
  /* Free the array of pointers to rows. */
  g_free (local_data->param_block);

  g_free (local_data->max_spread);
  g_free (local_data->use_rtree_index);
  g_free (local_data->herd_size_factor);

  for (i = 0; i < local_data->pending_infections->len; i++)
    {
      q = (GQueue *) g_ptr_array_index (local_data->pending_infections, i);
      while (!g_queue_is_empty (q))
        EVT_free_event (g_queue_pop_head (q));
      g_queue_free (q);
    }
  g_ptr_array_free (local_data->pending_infections, TRUE);

  g_free (local_data);
  g_ptr_array_free (self->outputs, TRUE);
  g_free (self);

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT free (%s)", MODEL_NAME);
#endif
}
예제 #3
0
/**
 * 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;
}