Version:0.9 StartHTML:0000000105 EndHTML:0000040966 StartFragment:0000000152 EndFragment:0000040932
/********************************************************************/
/* Team 080: Adam Cummings, David Saxton, Cyrus Marcum */
/* Adventures in SuperComputing 2004-2005 */
/* Programmed by Adam Cummings */
/* Version Date: 3-17-2005 */
/* This program uses models the spread of the AIDS virus */
/* It uses an extensively modified version of the */
/* Si model to accomplish this */
/* Input is required from the file "input.txt" */
/********************************************************************/
#include <iostream.h>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <time.h>
using namespace std;
//Function ProtoTypes:
void Input(); //Handles all input
bool ShouldThisOutput(ifstream& fin); //determines what should be output
void Output(); //handles all output
void Cure(); //called if cure is started
void Immunization(); //called if immunization is started
void LowerContact(int); //determines contact rate for each time step
//Type Definations
const int MAX_AGE=100;
typedef int ageCounter[MAX_AGE]; //0-99 each an age group
struct unDiagType //struct needed because c++ does not allow agregate
{ //operations of arrays
ageCounter unDiagnosedAge;
};
//Variable Definations:
int years, yearsUntilCure, yearsUntilImmunization;
double N=0, S=0, I=0;
double firstYearInfected=0,IR0=0, Ib=0, Id=0;
double Sb=0, Sd=0, uSb, uSd, uS;
double dI=0, udI=0;
double dIb=0, dId=0, udIb=0, udId=0;
double Sbr=0, Sdr=0, Idr=0, Ibr=0,c=0, i=0;
int popResponse;
int percentCured, percentImmunized;
int randNum;
long totalInfectedDeaths=0, startPopulation;
bool outputN=true, outputI=true, outputS=true, outputuS=true;
bool outputIR0=true, outputudI=true, outputdI=true, outputSb=true;
bool outputSd=true, outputudIb=true, outputudId=true;
bool outputdIb=true, outputdId=true, outputuSb=true, outputuSd=true;
ofstream fout("output.txt");
ageCounter infectedAge, susceptibleAge, unSusceptibleAge;
unDiagType yearsSinceInfection[10];
/*
N-total population
S-susceptible pop; uS-unsusceptible(people with born immunity)
I-infected pop; dI-diagnosed Infected; udI-undiagnosed infected
b -births br-birthrate
d-deaths dr-deathrate
IR0-infected this year(undiagnosed)
*/
int main()
{
Input();
startPopulation=N;
srand(time(NULL));
fout << setprecision(3) << "Total_Pop: " << int(N) <<"\tinf_Pop: "
<< int(I) << "\tContact_Rate: " << c << "\tinfectivity: " << i
<< "\tPop's_Response: " << popResponse << "\tCured%: " << percentCured/10
<< "\tImmunized%: " << percentImmunized/10
<< "\nSus_Brth_Rate: " << Sbr << "\tSus_Dth_Rate: " << Sdr
<< "\tInf_Brth_Rate: " << Ibr << "\tInf_Dth_Rate: " << Idr
<< "\tYears_until_Cure: " << yearsUntilCure
<< "\tYears_until_Immunization: " << yearsUntilImmunization
<< endl << endl;
fout << setw(5) << "Year"; //Outputs Column Headings
if(outputN)
fout << setw(20) << "Totl_Pop"; //Outputs Column Headings
if(outputS)
fout << setw(20) << "Sus_Pop"; //Outputs Column Headings
if(outputuS)
fout << setw(20) << "unSusceptible"; //Outputs Column Headings
if(outputI)
fout << setw(20) << "Inf_Pop"; //Outputs Column Headings
if(outputIR0)
fout << setw(20) << "New_Inf"; //Outputs Column Headings
if(outputudI)
fout << setw(20) << "unDiagnosed_Inf"; //Outputs Column Headings
if(outputdI)
fout << setw(20) << "Diagnosed_Inf"; //Outputs Column Headings
if(outputSb)
fout << setw(20) << "Sus_Birth"; //Outputs Column Headings
if(outputSd)
fout << setw(20) << "Sus_Death"; //Outputs Column Headings
if(outputudIb)
fout << setw(20) << "unDiagnosed_Bth"; //Outputs Column Headings
if(outputudId)
fout << setw(20) << "unDiagnosed_Dth"; //Outputs Column Headings
if(outputdIb)
fout << setw(20) << "Diagnosed_Bth"; //Outputs Column Headings
if(outputdId)
fout << setw(20) << "Diagnosed_Dth"; //Outputs Column Headings
if(outputuSb)
fout << setw(20) << "unSus_Brth"; //Outputs Column Headings
if(outputuSd)
fout << setw(20) << "unSus_Dth";
fout << setw(20) << "contact_Rate"; //Outputs Column Headings
fout << endl;
S = N - I; //initial susceptible calculation
dI = I; //all starting infected are diagnosed
IR0 = (c*i*S)*(I/N); //Initial SI
uS=S*.01;
S = S*.99;
for(int j = 0;j<MAX_AGE;j++) //Divides initial population into age groups
{
susceptibleAge[j] = S*((-.0882*j+9.19)/488);
infectedAge[j] = I*.01;
unSusceptibleAge[j] = uS*((-.0882*j+9.19)/488);
}
for(int counter = 0;counter<years;counter++) //Main Loop
{
if (counter>=yearsUntilImmunization) //starts immunizations
Immunization();
if (counter>=yearsUntilCure) //Cure
Cure();
dId=0;
dIb=0;
udIb=0;
udId=0;
uSb=0;
uSd=0;
Sb=0;
Sd=0;
/***********************************************************************/
/* The following loops are where most of the calculation take place */
/* (births, deaths, and infections). A random number is generated */
/* (usually 1-1000) and if the random number is less then rate */
/* currently being checked (i.e. if 150 babies are born per 1000 in */
/* population and the random number is <150 then a baby is born). */
/* This is done once for every person in the population */
/* */
/***********************************************************************/
for(int index = 0;index<MAX_AGE;index++)
{
for(int temp = 0;temp<susceptibleAge[index];temp++)
{
randNum = rand()%100000+1; //1-100000
if((index>=15)&&(index<=50)) //ages 15-50 can be infected only
{
if(randNum<=((IR0/S)*100000)) //infectionloop
{ //(IR0/S)*100000 is chance 1 susep becomes infected
susceptibleAge[index]--;
yearsSinceInfection[0].unDiagnosedAge[index]++;
firstYearInfected++;
}
}
randNum = rand()%1000+1;
if(index>=15&&index<=50) //ages 15-50 can have children only
if(randNum<=(Sbr*2))
{
randNum=rand()%100000+1;
if(randNum<=((Sbr*2)*(uS/N*10)*100)) //chance baby is uS over S
{
uSb++;
unSusceptibleAge[0]++;
}
else
{
susceptibleAge[0]++; //SuscepBirths
Sb++;
}
}
if(index<15) //age<15 deaths
if((randNum>=600)&&(randNum<=(600+(Sdr/2))))
{
susceptibleAge[index]--;
Sd++; //SuscepDeaths
}
if(index>=15&&index<=50) // 15<age<50
if((randNum>600)&&(randNum<=(600+(Sdr))))
{
susceptibleAge[index]--;
Sd++; //SuscepDeaths
}
if(index>50) // age>50
if((randNum>600)&&(randNum<=(600+(Sdr*2))))
{
susceptibleAge[index]--;
Sd++; //SuscepDeaths
}
}
for(int temp = 0;temp<unSusceptibleAge[index];temp++)
{
randNum = rand()%1000+1;
if(index>=15&&index<=50)
{
if(randNum<=Sbr*2) //UnSus Births
{
randNum=rand()%100000+1;
if(randNum<=((Sbr*2)*(uS/N*10)*100)) //chance baby is uS over S
{
uSb++;
unSusceptibleAge[0]++;
}
else
{
susceptibleAge[0]++;
Sb++;
}
}
}
if(randNum<=Sdr) //UnSusDeaths
{
uSd++;
unSusceptibleAge[index]--;
}
}
for(int temp = 0;temp<infectedAge[index];temp++)
{
randNum = rand()%1000+1; //infectedDeaths
if(randNum<=Idr)
{
infectedAge[index]--;
dId++;
}
if((randNum>200)&&(randNum<=(200+Ibr))) //infectedBirths
dIb++;
}
for(int temp = 0; temp<10;temp++)
for(int pop = 0; pop<yearsSinceInfection[temp].unDiagnosedAge[index]; pop++)
{
randNum = rand()%1000+1;
if(randNum<Sbr) //UnDiagnosed Births
{
udIb++;
dIb++;
yearsSinceInfection[temp].unDiagnosedAge[index]--;
infectedAge[index]++;
}
if(randNum>200 && randNum<(200+Sdr)) //UnDiagnosed Deaths
{
yearsSinceInfection[temp].unDiagnosedAge[index]--;
udId++;
}
}
}
for(int index =0 ;index<MAX_AGE;index++) //immigration loop
susceptibleAge[index]+=(10000*.01);
infectedAge[0]+=(dIb*.25);
susceptibleAge[0]+=(dIb*.75);
dI=0;
S=0;
udI=0;
uS=0;
for(int index = 0;index<MAX_AGE;index++) //retotals pop groups
{
uS+=unSusceptibleAge[index];
S+=susceptibleAge[index];
dI+=infectedAge[index];
for(int j=0;j<10;j++)
udI+=yearsSinceInfection[j].unDiagnosedAge[index];
}
I = dI+udI; //totals infected with and without symptoms(sick and healthy)
N = S + I + uS; //Finds the new total population
totalInfectedDeaths+=dId+udId;
fout << setw(5) << int(counter);
Output();
fout << endl;
cout << counter << endl;
for(int index=8;index>=0;index--)
yearsSinceInfection[index+1]=yearsSinceInfection[index];
for(int i=0;i<MAX_AGE;i++)
if(counter>=yearsUntilCure)
{
unSusceptibleAge[i]+=yearsSinceInfection[9].unDiagnosedAge[i]*.95;
infectedAge[i]+=yearsSinceInfection[9].unDiagnosedAge[i]*.05;
}
else
infectedAge[i]+=yearsSinceInfection[9].unDiagnosedAge[i];
for(int i =98; i>=0;i--) //Ages main groups
{
infectedAge[i+1]=infectedAge[i];
susceptibleAge[i+1]=susceptibleAge[i];
unSusceptibleAge[i+1]=unSusceptibleAge[i];
yearsSinceInfection[0].unDiagnosedAge[i]=0; //Zeros fst yr infected
for(int j=0;j<10;j++)
yearsSinceInfection[j].unDiagnosedAge[i+1] = yearsSinceInfection[j].unDiagnosedAge[i];
}
susceptibleAge[0]=0;
infectedAge[0]=0;
unSusceptibleAge[0]=0;
LowerContact(counter);
IR0 = (c*i*S)*(I/N); /*Finds New infected
this equation is contact rate*
infectivity*Susceptible pop*
(infected/total population)
this is called SI model
*/
if(I<1)
break;
}
fout << endl << endl;
fout << "Total infected deaths: " << totalInfectedDeaths << endl;
fout << "Population Change: " <<N<<'-'<<startPopulation<<'='<< N-startPopulation << endl;
return 0;
}
//***************************Input***************************//
void Input()
{
ifstream fin("input.txt");
fin >> years;
fin.ignore(100, '\n');
fin >> N;
fin.ignore(100, '\n');
fin >> I;
fin.ignore(100, '\n');
fin >> c;
fin.ignore(100, '\n');
fin >> i;
fin.ignore(100, '\n');
fin >> Sbr;
fin.ignore(100, '\n');
fin >> Sdr;
fin.ignore(100, '\n');
fin >> Ibr;
fin.ignore(100, '\n');
fin >> Idr;
fin.ignore(100, '\n');
fin >> yearsUntilCure;
fin.ignore(100, '\n');
fin >> percentCured;
fin.ignore(100, '\n');
fin >> yearsUntilImmunization;
fin.ignore(100, '\n');
fin >> percentImmunized;
fin.ignore(100, '\n');
fin >> popResponse;
fin.ignore(100, '\n');
fin.ignore(100, '\n');
outputN=ShouldThisOutput(fin);
outputI=ShouldThisOutput(fin);
outputS=ShouldThisOutput(fin);
outputuS=ShouldThisOutput(fin);
outputIR0=ShouldThisOutput(fin);
outputudI=ShouldThisOutput(fin);
outputdI=ShouldThisOutput(fin);
outputSb=ShouldThisOutput(fin);
outputSd=ShouldThisOutput(fin);
outputudIb=ShouldThisOutput(fin);
outputudId=ShouldThisOutput(fin);
outputdIb=ShouldThisOutput(fin);
outputdId=ShouldThisOutput(fin);
outputuSb=ShouldThisOutput(fin);
outputuSd=ShouldThisOutput(fin);
}
//***************************ShouldThisOutput***************************//
bool ShouldThisOutput(ifstream& fin)
{
int temp;
fin >> temp; fin.ignore(100, '\n');
return (temp==1);
}
//***************************Output***************************//
void Output()
{
if(outputN)
fout << setw(20) << int(N+.5);
if(outputS)
fout << setw(20) << int(S+.5);
if(outputuS)
fout << setw(20) << int(uS+.5);
if(outputI)
fout << setw(20) << int(I+.5);
if(outputIR0)
fout << setw(20) << int(IR0+.5);
if(outputudI)
fout << setw(20) << int(udI+.5);
if(outputdI)
fout << setw(20) << int(dI+.5);
if(outputSb)
fout << setw(20) << int(Sb+.5);
if(outputSd)
fout << setw(20) << int(Sd+.5);
if(outputudIb)
fout << setw(20) << int(udIb+.5);
if(outputudId)
fout << setw(20) << int(udId+.5);
if(outputdIb)
fout << setw(20) << int(dIb+.5);
if(outputdId)
fout << setw(20) << int(dId+.5);
if(outputuSb)
fout << setw(20) << int(uSb+.5);
if(outputuSd)
fout << setw(20) << int(uSd+.5);
fout << setw(20) << c;
}
//***************************Cure***************************//
void Cure()
{
for(int index=0;index<MAX_AGE;index++)
for(int temp =0;temp<infectedAge[index];temp++)
{
randNum = rand()%1000+1;
if(randNum<=percentCured)
{
infectedAge[index]--;
unSusceptibleAge[index]++;
}
}
}
//***************************Immunization***************************//
void Immunization()
{
for(int index=0;index<MAX_AGE;index++)
for(int temp =0;temp<susceptibleAge[index];temp++)
{
randNum = rand()%1000+1;
if(randNum<=percentImmunized)
{
susceptibleAge[index]--;
unSusceptibleAge[index]++;
}
}
}
//***************************LowerContact***************************//
void LowerContact(int counter)
{
static int cDown;
static float cConst;
if(counter<10) //Randomizes Contact Rate
{
c=c*.80;
cConst=c;
}
else
{
float temp;
temp = rand();
temp/=RAND_MAX;
temp/=10;
c=cConst+(.05-temp)-((I/N)/popResponse);
}
}