Ejemplo n.º 1
0
/**
 * Responds to a vaccination event by computing its cost.
 *
 * @param self the model.
 * @param event a vaccination event.
 */
void
handle_vaccination_event (struct naadsm_model_t_ *self, EVT_vaccination_event_t * event)
{
  local_data_t *local_data;
  HRD_herd_t *herd;
  double cost, sum = 0;

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

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

  herd = event->herd;

  if (local_data->vaccination_cost_params &&
      local_data->vaccination_cost_params[herd->production_type])
    {
      vaccination_cost_data_t *params = local_data->vaccination_cost_params[herd->production_type];

      /* Fixed cost for the herd. */
      cost = params->vaccination_fixed;
      RPT_reporting_add_real (local_data->cumul_vaccination_setup_cost, cost, NULL);
      sum += cost;

      /* Per-animal cost. */
      cost = params->vaccination * herd->size;

      if (params->capacity_used > params->baseline_capacity)
        {
          cost += params->extra_vaccination * herd->size;
        }
      else
        {
          params->capacity_used += herd->size;
          if (params->capacity_used > params->baseline_capacity)
            cost += params->extra_vaccination *
              (params->capacity_used - params->baseline_capacity);
        }
      /*
      RPT_reporting_add_real (local_data->vaccination_cost, cost, NULL);
      */
      RPT_reporting_add_real (local_data->cumul_vaccination_cost, cost, NULL);
      sum += cost;

      /*
      RPT_reporting_add_real (local_data->total_cost, cost, NULL);
      */
      RPT_reporting_add_real (local_data->cumul_vaccination_subtotal, sum, NULL);
      RPT_reporting_add_real (local_data->cumul_total_cost, sum, NULL);
    }

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_vaccination_event (%s)", MODEL_NAME);
#endif
}
Ejemplo n.º 2
0
/**
 * Responds to a vaccination event by computing its cost.
 *
 * @param self the model.
 * @param event a vaccination event.
 */
void
handle_vaccination_event (struct ergadm_model_t_ *self, EVT_vaccination_event_t * event)
{
  local_data_t *local_data;
  HRD_herd_t *herd;
  double cost = 0;

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

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

  herd = event->herd;

  if (local_data->production_type[herd->production_type] == TRUE)
    {
      /* Fixed cost for the herd. */
      cost += local_data->vaccination_fixed;

      /* Per-animal cost. */
      cost += local_data->vaccination * herd->size;

      if (local_data->capacity_used > local_data->baseline_capacity)
        {
          cost += local_data->extra_vaccination * herd->size;
        }
      else
        {
          local_data->capacity_used += herd->size;
          if (local_data->capacity_used > local_data->baseline_capacity)
            cost += local_data->extra_vaccination *
              (local_data->capacity_used - local_data->baseline_capacity);
        }

      RPT_reporting_add_real (local_data->vaccination_cost, cost, NULL);
      RPT_reporting_add_real (local_data->total_cost, cost, NULL);
      RPT_reporting_add_real (local_data->cumul_vaccination_cost, cost, NULL);
      RPT_reporting_add_real (local_data->cumul_total_cost, cost, NULL);
    }

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_vaccination_event (%s)", MODEL_NAME);
#endif
}
Ejemplo n.º 3
0
/**
 * Responds to a destruction event by computing its cost.
 *
 * @param self the model.
 * @param event a destruction event.
 */
