https://github.com/PublicHealthDynamicsLab/FRED
Revision a45e04ad99c865724a3c2b1a2d3fd979b3c6be88 authored by John Grefenstette on 07 January 2016, 16:32:02 UTC, committed by John Grefenstette on 07 January 2016, 16:32:02 UTC
1 parent 9bc2dce
Raw File
Tip revision: a45e04ad99c865724a3c2b1a2d3fd979b3c6be88 authored by John Grefenstette on 07 January 2016, 16:32:02 UTC
working markov epidemic model
Tip revision: a45e04a
Antiviral.cc
/*
  This file is part of the FRED system.

  Copyright (c) 2010-2015, University of Pittsburgh, John Grefenstette,
  Shawn Brown, Roni Rosenfield, Alona Fyshe, David Galloway, Nathan
  Stone, Jay DePasse, Anuroop Sriram, and Donald Burke.

  Licensed under the BSD 3-Clause license.  See the file "LICENSE" for
  more information.
*/

//
//
// File: Antiviral.cc
//

#include <iomanip>

#include "Antiviral.h"
#include "AV_Health.h"
#include "Random.h"
#include "Person.h"
#include "Health.h"
#include "Infection.h"
#include "Disease.h"
#include "Disease_List.h"
#include "Global.h"
#include "Population.h"

Antiviral::Antiviral(int _disease, int _course_length, double _reduce_infectivity,
                     double _reduce_susceptibility, double _reduce_asymp_period,
                     double _reduce_symp_period, double _prob_symptoms,
                     int _initial_stock, int _total_avail, int _additional_per_day,
                     double _efficacy, double* _av_course_start_day,
                     int _max_av_course_start_day, int _start_day, bool _prophylaxis,
                     double _percent_symptomatics) {
  disease                        = _disease;
  course_length                 = _course_length;
  reduce_infectivity            = _reduce_infectivity;
  reduce_susceptibility         = _reduce_susceptibility;
  reduce_asymp_period           = _reduce_asymp_period;
  reduce_symp_period            = _reduce_symp_period;
  prob_symptoms                 = _prob_symptoms;
  stock                         = _initial_stock;
  initial_stock                 = _initial_stock;
  reserve                       = _total_avail - _initial_stock;
  total_avail                   = _total_avail;
  additional_per_day            = _additional_per_day;
  efficacy                      = _efficacy;
  av_course_start_day           = _av_course_start_day;
  max_av_course_start_day       = _max_av_course_start_day;
  start_day                     = _start_day;
  prophylaxis                   = _prophylaxis;
  percent_symptomatics          = _percent_symptomatics;
}

int Antiviral::roll_will_have_symp() const {
  return (Random::draw_random() < prob_symptoms);
}

int Antiviral::roll_efficacy() const {
  return (Random::draw_random() < efficacy);
}

int Antiviral::roll_course_start_day() const {
  int days = 0;
  days = Random::draw_from_distribution(max_av_course_start_day, av_course_start_day);
  return days;
}

void Antiviral::update(int day) {
  if(day >= start_day) add_stock(additional_per_day);
}

void Antiviral::print() const {
  cout << "\tEffective for Disease \t\t"<< disease << "\n";
  cout << "\tCurrent Stock:\t\t\t"<<stock<< " out of "<< total_avail << "\n";
  cout << "\tWhat is left:\t\t\t"<< reserve << "\n";
  cout << "\tAdditional Per Day: \t\t"<< additional_per_day << "\n";
  //cout << "\tPercent Resistance\t\t"<<efficacy << "\n";
  cout << "\tReduces by:" << "\n";
  cout << "\t\tInfectivity:\t\t"<<reduce_infectivity*100.0 << "%\n";
  cout << "\t\tSusceptibility:\t\t"<<reduce_susceptibility*100.0 << "%\n";
  cout << "\t\tAymptomatic Period:\t" << reduce_asymp_period*100.0 << "%\n";
  cout << "\t\tSymptomatic Period:\t" << reduce_symp_period*100.0 << "%\n";
  cout << "\tNew Probability of symptoms:\t" << prob_symptoms << "\n";

  if(prophylaxis==1)
    cout <<"\tCan be given as prophylaxis" << "\n";

  if(percent_symptomatics != 0)
    cout << "\tGiven to percent symptomatics:\t" << percent_symptomatics*100.0 << "%\n";

  cout << "\n\tAV Course start day (max " << max_av_course_start_day << "):";

  for (int i = 0; i <= max_av_course_start_day; i++) {
    if((i%5)==0) cout << "\n\t\t";

    cout << setw(10) << setprecision(6) <<av_course_start_day[i] << " ";
  }

  cout << "\n";
}

