+1 (315) 557-6473 

How to simulate an infectious outbreak

Simulation is one of the areas taught in the school of programming. In this sample assignment, we explain how to simulate an infectious outbreak to help you understand the concept of simulation better.

Simulation of infectious outbreak

Program 2: Outbreak Model

Instructions

For this program you will be implementing an outbreak model in C or C++. Specifically, you will be creating an agentbased model of a flu outbreak in an island nation. You will need to come up with a way to represent each individual, oneach island, and their respective health status: Healthy, Infected, Infectious, and Recovered. Your program should beable to read in multiple user defined parameters from the terminal and/or from a file, and output the outbreak’s
progress over time in a consistent, understandable format.

Disease Modeling Basics

Some of the key parts of modeling many diseases are how to model the transmission of a disease from person toperson, and how to represent the disease characteristics. To start, representing a transmission is based on two factors,contacts and a transmission probability. In this model, each individual will have a set number of contacts they can makewith other individuals every day. When two individuals make a contact, one of two things can happen based on theirhealth status:
1. If one individual is Infectious and the other is Healthy, then both individuals expend a contact and there is apossible transmission of disease from the Infectious individual to the Healthy one.
2. All other cases result in both individuals expending a contact and no transmission occurring.
An additional part of the model is how to represent the disease itself. First, we need to represent the infectious period,or how many days someone remains Infectious before becoming Recovered. Next, we need to represent the infectedperiod, or how many days after someone is Infected they become Infectious. We also assume that once a person has
recovered from the disease they are permanently immune and can never be reinfected. Additionally, a number ofrandomly selected individuals must be initially Infectious at the outset of the model for the disease to begin spreading.
Further, the population itself needs to be modeled in such a way that each individual is represented, rather thanrepresenting the population as a total count. We assume that because the outbreak will not last sufficiently long, thehuman population total will not change during the model. Since this is an island nation, we assume that people can onlymake contacts with other individuals on the same island each day. We also assume that every day a certain number ofpeople travel from island to island via ferry or airplane. For the purposes of this model we will assume travel time isrelatively small and thus people move instantly from one island to another, though an individual may only move onceper day.
As an example, we could set the model parameters to:
·The infected period is 3 days
·The infectious period is 5 days
·The transmission probability is a 10% chance of a successful transmission during a contact
·The maximum number of contacts each person can make every day is 5
·10 randomly selected people are infectious at the beginning of the model

Requirements

For the most part you are free to design and program the model how you wish, so long as it adheres to the followingconstraints:
·A person must be represented as an individual
·The health status of each individual must be maintained throughout the modeling process
·People can only make contacts with other people on the same island
·The number of islands and the total population must be defined by the user before the simulation can start
o You can either allow the user to define the population for each island, or have your program
automatically distribute the defined total population across the islands in some way
·The transit routes and rates from each island must be defined by the user before the simulation can start
·The user must be able to configure the number of contacts individuals make every day, the transmissionprobability, the infected period, the infectious period, and the initial number of infectious individuals
·The model should output, perhaps to a file and/or the terminal, the total number of Healthy, Infected,Infectious, and Recovered individuals, across the entire island nation, for each day
·Your code must be well commented
·You must provide a short README.txt file which includes your name and explains how to compile and run yourprogram. This should include how to input model configuration data such as the population, the transit routesand rates, and the disease parameters.

For the design portion, you must generate documentation describing your program. You might consider including thingssuch as detailed explanations of your various functions and algorithms, how information is stored and is modified,and/or justifications of your design decisions. Diagrams are also an effective way to convey information, provided they
also have some description of what is being diagramed. This documentation must be provided along with your programand should be thorough.

#include

using namespace std;

intTotalPop;

intNumIsland;

intIslandRoutesNum;

intIslandPop;

intPeopleRoutesNum;

intContactsNum;

floatTransmissionProb;

intInfectedPeriod;

intInfectiousPeriod;

intInitialInfectious;

intInitialRecovered;

intInitialInfected;