void
handle_destruction_event (struct naadsm_model_t_ *self, EVT_destruction_event_t * event)
{
  local_data_t *local_data;
  HRD_herd_t *herd;
  unsigned int size;
  double cost, sum = 0;

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

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

  herd = event->herd;
  size = herd->size;

  if (local_data->destruction_cost_params &&
      local_data->destruction_cost_params[herd->production_type])
    {
      destruction_cost_data_t *params = local_data->destruction_cost_params[herd->production_type];

      cost = params->appraisal;
      /* RPT_reporting_add_real (local_data->appraisal_cost, cost, NULL); */
      RPT_reporting_add_real (local_data->cumul_appraisal_cost, cost, NULL);
      sum += cost;

      cost = size * params->euthanasia;
      /* RPT_reporting_add_real (local_data->euthanasia_cost, cost, NULL); */
      RPT_reporting_add_real (local_data->cumul_euthanasia_cost, cost, NULL);
      sum += cost;

      cost = size * params->indemnification;
      /* RPT_reporting_add_real (local_data->indemnification_cost, cost, NULL); */
      RPT_reporting_add_real (local_data->cumul_indemnification_cost, cost, NULL);
      sum += cost;

      cost = size * params->carcass_disposal;
      /* RPT_reporting_add_real (local_data->carcass_disposal_cost, cost, NULL); */
      RPT_reporting_add_real (local_data->cumul_carcass_disposal_cost, cost, NULL);
      sum += cost;

      cost = params->cleaning_disinfecting;
      /* RPT_reporting_add_real (local_data->cleaning_disinfecting_cost, cost, NULL); */
      RPT_reporting_add_real (local_data->cumul_cleaning_disinfecting_cost, cost, NULL);
      sum += cost;

      /* RPT_reporting_add_real (local_data->total_cost, sum, NULL); */
      RPT_reporting_add_real (local_data->cumul_destruction_subtotal, sum, NULL);
      RPT_reporting_add_real (local_data->cumul_total_cost, sum, NULL);
    }

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_destruction_event (%s)", MODEL_NAME);
#endif
}
Ejemplo n.º 4
0
/**
 * Responds to a trace result event by recording it.
 *
 * @param self the model.
 * @param event a trace result event.
 */
void
handle_trace_result_event (struct adsm_module_t_ *self, EVT_trace_result_event_t *event)
{
  local_data_t *local_data;
  UNT_unit_t *identified_unit, *origin_unit;
  UNT_trace_t trace;
  ADSM_contact_type contact_type;
  UNT_production_type_t prodtype;
  double nanimals;

  #if DEBUG
    g_debug ("----- ENTER handle_trace_result_event (%s)", MODEL_NAME);
  #endif

  identified_unit = (event->direction == ADSM_TraceForwardOrOut) ? event->exposed_unit : event->exposing_unit;
  origin_unit = (event->direction == ADSM_TraceForwardOrOut) ? event->exposing_unit : event->exposed_unit; 
  
  /* Record the trace in the GUI */
  /* --------------------------- */
  trace.day = (int) event->day;
  trace.initiated_day = (int) event->initiated_day;
  
  trace.identified_index = identified_unit->index;
  trace.identified_state = (ADSM_disease_state) identified_unit->state;
  
  trace.origin_index = origin_unit->index; 
  trace.origin_state = (ADSM_disease_state) origin_unit->state;
  
  trace.trace_type = event->direction;
  trace.contact_type = event->contact_type;
  if (trace.contact_type != ADSM_DirectContact
      && trace.contact_type != ADSM_IndirectContact)
    {
      g_error( "Bad contact type in contact-recorder-model.attempt_trace_event" );
      trace.contact_type = 0;
    }

  if( TRUE == event->traced )
    trace.success = ADSM_SuccessTrue;
  else
    trace.success = ADSM_SuccessFalse; 

  #ifdef USE_SC_GUILIB
    sc_trace_unit( event->exposed_unit, trace );
  #else
    if (NULL != adsm_trace_unit)
      adsm_trace_unit (trace);
  #endif


  /* Record the trace in the SC version */
  /* ---------------------------------- */
  local_data = (local_data_t *) (self->model_data);
  

  /* Record a potentially traced contact. */

  contact_type = event->contact_type;
  prodtype = identified_unit->production_type;
  nanimals = (double)(identified_unit->size);

  RPT_reporting_add_integer (local_data->nunits_potentially_traced, 1);
  RPT_reporting_add_integer (local_data->nunits_potentially_traced_by_contacttype[contact_type], 1);
  RPT_reporting_add_integer (local_data->nunits_potentially_traced_by_prodtype[prodtype], 1);
  RPT_reporting_add_integer (local_data->nunits_potentially_traced_by_contacttype_and_prodtype[contact_type][prodtype], 1);
  RPT_reporting_add_integer (local_data->cumul_nunits_potentially_traced, 1);
  RPT_reporting_add_integer (local_data->cumul_nunits_potentially_traced_by_contacttype[contact_type], 1);
  RPT_reporting_add_integer (local_data->cumul_nunits_potentially_traced_by_prodtype[prodtype], 1);
  RPT_reporting_add_integer (local_data->cumul_nunits_potentially_traced_by_contacttype_and_prodtype[contact_type][prodtype], 1);
  RPT_reporting_add_real (local_data->nanimals_potentially_traced, nanimals);
  RPT_reporting_add_real (local_data->nanimals_potentially_traced_by_contacttype[contact_type], nanimals);
  RPT_reporting_add_real (local_data->nanimals_potentially_traced_by_prodtype[prodtype], nanimals);
  RPT_reporting_add_real (local_data->nanimals_potentially_traced_by_contacttype_and_prodtype[contact_type][prodtype], nanimals);
  RPT_reporting_add_real (local_data->cumul_nanimals_potentially_traced, nanimals);
  RPT_reporting_add_real (local_data->cumul_nanimals_potentially_traced_by_contacttype[contact_type], nanimals);
  RPT_reporting_add_real (local_data->cumul_nanimals_potentially_traced_by_prodtype[prodtype], nanimals);
  RPT_reporting_add_real (local_data->cumul_nanimals_potentially_traced_by_contacttype_and_prodtype[contact_type][prodtype], nanimals);

  if (event->traced == TRUE)
    {
      /* Record a successfully traced contact. */

      RPT_reporting_add_integer (local_data->nunits_traced, 1);
      RPT_reporting_add_integer (local_data->nunits_traced_by_contacttype[contact_type], 1);
      RPT_reporting_add_integer (local_data->nunits_traced_by_prodtype[prodtype], 1);
      RPT_reporting_add_integer (local_data->nunits_traced_by_contacttype_and_prodtype[contact_type][prodtype], 1);
      RPT_reporting_add_integer (local_data->cumul_nunits_traced, 1);
      RPT_reporting_add_integer (local_data->cumul_nunits_traced_by_contacttype[contact_type], 1);
      RPT_reporting_add_integer (local_data->cumul_nunits_traced_by_prodtype[prodtype], 1);
      RPT_reporting_add_integer (local_data->cumul_nunits_traced_by_contacttype_and_prodtype[contact_type][prodtype], 1);
      RPT_reporting_add_real (local_data->nanimals_traced, nanimals);
      RPT_reporting_add_real (local_data->nanimals_traced_by_contacttype[contact_type], nanimals);
      RPT_reporting_add_real (local_data->nanimals_traced_by_prodtype[prodtype], nanimals);
      RPT_reporting_add_real (local_data->nanimals_traced_by_contacttype_and_prodtype[contact_type][prodtype], nanimals);
      RPT_reporting_add_real (local_data->cumul_nanimals_traced, nanimals);
      RPT_reporting_add_real (local_data->cumul_nanimals_traced_by_contacttype[contact_type], nanimals);
      RPT_reporting_add_real (local_data->cumul_nanimals_traced_by_prodtype[prodtype], nanimals);
      RPT_reporting_add_real (local_data->cumul_nanimals_traced_by_contacttype_and_prodtype[contact_type][prodtype], nanimals);
    }

  #if DEBUG
    g_debug ("----- EXIT handle_trace_result_event (%s)", MODEL_NAME);
  #endif
}
Ejemplo n.º 5
0
/**
 * Responds to a new day event by updating the reporting variables.
 *
 * @param self the model.
 * @param herds a list of herds.
 * @param zones a list of zones.
 * @param event a new day event.
 */