void Antiviral::reset() {
  stock = initial_stock;
  reserve = total_avail-initial_stock;
}

void Antiviral::print_stocks() const {
  cout << "Current: "<< stock << " Reserve: "<<reserve << " TAvail: "<< total_avail << "\n";
}

void Antiviral::report(int day) const {
  //STB - Need add a report utility
  cout << "\nNeed to write a report function";
}


int Antiviral::quality_control(int ndiseases) const {
  // Currently, this checks the parsing of the AVs, and it returns 1 if there is a problem
  if(disease < 0 || disease > ndiseases ) {
    cout << "\nAV disease invalid,cannot be higher than "<< ndiseases << "\n";
    return 1;
  }

  if(initial_stock < 0) {
    cout <<"\nAV initial_stock invalid, cannot be lower than 0\n";
    return 1;
  }

  if(efficacy>100 || efficacy < 0) {
    cout << "\nAV Percent_Resistance invalid, must be between 0 and 100\n";
    return 1;
  }

  if(course_length < 0) {
    cout << "\nAV Course Length invalid, must be higher than 0\n";
    return 1;
  }

  if(reduce_infectivity < 0 || reduce_infectivity > 1.00) {
    cout << "\nAV reduce_infectivity invalid, must be between 0 and 1.0\n";
    return 1;
  }

  if(reduce_susceptibility < 0 || reduce_susceptibility > 1.00) {
    cout << "\nAV reduce_susceptibility invalid, must be between 0 and 1.0\n";
    return 1;
  }

  if(reduce_infectious_period < 0 || reduce_infectious_period > 1.00) {
    cout << "\nAV reduce_infectious_period invalid, must be between 0 and 1.0; is equal to: " << reduce_infectious_period << "\n";
    //return 1;
    //  TODO: Help!!!  This is never set - just contains whatever garbage present at the address.
  }

  return 0;
}

void Antiviral::effect(Health *health, int cur_day, AV_Health* av_health) {
  // We need to calculate the effect of the AV on all diseases it is applicable to
  for (int disease_id = 0; disease_id < Global::Diseases.get_number_of_diseases(); disease_id++) {
    if(disease_id == this->disease) { //Is this antiviral applicable to this disease
      Disease *dis = Global::Diseases.get_disease(disease_id);
      avEffect(health, disease, cur_day, av_health);
    }
  }
}

void Antiviral::modify_susceptiblilty(Health *health, int disease) {
  health->modify_susceptibility(disease,1.0-reduce_susceptibility);
}

void Antiviral::modify_infectivity(Health *health, int disease) {
  health->modify_infectivity(disease,1.0-reduce_infectivity);
}

void Antiviral::modify_symptomaticity(Health *health, int disease, int cur_day) {
  if (!health->is_symptomatic() && cur_day < health->get_symptoms_start_date(disease)) {
    // Can only have these effects if the agent is not symptomatic yet
    health->modify_develops_symptoms(disease, roll_will_have_symp(), cur_day);
  }

  if (!health->is_symptomatic() && cur_day < health->get_symptoms_start_date(disease)) {
    health->modify_asymptomatic_period(disease, 1.0-reduce_asymp_period,cur_day);
  }

  if (health->is_symptomatic() && cur_day < health->get_infectious_end_date(disease)) {
    health->modify_symptomatic_period(disease, 1.0-reduce_symp_period,cur_day);
  }
}

void Antiviral::avEffect(Health *health, int disease, int cur_day, AV_Health *av_health) {
  // If this is the first day of AV Course
  if(cur_day == av_health->get_av_start_day()) {
    modify_susceptiblilty(health, disease);

    // If you are already exposed, we need to modify your infection
    if((health->get_exposure_date(disease) > -1) && (cur_day > health->get_exposure_date(disease))) {
      if(Global::Debug > 3) cout << "reducing an already exposed person\n";

      modify_infectivity(health, disease);
      //modify_symptomaticity(health, disease, cur_day);
    }
  }

  // If today is the day you got exposed, prophilaxis
  if(cur_day == health->get_exposure_date(disease)) {
    if(Global::Debug > 3) cout << "reducing agent on the day they are exposed\n";

    modify_infectivity(health, disease);
    modify_symptomaticity(health, disease, cur_day);
  }

  // If this is the last day of the course
  if(cur_day == av_health->get_av_end_day()) {
    if(Global::Debug > 3) cout << "resetting agent to original state\n";

    modify_susceptiblilty(health, disease);

    if(cur_day >= health->get_exposure_date(disease)) {
      modify_infectivity(health, disease);
    }
  }
}
back to top