void Healthy(){

cout<

void Infected(){

cout<

void Infectious(){

cout<

void Recovered(){

cout<

void Day(){

for(int day = 1, InitialInfected = 0; day

cout<< day;

Healthy();

Infected();

Infectious();

Recovered();

}

int main ()

{

cout<< “Enter total population of island nation: ” ;

cin>>TotalPop;

cout<< “Enter number of islands: ” ;

cin>>NumIsland;

IslandPop = TotalPop/NumIsland;

cout<< “Enter the number of routes between islands: ” ;

cin>>IslandRoutesNum;

cout<< “Enter the number of people that can travel on each route: “;

cin>>PeopleRoutesNum;

cout<< “Enter the number of contacts made each day: “;

cin>>ContactsNum;

cout<< “Enter the Transmission Probability(in decimal format 0.00): “;

cin>>TransmissionProb;

cout<< “Enter the Infected Period: “;

cin>>InfectedPeriod;

cout<< “Enter the Infectious Period: “;

cin>>InfectiousPeriod;

cout<< “Enter the initial number of infectious individuals: “;

cin>>InitialInfectious;

cout<< “DAY ” << “HEALTHY ” << “INFECTED ” << “INFECTIOUS ” << “RECOVERED ” <

Day();

return 0;

}

Solution 

person.cpp 

#include

#include “person.h”

//Method that gets the health status of the person

int Person::get_health () {

returnhealth_status;

}

//Method that sets the health status of the person

void Person::set_health (intnew_health_status) {

health_status = new_health_status;

}

//Method that handles the infection of the person

void Person::infect (float probability) {

if (rand()%100 + 1 <= probability*100)

if (health_status == 0) health_status = 1;

}

//Method that applies the effects of a day passing to the person

void Person::pass_day (intDiseasePer) {

if (health_status != 0 &&health_status != DiseasePer) health_status++;

}

//Method that gets the island where the islander is located

void Person::set_island (intisl) {

island = isl;

}

//Method that sets the island where the islander is located

int Person::get_island () {

return island;

}

//Method that gets how many contacts the person still has to do for the day

int Person::get_contacts () {

return contacts;

}

//Method that gets how many contacts the person still has to do for the day

void Person::set_contacts(intcnt) {

contacts = cnt;


person.h 

#ifndef PERSON_H

#define PERSON_H

class Person {

private:

inthealth_status; //Attribute that tells if a person is Healthy, Infected, Infectious or Recovered

int island; //Attribute that tells the island where the islander is

int contacts; //Attribute that tells how much contacts the person has left to do during the day

public:

intget_health(); //Method that gets the health status of the person

voidset_health(int); //Method that sets the health status of the person

void infect(float); //Method that handles the infection of the person

voidpass_day(int); //Method that applies the effects of a day passing to the person

intget_island(); //Method that gets the island where the islander is located

voidset_island(int); //Method that sets the island where the islander is located

intget_contacts(); //Method that gets how many contacts the person still has to do for the day

voidset_contacts(int); //Method that gets how many contacts the person still has to do for the day

};

#endif 

proghw2take3.cpp 

#include

#include

#include

#include

#include

#include “person.h”

using namespace std;

/*

intTotalPop;

intNumIsland;

intIslandRoutesNum;

intIslandPop;

intPeopleRoutesNum;

intContactsNum;

floatTransmissionProb;

intInfectedPeriod;

intInfectiousPeriod;

intInitialInfectious;

intInitialRecovered;

intInitialInfected;

void Healthy(){

cout<

void Infected(){

cout<

void Infectious(){

cout<

void Recovered(){

cout<

void Day(){

for(int day = 1, InitialInfected = 0; day

cout<< day;

Healthy();

Infected();

Infectious();

Recovered();

}

*/

//Function that handles user input

intget_input (string output) {

int ret;

while (true) {

string input;

cout<< output ;

getline(cin, input);

//cout<< input <

stringstreammyStream(input);

if (myStream>> ret && ret >= 0) break;

 

cout<< “Error! Please try again.” <

}

return ret;

}

voidprint_situation (Person people[], intTotalPop, intInfecPer, intInfectiousPer, intday_counter) {

int Healthy = 0, Infected = 0, Infectious=0, Recovered=0, i;

for (i=0; i

if (people[i].get_health() == 0) Healthy++;

else if (people[i].get_health() > 0 && people[i].get_health() <= InfecPer) Infected++;

else if (people[i].get_health() >InfecPer&& people[i].get_health() <= InfectiousPer + InfecPer) Infectious++;

else Recovered++;

}

cout<

for (i=1; day_counter>= 10; i++) day_counter /= 10;

for (i= -(3 – i); i<6; i++) cout<< ” “;

cout<< Healthy;

for (i=1; Healthy >= 10; i++) Healthy /= 10;

for (i= -(7 – i); i<6; i++) cout<< ” “;

cout<< Infected;

for (i=1; Infected >= 10; i++) Infected /= 10;

for (i= -(8 – i); i<6; i++) cout<< ” “;

cout<< Infectious;

for (i=1; Infectious >= 10; i++) Infectious/= 10;

for (i= -(10 – i); i<6; i++) cout<< ” “;

cout<< Recovered <

/*

cout<< “Healthy : ” << Healthy <

cout<< “Infected : ” << Infected <

cout<< “Infectious : ” << Infectious <

cout<< “Recovered : ” << Recovered <

*/

}

int main ()

{

srand(time(NULL));

inti,j;

intTotalPop = get_input(“Enter total population of island nation: “);

intNumIsland = get_input(“Enter number of islands: ” );

Person people[TotalPop];

//Initializing people with health_status’ of 0 and a random island

for (i=0; i

people[i].set_health(0);

people[i].set_island(i%NumIsland + 1);

//cout<< “Health: ” << people[i].get_health() << “; “;

//cout<< “Island: ” << people[i].get_island() <

}

//Getting the time a person stays infected

intInfecPer = get_input(“Enter the Infected Period: “);

//Getting the time a person stays infectious

intInfectiousPer = get_input(“Enter the Infectious Period: “);

//intNumInfected = 0;

intNumInfectious = 0;

//Getting the numer of people who are infected at the beginning (if the period of staying infected is 0 then no people are infected at the beginning)

//if (InfecPer> 0) NumInfected = get_input(“Enter the amount of people infected: “);

//Getting the numer of people who are infectious at the beginning (if the period of staying infectious is 0 then no people are infectious at the beginning)

if (InfectiousPer> 0) NumInfectious = get_input(“Enter the amount of people infectious: “);

//cout<

/*

//Initializing the people infected

for (i=0; InfecPer!= 0 && i

int temp;

while (true) {

temp = rand()%TotalPop;

if (people[temp].get_health() != InfecPer) break;

}

people[temp].set_health(1);

}

cout<< “No Infected : ” << i <

*/

//Initializing people infectious (the infected ones are ruled out)

for (i=0; InfectiousPer!= 0 && i<(TotalPop/* – NumInfected*/) && i

int temp;

while (true) {

temp = rand()%TotalPop;

if ((people[temp].get_health() != InfecPer || InfecPer == 0) && people[temp].get_health() != InfectiousPer) break;

}

people[temp].set_health(InfecPer+1);

}

// cout<< “No Infectious : ” << i <

//Printing the values the health_status and island of each individual

/*

for (i=0; i

cout<< “Health: ” << people[i].get_health() << “; “;

cout<< “Island: ” << people[i].get_island() <

}

*/

float Probability = 0;

//Getting a valid probability of an infection occuring

while (true) {

string input;

cout<< “Enter the Transmission Probability (in decimal format 0.00): ” ;

getline(cin, input);

//cout<< input <

stringstreammyStream(input);

if (myStream>> Probability) break;

cout<< “Error! Please try again.” <

}

//cout<< “Probability : “<< Probability <

//Getting the number of contacts with other people someone makes during the day

intNumContacts = get_input(“Enter the maximum number of contacts each person can make every day: “);

//Getting the number of days the simulation will run

int Days = get_input(“Enter the number of days the program must simulate: “);

//cout<< “The number of days: ” << Days <

int Boats = 0;

//Getting the number of boats that transport people from an island to the other

if (NumIsland> 1) Boats = get_input(“Enter the number of boats available each day: “);

intNumPassengers[Boats], Sources[Boats], Destinations[Boats];

//Getting the number of passengers, the source and destination for each boat

for (i=0; i

cout<< “Boat No.” << i+1 << ” :” <

NumPassengers[i] = get_input(” – Enter the number of passengers: “);

//Getting a valid source island

while (true) {

Sources[i] = get_input(” – Enter the island from where the boat should departure: “);

if (Sources[i] <= NumIsland&& Sources[i] > 0) break;

cout<< “Error, please try again.” <

}

//Getting a valid destination island

while (true) {

Destinations[i] = get_input(” – Enter the island to where the boat shoult go: “);

if (Destinations[i] <= NumIsland&& Destinations[i] > 0) break;

cout<< “Error, please try again.” <

}

//cout<< “————————————————————-” <

}

intday_counter = 0;

cout<< “DAY HEALTHY INFECTED INFECTIOUS RECOVERED” <

//Prints the situation of the islanders at the beginning of the simulation

//cout<< “————————–BEGINNING————————–” <

print_situation(people, TotalPop, InfecPer, InfectiousPer,day_counter);

//cout<< “————————————————————-” <

//Performing the effect of a day on the people

while (day_counter< Days) {

//cout<< “————————————————————-” <

//Initializing the contacts of the people for the day

for (i=0; i

intnum = rand()%(NumContacts+1);

people[i].set_contacts(num);

//cout<< “Contacts: “<< people[i].get_contacts() <

}

//cout<< “————————————————————-” <

//Performing the contacts for each person

for (i=0; i

//Performing each contact of a person

while (people[i].get_contacts() > 0) {

intbreaking_point = 1;

//Checking if there’s a pair (with contacts left to make and on the same island) for the person

for (j=0; j

if (j!=i && people[j].get_contacts()>0 && people[j].get_island() == people[i].get_island()) {

breaking_point = 0;

break;

}

if (breaking_point) break;

//Getting a random pair for the person (with contacts left to make and on the same island)

int temp;

while (true) {

temp = rand()%TotalPop;

if (temp != i && people[temp].get_contacts() > 0 && people[temp].get_island() == people[i].get_island()) break;

}

intPersonPrevHS = people[i].get_health();

intPairPrevHS = people[temp].get_health();

//cout<< “Isl (Person) : ” << people[i].get_island() <

//cout<< “Isl (Pair) : ” << people[temp].get_island() <

//Checking if one of the pair is infectious and the other is healthy, and therefore existing the possibility of infection

if (people[i].get_health() <= (InfectiousPer + InfecPer) && people[i].get_health() >InfecPer&& people[temp].get_health() == 0)

people[temp].infect(Probability);

else if (people[i].get_health() == 0 && people[temp].get_health() <= (InfectiousPer + InfecPer) && people[temp].get_health() >InfecPer)

people[i].infect(Probability);

//cout<< “HS (Person) : ” < ” << people[i].get_health() << “;” <

//cout<< “HS (Pair) : ” < ” << people[temp].get_health() << “;” <

intPersonPrevCont = people[i].get_contacts();

intPairPrevCont = people[temp].get_contacts();

//Decrementing the number of contacts the pair found for the person has left to make

people[temp].set_contacts(people[temp].get_contacts() – 1);

//Decrementing the number of contacts the person has left to make

people[i].set_contacts(people[i].get_contacts() – 1);

//cout<< “Cont (Person) : ” < ” << people[i].get_contacts() << “; ” <

//cout<< “Cont (Pair) : ” < ” << people[temp].get_contacts() << “; ” <

//cout<< “————————————————————-” <

}

}

//cout<< “————————————————————-” <

//for (i=0; i

//cout<< “Contacts: “<< people[i].get_contacts() <

//cout<< “————————————————————-” <

//Prints the situation of the islanders at the end of the day

//cout<< “———————–END OF THE DAY————————” <

//print_situation(people, TotalPop, InfecPer, InfectiousPer,day_counter);

//cout<< “————————————————————-” <

//Performing the effects o a day passing on the health_status of each person

for (i=0; i

people[i].pass_day(InfecPer + InfectiousPer + 1);

day_counter++;

//Prints the situation of the islanders at the beginning of the next day

//cout<< “————————ONE DAY AFTER————————” <

print_situation(people, TotalPop, InfecPer, InfectiousPer, day_counter);

//cout<< “————————————————————-” <

// Checking previous island

/*for (i=0; i

cout<< people[i].get_island() << “;”;

cout<

*/

//Performing the transportation of people from island to island

for (i=0; i

//Transporting every passenger

intnum_passengers = NumPassengers[i];

while (num_passengers>0) {

intbreaking_point = 1;

for (j=0; j

if (people[j].get_island() == Sources[i]) breaking_point = 0;

if (breaking_point) break;

int temp = rand()%TotalPop;

if (people[temp].get_island() == Sources[i]) {

people[temp].set_island(Destinations[i]);

num_passengers–;

boolstill_islanders = 0;

//Checking if there’re still islanders to transport

for (j=0; j

if (people[j].get_island() == Sources[i]) still_islanders = 1;

if (!still_islanders) break;

}

}

}

//Checking after island

/*for (i=0; i

cout<< people[i].get_island() << “;”;

cout<

cout<< “————————————————————-” <

*/

}

/*

IslandPop = TotalPop/NumIsland;

cout<< “Enter the number of routes between islands: ” ;

cin>>IslandRoutesNum;

cout<< “Enter the number of people that can travel on each route: “;

cin>>PeopleRoutesNum;

cout<< “Enter the number of contacts made each day: “;

cin>>ContactsNum;

cout<< “Enter the Transmission Probability(in decimal format 0.00): “;

cin>>TransmissionProb;

cout<< “Enter the Infected Period: “;

cin>>InfectedPeriod;

cout<< “Enter the Infectious Period: “;

cin>>InfectiousPeriod;

cout<< “Enter the initial number of infectious individuals: “;

cin>>InitialInfectious;

*/

// cout<< “DAY ” << “HEALTHY ” << “INFECTED ” << “INFECTIOUS ” << “RECOVERED ” <

// Day();

return 0;

}