void
handle_new_day_event (struct naadsm_model_t_ *self, HRD_herd_list_t * herds,
                      ZON_zone_list_t * zones, EVT_new_day_event_t * event)
{
  local_data_t *local_data = (local_data_t *) (self->model_data);

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

  /* Zero the daily counts. */
  /*
  RPT_reporting_zero (local_data->total_cost);
  RPT_reporting_zero (local_data->appraisal_cost);
  RPT_reporting_zero (local_data->euthanasia_cost);
  RPT_reporting_zero (local_data->indemnification_cost);
  RPT_reporting_zero (local_data->carcass_disposal_cost);
  RPT_reporting_zero (local_data->cleaning_disinfecting_cost);
  RPT_reporting_zero (local_data->vaccination_cost);
  RPT_reporting_zero (local_data->surveillance_cost);
  */

  /* This is an expensive cost calculation, so only do it if the user
   * will see any benefit from it. */
  if ((local_data->surveillance_cost_param) &&
      (/*(local_data->surveillance_cost->frequency != RPT_never ) ||
       (local_data->total_cost->frequency != RPT_never) ||*/
       (local_data->cumul_surveillance_cost->frequency != RPT_never ) ||
       (local_data->cumul_total_cost->frequency != RPT_never)))
    {
      double **surveillance_cost_param = local_data->surveillance_cost_param;
      unsigned int nherds = zones->membership_length;
      unsigned int i;
      double cost = 0;
      
      for (i = 0; i < nherds; i++)
        {
          ZON_zone_t *zone = zones->membership[i]->parent;
          unsigned int zone_index = zone->level - 1;
          HRD_herd_t *herd = HRD_herd_list_get (herds, i);

          if (surveillance_cost_param[zone_index] &&
              /* TODO.  This should probably be the authority's view
               * of whether the herd has been destroyed or not. */
              (herd->status != Destroyed))
            {
              cost =
                surveillance_cost_param[zone_index][herd->production_type] *
                (double) (herd->size);
              /*
              RPT_reporting_add_real (local_data->surveillance_cost, cost, NULL);
              RPT_reporting_add_real (local_data->total_cost, cost, NULL);
              */
              RPT_reporting_add_real (local_data->cumul_surveillance_cost, cost, NULL);
              RPT_reporting_add_real (local_data->cumul_total_cost, cost, NULL);
            }
        }
    }

#if DEBUG
  g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "----- EXIT handle_new_day_event (%s)", MODEL_NAME);
#endif
}
Ejemplo n.º 6
0
/**
 * Responds to an exposure event by recording it.
 *
 * @param self the model.
 * @param event an exposure event.
 */
void
handle_exposure_event (struct adsm_module_t_ *self, EVT_exposure_event_t * event)
{
  local_data_t *local_data;
  UNT_unit_t *exposing_unit, *exposed_unit;
  UNT_expose_t update;
  ADSM_contact_type cause;
  UNT_production_type_t prodtype;
  double nanimals;
  
#if DEBUG
  g_debug ("----- ENTER handle_exposure_event (%s)", MODEL_NAME);
#endif

  local_data = (local_data_t *) (self->model_data);
  exposing_unit = event->exposing_unit;
  exposed_unit = event->exposed_unit;

  cause = event->contact_type;
                                
  /* No exposing unit means this is an initially infected unit. */
  if (exposing_unit != NULL)
    {
      update.src_index = exposing_unit->index;
      update.src_state = (ADSM_disease_state) exposing_unit->state;
      update.dest_index = exposed_unit->index;
      update.dest_state = (ADSM_disease_state) exposed_unit->state;
  
      update.initiated_day = (int) event->initiated_day;
      update.finalized_day = (int) event->initiated_day + event->delay;
  
      if( TRUE == event->adequate )
        update.is_adequate = ADSM_SuccessTrue;
      else
        update.is_adequate = ADSM_SuccessFalse;
  
      switch (event->contact_type)
        {
          case ADSM_DirectContact:
          case ADSM_IndirectContact:
          case ADSM_AirborneSpread:
            update.exposure_method = event->contact_type;
            break;      
          default:
            /* If this condition occurs, someone forgot something. */
            g_error( "An unrecognized exposure mechanism (%s) occurred in handle_exposure_event", cause );
            update.exposure_method = 0;     
        }

    #ifdef USE_SC_GUILIB
      sc_expose_unit( exposed_unit, update );
    #else	  
      if (NULL != adsm_expose_unit)
        {
          adsm_expose_unit (update);
        }
    #endif  

    #if UNDEFINED
      printf ("unit at index %d exposed by method %s\n", event->exposed_unit->index, cause);
    #endif

      /* Update the counts of exposures. */
      prodtype = exposed_unit->production_type;
      nanimals = (double)(exposed_unit->size);
      RPT_reporting_add_integer (local_data->num_units_exposed, 1);
      RPT_reporting_add_integer (local_data->num_units_exposed_by_cause[cause], 1);
      RPT_reporting_add_integer (local_data->num_units_exposed_by_prodtype[prodtype], 1);
      RPT_reporting_add_integer (local_data->num_units_exposed_by_cause_and_prodtype[cause][prodtype], 1);
      RPT_reporting_add_real (local_data->num_animals_exposed, nanimals);
      RPT_reporting_add_real (local_data->num_animals_exposed_by_cause[cause], nanimals);
      RPT_reporting_add_real (local_data->num_animals_exposed_by_prodtype[prodtype], nanimals);
      RPT_reporting_add_real (local_data->num_animals_exposed_by_cause_and_prodtype[cause][prodtype], nanimals);
      RPT_reporting_add_integer (local_data->cumul_num_units_exposed, 1);
      RPT_reporting_add_integer (local_data->cumul_num_units_exposed_by_cause[cause], 1);
      RPT_reporting_add_integer (local_data->cumul_num_units_exposed_by_prodtype[prodtype], 1);
      RPT_reporting_add_integer (local_data->cumul_num_units_exposed_by_cause_and_prodtype[cause][prodtype], 1);
      RPT_reporting_add_real (local_data->cumul_num_animals_exposed, nanimals);
      RPT_reporting_add_real (local_data->cumul_num_animals_exposed_by_cause[cause], nanimals);
      RPT_reporting_add_real (local_data->cumul_num_animals_exposed_by_prodtype[prodtype], nanimals);
      RPT_reporting_add_real (local_data->cumul_num_animals_exposed_by_cause_and_prodtype[cause][prodtype], nanimals);
      if (event->adequate)
        {
          RPT_reporting_add_integer (local_data->num_adequate_exposures, 1);
          RPT_reporting_add_integer (local_data->cumul_num_adequate_exposures, 1);
          RPT_reporting_add_integer (local_data->cumul_num_adequate_exposures_by_cause[cause], 1);
        }
    }

#if DEBUG
  g_debug ("----- EXIT handle_exposure_event (%s)", MODEL_NAME);
#endif
}
Ejemplo n.º 7
0
/**
 * Responds to a vaccination by recording it.
 *
 * @param self the model.
 * @param event a vaccination event.
 */
void
handle_vaccination_event (struct adsm_module_t_ *self, EVT_vaccination_event_t * event)
{
  local_data_t *local_data;
  UNT_unit_t *unit;
  UNT_control_t update;
  ADSM_control_reason reason;
  UNT_production_type_t prodtype;
  double nanimals;
  
#if DEBUG
  g_debug ("----- ENTER handle_vaccination_event (%s)", MODEL_NAME);
#endif 
  
  local_data = (local_data_t *) (self->model_data);
  unit = event->unit;

  update.unit_index = unit->index;
  update.day_commitment_made = event->day_commitment_made;
  update.reason = event->reason;
  
#ifdef USE_SC_GUILIB
  sc_vaccinate_unit( event->day, unit, update );
#else  
  if (NULL != adsm_vaccinate_unit)
    {
      adsm_vaccinate_unit (update);
    }
#endif  

  reason = event->reason;
  prodtype = unit->production_type;
  nanimals = (double)(unit->size);
  
  /* Initially vaccinated units do not count as the first vaccination. */
  if (event->reason != ADSM_ControlInitialState)
    {
      if (local_data->first_vaccination->is_null)
        {
          RPT_reporting_set_integer (local_data->first_vaccination, event->day);
          RPT_reporting_set_integer (local_data->vaccination_occurred, 1);
        }
      if (local_data->first_vaccination_by_reason[reason]->is_null)
        RPT_reporting_set_integer (local_data->first_vaccination_by_reason[reason], event->day);
      if (local_data->first_vaccination_by_prodtype[prodtype]->is_null)
        RPT_reporting_set_integer (local_data->first_vaccination_by_prodtype[prodtype], event->day);  
      if (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype]->is_null)
        RPT_reporting_set_integer (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype], event->day);

      /* Initially vaccinated units also are not included in many of the
       * counts.  They will not be part of vacnU or vacnU broken down by
       * production type.  They will be part of vacnUIni and vacnUIni broken
       * down by production type. */
      RPT_reporting_add_integer (local_data->num_units_vaccinated, 1);
      RPT_reporting_add_integer (local_data->num_units_vaccinated_by_prodtype[prodtype], 1);
      RPT_reporting_add_real (local_data->num_animals_vaccinated, nanimals);
      RPT_reporting_add_real (local_data->num_animals_vaccinated_by_prodtype[prodtype], nanimals);
      RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated, 1);
      RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_prodtype[prodtype], 1);
      RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated, nanimals);
      RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_prodtype[prodtype], nanimals);
    }
  RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason[reason], 1);
  RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason[reason], nanimals);
  RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason[reason], 1);
  RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason[reason], nanimals);
  RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1);
  RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals);
  RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1);
  RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals);

#if DEBUG
  g_debug ("----- EXIT handle_vaccination_event (%s)", MODEL_NAME);
#endif
}