Solved

LINK : fatal error LNK1181: cannot open input file

Posted on 2008-10-16
9
1,843 Views
Last Modified: 2012-08-13
Hello everyone,

I am trying to build a project in Visual Studio that was passed down to me. I've tried loading it on several computers and every time I get the following error:

1>------ Build started: Project: Flu, Configuration: Release Win32 ------
1>Linking...
1>LINK : fatal error LNK1181: cannot open input file 'C:\ILOG\Concert21\lib\x86_.net2003_7.1\stat_sta\concert.lib'
1>Build log was saved at "file://c:\Users\Daniel Park\Documents\Visual Studio 2008\Projects\spread_code_census_tract\Release\BuildLog.htm"
1>Flu - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can anyone give me some leads as to some things to check to try to get the code to build?

Daniel
0
Comment
Question by:ltdanp22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22736455
Does this file exist 'C:\ILOG\Concert21\lib\x86_.net2003_7.1\stat_sta\concert.lib'

If not it needs to.  If it does, check that you can access it as the user that is doing the build.
0
 

Author Comment

by:ltdanp22
ID: 22736797
That file does not exist. Is there some way I'm missing it? Like it's a hidden file.
If not, how do I create it?
0
 
LVL 17

Assisted Solution

by:sweetfa2
sweetfa2 earned 500 total points
ID: 22736832
Where is your ILOG CPLEX package installed?

It needs to point to that somehow.  Have you got the software from another machine.  It looks like you may not have the required software installed on your build machine.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ltdanp22
ID: 22736924
i don't believe i have ilog cplex installed.
can you look through the code below and see if there's a way to turn the use of cplex off? i do not need the part of the code that uses cplex.
below is the cpp file. next post is the .h file.

#define NAG
#define DEBUG
#define DISPLAY
//#define PRINT_STATS
//#define READ_PARAMETERS
//#define PRINT_TIME_SERIES
#define IMPORT 
//#define SINGLE_SEED
//#define CHECK_TARGETS
#define CONTACT_TRACING
#define DURATION_DETAILS
#define LOW_SPAM
#define TESTING
 
#include <ctime>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <queue>
#include <algorithm>
#include <string>
#include <cassert>
#include <cmath>
#include <iomanip>
 
#include <algorithm>
#include <functional>
#include <vector>
using std::vector;
 
#include "Flu.h"
 
//#include <nag.h>
//#include <nagg05.h>
//#include <nag_stdlib.h>
 
using namespace std;
 
 
void workflowdata()
{
 
	ifstream input;
 
	ofstream output;
	int iCounter;
	int A[162][161]={0};
 
 
	int i,j;
 
 
	FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/workflow.txt", "r");
 
	if (!inFile)
	{
		printf("Cannot find workflow.txt\n");
	}
	else
	{	for(i=0;i<162;i++)
		{	for(j=0;j<161;j++)
				fscanf(inFile, "%d ", &A[i][j]);
			fscanf(inFile, "\n");
		}
	}
	fclose(inFile);
 
 
	cout << "A = " << A[161][160] << endl;
 
 
	for(j=0;j<161;j++)
		A[60][j] += (A[20][j] + A[101][j]);
 
	for(i=0;i<162;i++)
		for(j=0;j<161;j++)
			if(20<i && i<101)
				A[i-1][j]=A[i][j];
			else if(101<i)
				A[i-2][j]=A[i][j];
 
	for(i=0;i<number_counties;i++)
		A[i][60] += (A[i][20] + A[i][101]);
 
	for(i=0;i<number_counties;i++)
		for(j=0;j<161;j++)
			if(20<j && j<101)
				A[i][j-1]=A[i][j];
			else if(101<j)
				A[i][j-2]=A[i][j];
 
	for(i=0;i<number_counties;i++)
		for(j=0;j<number_counties-1;j++)
			workflow[i][j] = A[i][j];
 
	for(iCounter=0;iCounter<number_counties;iCounter++)
		gc_iAdultsPopulation[iCounter] = static_cast<int>(gc_dPropAgeGroup[3][iCounter]*gc_iPopulationSize[iCounter]);
 
 
	output.open("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/workflow2.txt");
 
	for (i=0;i<number_counties-1;i++)
	{	sum[i] = 0;
		for(j=0;j<number_counties-1;j++)
			sum[i] += workflow[i][j];
		ratio[i]= (double)(gc_iAdultsPopulation[i])/(double)sum[i];
 
		output<<ratio[i]<< "\t" << gc_iAdultsPopulation[i]<< "\t" << sum[i]<<"\t";
		output<<endl;
	}
	output.close();
 
	for(j=0;j<number_counties-1;j++)
		workflow[number_counties-1][j] = (int)(ratio[j]*workflow[number_counties-1][j]);
 
	for(j=0;j<number_counties-1;j++)
		workflow[number_counties-1][j] = (int)(workflow[number_counties-1][j]/10.0);
 
	gc_iPopulationSize[number_counties-1] = 0;
	for(j=0;j<number_counties-1;j++)
		gc_iPopulationSize[number_counties-1] += workflow[number_counties-1][j];
 
	cout << "Out of State Population = " << gc_iPopulationSize[number_counties-1] << endl;
}
 
 
//WORKFLOW DONE
 
 
void CheckFOI();
void AddEvent(CEventListRecord x)
{
	if ((gc_dTimeMax-x.GetTime()) > 1e-6)
	{
		int iPosEventList = static_cast<int>(floor(x.GetTime()/gc_dTimeMax*gc_iNumEventLists));
		if (iPosEventList > gc_iNumEventLists-1)
		{
			cout << "Error in AddEvent.  iPosEventList = " << iPosEventList << endl;
			Pause();
		}
		(*(g_pEventList[iPosEventList])).push(x);
	}
}
 
double CSocialGroup::ComputeInfectivity()
{
	m_dInfectivity = 0;
	for (int iCounter = 0; iCounter < m_cMemberList.Size(); ++iCounter)
		m_dInfectivity += g_cIndividual[m_cMemberList[iCounter]].GetInfectivity(m_iGroupType);
	return m_dInfectivity;
}
 
double CSocialGroup::ComputeSusceptibility()
{
	m_dSusceptibility = 0;
	for (int iCounter = 0; iCounter < m_cMemberList.Size(); ++iCounter)
		m_dSusceptibility += g_cIndividual[m_cMemberList[iCounter]].GetSusceptibility(m_iGroupType);
	return m_dSusceptibility;
}
 
double CSocialGroup::ChangeInfectivity(const double dDelta)
{
	double dFOIDelta;
	int iSlot = static_cast<int>(floor(m_iGroupID/
		static_cast<double>(g_iNumGroups[m_iGroupType]-1)*(gc_iNumEngineSlots-1)));
	if (m_bFOIPerturbedStatus == false)
	{
		m_bFOIPerturbedStatus = true;
		g_cFOIPerturbedList[m_iGroupType][iSlot].Push(CFOIPerturbedListElement(m_iGroupID, GetFOI()));
	}
	m_dInfectivity += dDelta;
	dFOIDelta = dDelta*m_dSusceptibility/GetFOIDenominator()*GetInfHazardGroup();
	g_dFOI[m_iGroupType][iSlot] += dFOIDelta;
	g_dTotalFOI[m_iGroupType] += dFOIDelta;
 
	++g_iNumFOIUpdates;
	return m_dInfectivity;
}
 
double CSocialGroup::ChangeSusceptibility(const double dDelta)
{
	double dFOIDelta;
	int iSlot = static_cast<int>(floor(m_iGroupID/static_cast<double>(g_iNumGroups[m_iGroupType]-1)*(gc_iNumEngineSlots-1)));
	if (m_bFOIPerturbedStatus == false)
	{
		m_bFOIPerturbedStatus = true;
		g_cFOIPerturbedList[m_iGroupType][iSlot].Push(CFOIPerturbedListElement(m_iGroupID, GetFOI()));
	}
	m_dSusceptibility += dDelta;
	dFOIDelta = dDelta*m_dInfectivity/GetFOIDenominator()*GetInfHazardGroup();
	g_dFOI[m_iGroupType][iSlot] += dFOIDelta;
	g_dTotalFOI[m_iGroupType] += dFOIDelta;
 
	++g_iNumFOIUpdates;
	return m_dSusceptibility;
}
 
 
int CSocialGroup::SelectInfectee(const double dFOICutOff)
{
 
	if (m_dInfectivity < gc_dSmallestInfectivity || m_dSusceptibility < gc_dSmallestSusceptibility)
	{
		cout << "Error in SelectInfectee(). " << endl;
		cout << "Infectivity = " << m_dInfectivity << ", Susceptibility = " << m_dSusceptibility << endl;
		Pause();
	}
 
	int iCounter;
	double dCumulativeSusceptibility = 0, dSusceptibilityCutOff = dFOICutOff/(m_dInfectivity/GetFOIDenominator()*GetInfHazardGroup());
	//for (iCounter = 0; iCounter < m_cMemberList.Size(); ++iCounter)
	//	dCumulativeSusceptibility += g_cIndividual[m_cMemberList[iCounter]].GetSusceptibility(m_iGroupType);
 
	if ((dSusceptibilityCutOff/m_dSusceptibility-1) > 0.001)
	{
		cout << "Error in SelectInfectee(). " << endl;
		cout << "m_dSusceptibility = " << m_dSusceptibility << ", dSusceptibilityCutOff = " << dSusceptibilityCutOff << endl;
		Pause();
	}
	dSusceptibilityCutOff = MIN(0.9999*m_dSusceptibility, dSusceptibilityCutOff); 
 
	if (dSusceptibilityCutOff < m_dSusceptibility/2.0)
	{
		for (iCounter = 0; iCounter < m_cMemberList.Size(); ++iCounter)
		{
			dCumulativeSusceptibility += g_cIndividual[m_cMemberList[iCounter]].GetSusceptibility(m_iGroupType);
			if (dCumulativeSusceptibility > dSusceptibilityCutOff)
				break;
		}
	}
	else
	{
		dCumulativeSusceptibility = m_dSusceptibility;
		for (iCounter = m_cMemberList.Size()-1; iCounter > -1; --iCounter)
		{
			dCumulativeSusceptibility -= g_cIndividual[m_cMemberList[iCounter]].GetSusceptibility(m_iGroupType);
			if (dCumulativeSusceptibility < dSusceptibilityCutOff)
				break;
		}
	}
	//If fall off, rerun the routine
	if ((iCounter == m_cMemberList.Size() && dCumulativeSusceptibility < dSusceptibilityCutOff) ||
		(iCounter == -1 && dCumulativeSusceptibility > gc_dSmallestSusceptibility))
	{
		cout << dCumulativeSusceptibility << " " << dSusceptibilityCutOff << endl;
		cout << "SelectInfectee() fall off error." << endl;
		Pause();
	}
 
	g_iSelectedSeed = m_cMemberList[iCounter];
 
#ifdef CHECK_TARGETS
	++g_iNumInfecteesBySeed[g_cIndividual[g_iSelectedSeed].GetDiseaseStatus()-PRESYMPTOMATIC][m_iGroupType];
	g_dTg += g_dTime;
#endif
	if (g_cIndividual[m_cMemberList[iCounter]].GetDiseaseStatus() != SUSCEPTIBLE)
	{
		cout << "Error: Not susceptible: " << g_cIndividual[m_cMemberList[iCounter]].GetDiseaseStatus() << endl;
		cout << g_cIndividual[m_cMemberList[iCounter]].GetSusceptibility(m_iGroupType) << endl;
		cout << dCumulativeSusceptibility << " " << dSusceptibilityCutOff << endl;
		Pause();
	}
	return m_cMemberList[iCounter];
}
 
 
 
 
int CHousehold::GetHouseholdSize()
{
	return GetMemberList().Size();
}
 
int CHousehold::GetNumAdults()
{
	int iNumAdults = 0, iCounter;
	for (iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		if (g_cIndividual[GetMemberList()[iCounter]].GetAdultStatus() == true)
			++iNumAdults;
	}
	return iNumAdults;
}
 
int CHousehold::ComputeActiveHouseholdSize()
{
	m_iActiveHouseholdSize = 0;
	for (int iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		if (g_cIndividual[GetMemberList()[iCounter]].GetHouseholdActiveStatus() == true)
			++m_iActiveHouseholdSize;
	}
	return m_iActiveHouseholdSize;
}
 
bool CHousehold::GetHouseholdQuarantineStatus()
{
	for (int iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		if (g_cIndividual[GetMemberList()[iCounter]].GetQuarantineStatus() == true)
			return true;
	}
	return false;
}
 
bool CHousehold::GetHouseholdDrugStatus()
{
	for (int iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		if (g_cIndividual[GetMemberList()[iCounter]].GetDrugStatus() == true)
			return true;
	}
	return false;
}
 
int CHousehold::GetHouseholdQuarantineSize()
{
	int iCounter2 = 0;
	for (int iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		if (g_cIndividual[GetMemberList()[iCounter]].GetQuarantineStatus() == true)
			++iCounter2;
	}
	return iCounter2;
}
 
int CHousehold::ChangeActiveHouseholdSize(const int iDelta)
{
	double dFOIDelta;
	int iOldActiveHouseholdSize = m_iActiveHouseholdSize, 
		iSlot = static_cast<int>(floor(GetGroupID()/static_cast<double>(g_iNumGroups[HOUSEHOLD]-1)*(gc_iNumEngineSlots-1)));
	if (GetFOIPerturbedStatus() == false)
	{
		SetFOIPerturbedStatus(true);
		g_cFOIPerturbedList[HOUSEHOLD][iSlot].Push(CFOIPerturbedListElement(GetGroupID(), GetFOI()));
	}
	m_iActiveHouseholdSize += iDelta;
	dFOIDelta =  GetInfectivity()*GetSusceptibility()*GetInfHazardGroup()*
		(1.0/MAX(1, m_iActiveHouseholdSize)-1.0/MAX(1, iOldActiveHouseholdSize));
	g_dFOI[HOUSEHOLD][iSlot] += dFOIDelta;  
	g_dTotalFOI[HOUSEHOLD] += dFOIDelta;  
 
	++g_iNumFOIUpdates;
	return m_iActiveHouseholdSize;
}
 
 
double CPeerGroup::GetInfHazardGroup()
{
	if (GetGroupID() < g_iNumClassrooms[0])
		return g_dInfHazardPeerGroup[0];
	else if (GetGroupID() < g_iNumClassrooms[1])
		return g_dInfHazardPeerGroup[1];
	else if (GetGroupID() < g_iNumClassrooms[2])
		return g_dInfHazardPeerGroup[2];
	else if (GetGroupID() < g_iNumClassrooms[2] + g_iOldGroups)
		return g_dInfHazardPeerGroup[4];
	else
		return g_dInfHazardPeerGroup[3];
}
 
 
int CIndividual::GetHouseholdSize(){ return (g_cHousehold[m_iHouseholdID].GetMemberList()).Size();}
int CIndividual::GetPeerGroupSize(){ return (g_cPeerGroup[m_iPeerGroupID].GetMemberList()).Size();}
 
 
void CIndividual::Quarantine(bool iNewCase)
{
#ifdef DURATION_DETAILS
	m_dQuarantineEntryTime = static_cast<float>(g_dTime);
	if (iNewCase == true)
		++m_iQuarantineTimes;
#endif
	int iCounter;
	m_dTimeRecord = static_cast<float>(g_dTime);
	if (iNewCase == true)
	{
		g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
#ifdef DURATION_DETAILS
		g_cHousehold[m_iHouseholdID].SetQuarantineEntryTime(static_cast<float>(g_dTime));
		/*	g_cHousehold[m_iHouseholdID].IncreaseQuarantineTimes();*/
#endif
	}
	++g_iNumQuarantined;
	++g_iQuarantineIncidence;
	--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	m_bQuarantineStatus = true;
	if (m_bLeadStatus == true ||  iNewCase == false ||
		(GetSymptomsStatus() == false && Probability() < g_dProbCompliance))
	{
		double dOldInfectivity[2], dOldSusceptibility[2];
		for (iCounter = 0; iCounter < 2; ++iCounter)
		{
			dOldInfectivity[iCounter] = GetInfectivity(iCounter);
			dOldSusceptibility[iCounter] = GetSusceptibility(iCounter);
		}
 
		m_bComplianceStatus = true;
		UpdateFOI(dOldInfectivity, dOldSusceptibility);
	}
 
#ifdef CONTACT_TRACING
	if (g_bTracingActive == true && iNewCase == true && m_bAdultStatus == true && m_bComplianceStatus == true)
	{
		if (m_bCTInterviewed == false)
		{	
			int iID, iCounter2;
			double dProbContactNamed = gc_dMeanNumContactNamed/static_cast<double>(GetPeerGroupSize()); 
			m_bCTInterviewed = true;
			iCounter2 = GetPeerGroupIndex();
 
			for (iCounter = 0; iCounter < GetPeerGroupSize(); ++iCounter)
			{
				iID = GetPeerGroupMember(iCounter);
				if (iID != m_iID && (dProbContactNamed > 0.9999 || Probability() < dProbContactNamed))
				{
					AddToContactIndexList(iCounter);
					g_cIndividual[iID].AddToContactIndexList(iCounter2);
				}
			}
		}
		if (GetSymptomsStatus() == true)
			TraceContacts();
	}	
#endif
	++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
#ifdef TESTING
	if (iNewCase == true && g_bTestingActive == true && g_bStopTesting == false)
	{
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
		{
			TakeTest();
			AddEvent(CEventListRecord(g_dTime+TestDuration(), m_iID, TEST_RETURN));
		}
		return;
	}
#endif
	AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
}
 
void CIndividual::ActivateDrug()
{
	if (IsEqual(g_cHousehold[m_iHouseholdID].GetDrugTime(), g_dTime) == false)
		return;
 
	g_cHousehold[m_iHouseholdID].SetDrugTime(LARGE_NUMBER);
 
	int iCounter, iCounter2, iID;
	double dOldInfectivity[2], dOldSusceptibility[2];
 
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{ 
		iID = GetHouseholdMember(iCounter);
		if (g_cIndividual[iID].GetQuarantineStatus() == true && g_cIndividual[iID].GetComplianceStatus() == true)
		{
			for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			{
				dOldInfectivity[iCounter2] = g_cIndividual[iID].GetInfectivity(iCounter2);
				dOldSusceptibility[iCounter2] = g_cIndividual[iID].GetSusceptibility(iCounter2);
			}
 
			g_cIndividual[iID].SetDrugStatus(true);
		    g_cIndividual[iID].SetTimeRecord(static_cast<float>(g_dTime));
			g_cIndividual[iID].UpdateFOI(dOldInfectivity, dOldSusceptibility);
		}
	}	
}
 
#ifdef CONTACT_TRACING
bool CIndividual::FindFamilyMember(const int iID)
{
	for (int iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		if (GetHouseholdMember(iCounter) == iID)
			return true;
	}
	return false;
}
 
void CIndividual::TraceContacts()
{
	int iCounter, iID;
	for (iCounter = 0; iCounter < m_cContactIndexList.Size(); ++iCounter)
	{
		iID = GetPeerGroupMember(m_cContactIndexList[iCounter]);
		if (g_cIndividual[iID].GetCTListStatus() == true)
		{
			// this loop will not be entered for now
			AddEvent(CEventListRecord(g_dTime+gc_dMaxCTListDuration, iID, CLEAR_CTLIST_RECORD));
			g_cIndividual[iID].ChangeCTMultiplicity(1);
		}
		else if (g_cIndividual[iID].GetQuarantineStatus() == false && g_cIndividual[iID].GetHouseholdCTActive() == false && 
			g_cIndividual[iID].GetImmuneStatus() == false && g_cIndividual[iID].GetIsolationStatus() == false && FindFamilyMember(iID) == false)
		{	
 
			g_cIndividual[iID].AddedToCTList(true);
			if (g_cIndividual[iID].GetCTListStatus() == true)
			{
				AddEvent(CEventListRecord(g_dTime+gc_dMaxCTListDuration, iID, CLEAR_CTLIST_RECORD));
				g_cIndividual[iID].ChangeCTMultiplicity(1);
			}
		}
	}
}
 
bool CIndividual::GetHouseholdCTActive() 
{ 
	int iCounter, iID;
	if (g_cHousehold[m_iHouseholdID].GetHouseholdSeen() == false)
	{
		if (m_bCTActive == true)
			return true;
		return false;
	}
	else
	{
		for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
		{ 
			iID = GetHouseholdMember(iCounter);
			if (g_cIndividual[iID].GetCTActive() == true)
				return true;
		} 
		return false;
	}
}
 
void CIndividual::ClearCTListRecord()
{
	if (m_iCTMultiplicity > 0)
		--m_iCTMultiplicity;
	if (m_bCTListStatus == true && m_iCTMultiplicity == 0)
		RemovedFromCTList(true);
}
 
void CIndividual::AddedToCTList(const bool bNewRecord){
	// Checked 10/8
	// This is an individual action
#ifdef DEBUG
	assert(m_iDiseaseStatus != DEAD);
	assert(m_bQuarantineStatus == false);
	assert(m_bIsolationStatus == false);
	assert(m_bCTListStatus == false);
	assert(m_bImmuneStatus == false);
#endif
	if (bNewRecord)
		m_dTimeRecord = static_cast<float>(g_dTime);
	if (g_iNumActiveCTServers < gc_iMaxNumCTServers)
		ActivateTracing();
	else
	{
		m_bCTListStatus = true;
		g_cCTList.push_back(CCTRecord(m_iID, m_dTimeRecord));
	}
}
 
void CIndividual::RemovedFromCTList(const bool bCloseRecord)
{
#ifdef DEBUG
	assert(m_bCTActive == false);
	assert(m_bQuarantineStatus == false);
	assert(m_bIsolationStatus == false);
	assert(m_bCTListStatus == true);
	assert(m_bImmuneStatus == false);
#endif
	if (g_cCTList.empty() == false)
	{
		if (m_iID == (*(g_cCTList.begin())).GetID())
			g_cCTList.pop_front();
		else if (m_iID == (*(g_cCTList.rbegin())).GetID())
			g_cCTList.pop_back();
		else
			++g_iNumCTRecordRemoved;
	}
	m_bCTListStatus = false;
	if (bCloseRecord == true)
	{
		m_dTimeRecord = LARGE_NUMBER;
		m_iCTMultiplicity = 0;
	}
}
 
void CIndividual::ActivateTracing()
{
	int iID, iCounter;
	if (g_cHousehold[m_iHouseholdID].GetHouseholdSeen() == false)
	{
		if (m_bCTListStatus == true)
			RemovedFromCTList(true);
	}
	else
	{
		for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
		{	
			iID = GetHouseholdMember(iCounter);
			if (g_cIndividual[iID].GetCTListStatus() == true)
				g_cIndividual[iID].RemovedFromCTList(true);
		}
	}
	m_bCTActive = true;
	m_dTimeRecord = static_cast<float>(g_dTime+TraceDuration());  // the time at which the contact is traced
	AddEvent(CEventListRecord(m_dTimeRecord, m_iID, TRACED));
	++g_iNumActiveCTServers;
}
 
void CIndividual::Traced()
{
	if (m_bCTActive == false || IsEqual(m_dTimeRecord, g_dTime) == false)
		return;
	PushCTList();
	if (m_iDiseaseStatus == SYMPTOMATIC || Probability() > g_dProbReport)
		return;
 
	++g_iNumTraced;
 
	m_bLeadStatus = true;
	g_cHousehold[m_iHouseholdID].SetHouseholdSeen(true);
 
	++g_iNumHouseholdsQuarantined;
#ifdef DURATION_DETAILS
	g_cHousehold[m_iHouseholdID].IncreaseQuarantineTimes();
#endif
	int iCounter, iID;
	bool bQuarantine = false;
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		// Note: immune individuals will not enrolled in the program (e.g., no drug is given to them).  However, we count them in activeHouseholdSize
		if (g_cIndividual[iID].IsQuarantinable() == true)
		{
			g_cIndividual[iID].Quarantine(true);
			bQuarantine = true;
		}
	}
	
	if (g_bDrugActive == true && bQuarantine == true)
	{
		float dDummy = static_cast<float>(g_dTime+DrugDelay());
		g_cHousehold[m_iHouseholdID].SetDrugTime(dDummy);
		AddEvent(CEventListRecord(dDummy, m_iID, DRUG_ACTIVATE));
	}
}
 
 
void CIndividual::PushCTList(){
#ifdef DEBUG
	assert(m_bQuarantineStatus == false);
	assert(m_bIsolationStatus == false);
	assert(m_bImmuneStatus == false);
#endif
	int iID, iCounter, iNumServersFreed = 0;
 
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		if (g_cIndividual[iID].GetCTListStatus() == true)
			g_cIndividual[iID].RemovedFromCTList(true);
		if (g_cIndividual[iID].GetCTActive() == true)
		{
			g_cIndividual[iID].SetCTActive(false);
			++iNumServersFreed;
			--g_iNumActiveCTServers;
		}
	}
 
	for (iCounter = 0; iCounter < iNumServersFreed; ++iCounter)
	{
		if (g_cCTList.empty() == false)
		{
			while (g_cCTList.empty() == false && (g_cIndividual[(*(g_cCTList.begin())).GetID()].GetCTListStatus() == false || 
				IsEqual(g_cIndividual[(*(g_cCTList.begin())).GetID()].GetTimeRecord(), (*(g_cCTList.begin())).GetCTRecordTime()) == false))
			{
				g_cCTList.pop_front();
				--g_iNumCTRecordRemoved;
			}
			if (g_cCTList.empty() == false)
			{
				g_cIndividual[(*(g_cCTList.begin())).GetID()].RemovedFromCTList(true);
				g_cIndividual[(*(g_cCTList.begin())).GetID()].ActivateTracing();
			}
		}
	}
}
#endif
 
#ifdef TESTING
void CIndividual::TakeTest()
{	
	if (m_bTestActive == true)
	{
		cout << "Error: " << m_bQuarantineStatus << " " << m_bComplianceStatus << endl;
 
		Pause();
 
	}
	if (m_iDiseaseStatus == PRESYMPTOMATIC || m_iDiseaseStatus == ASYMPTOMATIC || m_iDiseaseStatus == SYMPTOMATIC || m_iDiseaseStatus == HOSPITALIZED)
	{
		if (Probability() < gc_dTestSensitivity)
			m_bTestResult = true;
		else
			m_bTestResult = false;
	}
	else
		m_bTestResult = false;
	m_bTestActive = true;
	g_cHousehold[m_iHouseholdID].SetTestActive(true);
	++g_iNumActiveTestServers;
}
 
 
void CIndividual::CheckTestResult()
{
	int iID, iCounter;
	if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == false)
	{
		g_cHousehold[m_iHouseholdID].SetTestActive(false);
		for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
		{
			iID = GetHouseholdMember(iCounter);
			if (g_cIndividual[iID].GetTestActive() == true)
			{
				--g_iNumActiveTestServers;
				g_cIndividual[iID].SetTestActive(false);
				g_cIndividual[iID].SetTestResult(false);
			}
		}
		return;
	}
	if (g_cHousehold[m_iHouseholdID].GetTestActive() == false)
		return;
	//if (IsEqual(g_cHousehold[m_iHouseholdID].GetTestReturnTime(), g_dTime) == false)
	//	return;
 
	bool iHouseholdQuarantineReleasable = true;
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		if (g_cIndividual[iID].GetTestActive() == true)
		{
			--g_iNumActiveTestServers;
			g_cIndividual[iID].SetTestActive(false);
		}
		if (g_cIndividual[iID].GetTestResult() == true)
		{
			iHouseholdQuarantineReleasable = false;
			if (g_cIndividual[iID].GetQuarantineStatus() == true)
			{
				// ISOLATION DELAY??
				g_cIndividual[iID].QuarantineRelease();
				g_cIndividual[iID].Isolation();
			}
			g_cIndividual[iID].SetTestResult(false);
		}
	}
	g_cHousehold[m_iHouseholdID].SetTestActive(false);
	
	/*if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == true)
	{
		g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
		AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
	}*/
 
		
	if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == true)
	{
	/*	g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime-gc_dQuarantineClock));
		CheckQuarantineRelease(); 
		return;*/
		if (iHouseholdQuarantineReleasable == false)
		{
			if (g_bStopTesting == false)
			{
				g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
				AddEvent(CEventListRecord(g_dTime+gc_dMeanRetestDuration, m_iID, RETEST));
			}
			else
			{
				g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
				AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
			}
		}
		else
		{
			g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime-gc_dQuarantineClock));
			CheckQuarantineRelease();  // Actual release or Quarantine release?
		}
	}
}
 
void CIndividual::Retest()
{
	if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == false)
		return;
	if (IsEqual(g_cHousehold[m_iHouseholdID].GetQuarantineTime()+gc_dMeanRetestDuration, g_dTime) == false)
		return;
 
	/*g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime-gc_dQuarantineClock));
		CheckQuarantineRelease();
		return;*/
	if (g_bStopTesting == true)
	{
		g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime-gc_dQuarantineClock));
		CheckQuarantineRelease();
		return;
	}
 
	bool bTakeTest = false;
	int iCounter, iID;
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		if (g_cIndividual[iID].GetQuarantineStatus() == true && g_cIndividual[iID].GetComplianceStatus() == true)
		{
			bTakeTest = true;
			g_cIndividual[iID].TakeTest();
			AddEvent(CEventListRecord(g_dTime+TestDuration(), iID, TEST_RETURN));
		}
	}
	if (bTakeTest == false)
	{
		g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime-gc_dQuarantineClock));
		CheckQuarantineRelease();
		return;
	}
}
#endif
 
 
int CIndividual::GetHouseholdMember(const int iIndex)
{
	return (g_cHousehold[m_iHouseholdID].GetMemberList())[iIndex];
}
 
int CIndividual::GetPeerGroupMember(const int iIndex)
{
	return (g_cPeerGroup[m_iPeerGroupID].GetMemberList())[iIndex];
}
 
void CIndividual::UpdateFOI(double dOldInfectivity[], double dOldSusceptibility[])
{
	double dInfectivityDelta[2], dSusceptibilityDelta[2];
	int iCounter;
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dInfectivityDelta[iCounter] = GetInfectivity(iCounter)-dOldInfectivity[iCounter];
		if (fabs(dInfectivityDelta[iCounter]) > SMALLEST_DOUBLE)
		{
			if (iCounter == HOUSEHOLD)
				g_cHousehold[m_iHouseholdID].ChangeInfectivity(dInfectivityDelta[iCounter]);
			else if (iCounter == PEERGROUP)
				g_cPeerGroup[m_iPeerGroupID].ChangeInfectivity(dInfectivityDelta[iCounter]);
		}
		dSusceptibilityDelta[iCounter] = GetSusceptibility(iCounter)-dOldSusceptibility[iCounter];
		if (fabs(dSusceptibilityDelta[iCounter]) > SMALLEST_DOUBLE)
		{
			if (iCounter == HOUSEHOLD)
				g_cHousehold[m_iHouseholdID].ChangeSusceptibility(dSusceptibilityDelta[iCounter]);
			else if (iCounter == PEERGROUP)
				g_cPeerGroup[m_iPeerGroupID].ChangeSusceptibility(dSusceptibilityDelta[iCounter]);
		}
	}
	//if (IsEqual(g_cHousehold[m_iHouseholdID].GetFOI(), g_cHousehold[m_iHouseholdID].ComputeFOI()) == false)
	//{
	//	cout << "HH FOI matching failed." << endl;
	//	cout << g_cHousehold[m_iHouseholdID].GetFOI() << " " << g_cHousehold[m_iHouseholdID].ComputeFOI() << endl;
	//	Pause();
	//}
	//if (IsEqual(g_cPeerGroup[m_iPeerGroupID].GetFOI(), g_cPeerGroup[m_iPeerGroupID].ComputeFOI()) == false)
	//{
	//	cout << "PG FOI matching failed." << endl;
	//	cout << g_cPeerGroup[m_iPeerGroupID].GetFOI() << " " << g_cPeerGroup[m_iPeerGroupID].ComputeFOI() << endl;
	//	Pause();
	//}
	//if (g_cHousehold[m_iHouseholdID].GetInfectivity() < -gc_dSmallestInfectivity ||
	//	g_cHousehold[m_iHouseholdID].GetSusceptibility() < -gc_dSmallestSusceptibility ||
	//	g_dTotalFOI[HOUSEHOLD] < -gc_dSmallestFOI)
	//{
	//	cout << "Policy: " << g_sPolicyString[g_iPolicy] << " " << g_dTime << endl;
	//	cout << "Household Inf: " << g_cHousehold[m_iHouseholdID].GetInfectivity() << 
	//		" Household Sus: " << g_cHousehold[m_iHouseholdID].GetSusceptibility() << 
	//		" TotalHHFOI: " << g_dTotalFOI[HOUSEHOLD] << endl;
	//	Pause();
	//}
	//if (g_cPeerGroup[m_iPeerGroupID].GetInfectivity() < -gc_dSmallestInfectivity ||
	//	g_cPeerGroup[m_iPeerGroupID].GetSusceptibility() < -gc_dSmallestSusceptibility ||
	//	g_dTotalFOI[PEERGROUP] < -gc_dSmallestFOI) 
	//{
	//	cout << "Policy: " << g_sPolicyString[g_iPolicy] <<  " " << g_dTime << endl;
	//	cout << "PeerGroup Inf: " << g_cPeerGroup[m_iPeerGroupID].GetInfectivity() << 
	//		" PeerGroup Sus: " << g_cPeerGroup[m_iPeerGroupID].GetSusceptibility() << 
	//		" TotalPGFOI: " << g_dTotalFOI[PEERGROUP] << endl;
	//	Pause();
	//}
}
 
bool CHousehold::IsQuarantineReleasable()
{
	int iCounter, iID;
	for (iCounter = 0; iCounter < GetMemberList().Size(); ++iCounter)
	{
		iID = GetMemberList()[iCounter];
		if (g_cIndividual[iID].GetQuarantineStatus() == true &&
			g_cIndividual[iID].GetComplianceStatus() == true &&
			g_cIndividual[iID].GetSymptomsStatus() == true)
			return false;
	}
	return true;
}
 
void CIndividual::CheckQuarantineRelease()
{
	if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == false)
		return;
	if (IsEqual(g_cHousehold[m_iHouseholdID].GetQuarantineTime()+gc_dQuarantineClock, g_dTime) == false)
		return;
 
	if (g_cHousehold[m_iHouseholdID].IsQuarantineReleasable() == false)
	{
		g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
		AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
		return;
	}
#ifdef DURATION_DETAILS
	float dDummy = g_cHousehold[m_iHouseholdID].GetQuarantineEntryTime();
	short iDummy = static_cast<int>(MIN(MAX_DURATION, floor(0.5+g_dTime-dDummy)));
 
	if (iDummy < 0)
	{ 
		cout << "Index below zero 2" << endl;
		Pause();
	}
	++g_iHouseholdQuarantineDurationPDF[iDummy];
	g_cHousehold[m_iHouseholdID].ChangeTotalQuarantineDuration(iDummy);
	++g_iDailyNumHouseholdsQuarantineReleased;
#endif
	int iCounter, iID;
	for (iCounter =0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		// Note: immune individuals will not enrolled in the program (e.g., no drug is given to them).  However, we count them in activeHouseholdSize
		if (g_cIndividual[iID].GetQuarantineStatus() == true)
		{
#ifdef HISTORY
			g_cIndividual[iID].AddHistory(QuaRelease);
#endif
			g_cIndividual[iID].QuarantineRelease();
		}
	}
	--g_iNumHouseholdsQuarantined;
}
 
void CIndividual::QuarantineRelease()
{
#ifdef DURATION_DETAILS
	short iDummy = static_cast<int>(MIN(MAX_DURATION, floor(g_dTime-m_dQuarantineEntryTime+0.5)));
	if (iDummy < 0)
	{ 
		if (GetSymptomsStatus() == false && iDummy < 7)
		{
			cout << iDummy << endl;
			Pause();
		}
		cout << "Index below zero 3" << endl;
		Pause();
	}
	//	if (IsEqual(m_dQuarantineEntryTime, g_cHousehold[m_iHouseholdID].GetQuarantineEntryTime()) == true) 
	m_iTotalQuarantineDuration += iDummy;
	++g_iQuarantineDurationPDF[iDummy];
#endif
	if (g_bDrugActive == true)
	{
		if (m_bComplianceStatus == true && m_bDrugStatus == true)
		{
			if (m_iDiseaseStatus == SYMPTOMATIC)
				g_dDailyDrugUsedQuarantineSymp += g_dTime-m_dTimeRecord;
			else
				g_dDailyDrugUsedQuarantineNonSymp += g_dTime-m_dTimeRecord;
		}
		if (m_bComplianceStatus == false)
			g_dDailyDrugUsedQuarantineNonComp += g_dTime-m_dTimeRecord;
 
		//if (m_bComplianceStatus == true && m_bDrugStatus == true)
		//	g_dDailyDrugUsed += g_dTime-m_dTimeRecord;
		//g_dDailyDrugUsedAll += g_dTime-m_dTimeRecord;
	}
	--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	--g_iNumQuarantined;
	double dOldInfectivity[2], dOldSusceptibility[2];
	int iCounter;
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dOldInfectivity[iCounter] = GetInfectivity(iCounter);
		dOldSusceptibility[iCounter] = GetSusceptibility(iCounter);
	}
	m_bLeadStatus = false;
	m_bQuarantineStatus = false;
	m_bComplianceStatus = false;
	m_bDrugStatus = false; //// fkf
	UpdateFOI(dOldInfectivity, dOldSusceptibility);
 
	++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	++g_iDailyNumQuarantineReleased;
 
	m_dTimeRecord = LARGE_NUMBER;
	if (GetInfectivity(HOUSEHOLD) > gc_dSmallestInfectivity)
		g_iDailyLeakage++;
	if (g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == false)
		g_cHousehold[m_iHouseholdID].SetDrugTime(LARGE_NUMBER);
}
 
void CIndividual::Report()
{
	// Record family membership if this is the first time they are observed
 
	m_bImmuneStatus = false;  // if he reports, he must not be immune   
	m_bLeadStatus = true;
	++g_iNumHouseholdsQuarantined;
#ifdef DURATION_DETAILS
	g_cHousehold[m_iHouseholdID].IncreaseQuarantineTimes();
#endif
	int iCounter, iID, iTraceActive = false;
#ifdef CONTACT_TRACING
	g_cHousehold[m_iHouseholdID].SetHouseholdSeen(true);
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		if (g_cIndividual[iID].GetCTActive() == true)
		{
			g_cIndividual[iID].PushCTList();
			iTraceActive = true;
			break;
		}
	}
	// Take family members off CTList if any
	if (iTraceActive == false)
	{
		for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
		{
			iID = GetHouseholdMember(iCounter);
			if (g_cIndividual[iID].GetCTListStatus() == true)
				g_cIndividual[iID].RemovedFromCTList(true);
		}       
	}
#endif
 
	bool bQuarantine = false;
	for (iCounter = 0; iCounter < GetHouseholdSize(); ++iCounter)
	{
		iID = GetHouseholdMember(iCounter);
		// Note: immune individuals will not enrolled in the program (e.g., no drug is given to them).  However, we count them in activeHouseholdSize
		if (g_cIndividual[iID].IsQuarantinable() == true)
		{
			g_cIndividual[iID].Quarantine(true);
			bQuarantine = true;
		}
	}
	if (g_bDrugActive == true && bQuarantine == true)
	{
		float dDummy = static_cast<float>(g_dTime+DrugDelay());
		g_cHousehold[m_iHouseholdID].SetDrugTime(dDummy);
		AddEvent(CEventListRecord(dDummy, m_iID, DRUG_ACTIVATE));
	}
}
 
void CIndividual::SetPeerGroupActive(const bool x)
{
	double dOldInfectivityPeerGroup = GetInfectivity(PEERGROUP), dInfectivityDeltaPeerGroup;
	double dOldSusceptibilityPeerGroup = GetSusceptibility(PEERGROUP), dSusceptibilityDeltaPeerGroup;
 
	m_bPeerGroupActive = x;
 
	dInfectivityDeltaPeerGroup = GetInfectivity(PEERGROUP)-dOldInfectivityPeerGroup; 
	if (fabs(dInfectivityDeltaPeerGroup) > SMALLEST_DOUBLE)
		g_cPeerGroup[m_iPeerGroupID].ChangeInfectivity(dInfectivityDeltaPeerGroup);		
 
	dSusceptibilityDeltaPeerGroup = GetSusceptibility(PEERGROUP)-dOldSusceptibilityPeerGroup; 
	if (fabs(dSusceptibilityDeltaPeerGroup) > SMALLEST_DOUBLE)
		g_cPeerGroup[m_iPeerGroupID].ChangeSusceptibility(dSusceptibilityDeltaPeerGroup);		
}
 
void CIndividual::SetDiseaseStatus(const int iNewDiseaseStatus)
{
	double dOldInfectivityHousehold = GetInfectivity(HOUSEHOLD), dInfectivityDeltaHousehold,
		dOldInfectivityPeerGroup = GetInfectivity(PEERGROUP), dInfectivityDeltaPeerGroup;
	--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	m_iDiseaseStatus = iNewDiseaseStatus;
	++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	dInfectivityDeltaHousehold = GetInfectivity(HOUSEHOLD)-dOldInfectivityHousehold; 
	if (fabs(dInfectivityDeltaHousehold) > SMALLEST_DOUBLE)
		g_cHousehold[m_iHouseholdID].ChangeInfectivity(dInfectivityDeltaHousehold);
	dInfectivityDeltaPeerGroup = GetInfectivity(PEERGROUP)-dOldInfectivityPeerGroup; 
	if (fabs(dInfectivityDeltaPeerGroup) > SMALLEST_DOUBLE)
		g_cPeerGroup[m_iPeerGroupID].ChangeInfectivity(dInfectivityDeltaPeerGroup);
}
 
 
void CIndividual::SusceptibleToExposed()
{
#ifdef HISTORY
	addHistory(StoE);
#endif   
#ifdef SYMPTOMS_DESTINED
	if (Probability() < gc_dAgeProbSymptoms[m_iAgeGroup])
		m_bWillBeSymptomatic = true;
#endif
	++g_iInfectionIncidence;
	g_cHousehold[m_iHouseholdID].ChangeSusceptibility(-GetSusceptibility(HOUSEHOLD));
	g_cPeerGroup[m_iPeerGroupID].ChangeSusceptibility(-GetSusceptibility(PEERGROUP));
	SetDiseaseStatus(EXPOSED);
#ifdef CHECK_TARGETS
	if (m_iID != g_iSelectedSeed)
		return;
#endif
 
	AddEvent(CEventListRecord(g_dTime+ExposedDuration(), m_iID, PROGRESSION));
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToExposed2()
{
#ifdef HISTORY
	addHistory(StoE);
#endif   
#ifdef SYMPTOMS_DESTINED
	if (Probability() < gc_dAgeProbSymptoms[m_iAgeGroup])
		m_bWillBeSymptomatic = true;
#endif
	++g_iInfectionIncidence;
	g_cHousehold[m_iHouseholdID].ChangeSusceptibility(-GetSusceptibility(HOUSEHOLD));
	g_cPeerGroup[m_iPeerGroupID].ChangeSusceptibility(-GetSusceptibility(PEERGROUP));
	SetDiseaseStatus(EXPOSED);
#ifdef CHECK_TARGETS
	if (m_iID != g_iSelectedSeed)
		return;
#endif
	AddEvent(CEventListRecord(g_dTime+ExposedDuration(), m_iID, PROGRESSION));
}
 
 
 
 
void CIndividual::ExposedToPresymptomatic()
{
#ifdef HISTORY
	addHistory(EtoI_P);
#endif  
	SetDiseaseStatus(PRESYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+PresymptomaticDuration(), m_iID, PROGRESSION));
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToPresymptomatic2()
{
#ifdef HISTORY
	addHistory(EtoI_P);
#endif  
	SetDiseaseStatus(PRESYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+PresymptomaticDuration(), m_iID, PROGRESSION));
}
 
 
 
 
void CIndividual::PresymptomaticToAsymptomatic()
{
#ifdef HISTORY
	addHistory(I_PtoI_A);
#endif  
	SetDiseaseStatus(ASYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+AsymptomaticDuration(), m_iID, PROGRESSION));
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToAsymptomatic2()
{
#ifdef HISTORY
	addHistory(I_PtoI_A);
#endif  
	SetDiseaseStatus(ASYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+AsymptomaticDuration(), m_iID, PROGRESSION));
}
 
 
 
 
 
void CIndividual::PresymptomaticToSymptomatic()
{
#ifdef HISTORY
	addHistory(I_PtoS);
#endif  
 
	if (m_bAdultStatus == false)
	{
		if (Probability() > g_dProbSymActiveChildren)
			SetPeerGroupActive(false);
		//m_bPeerGroupActive = false;
	}
	else if (Probability() > g_dProbSymActiveAdults)
		SetPeerGroupActive(false);
	//m_bPeerGroupActive = false;
	SetDiseaseStatus(SYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+SymptomaticDuration(), m_iID, PROGRESSION));
	if (g_bQuarantineActive == true)
	{
#ifdef CONTACT_TRACING
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && g_bTracingActive == true && m_bAdultStatus == true)
			TraceContacts();
#endif
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && m_bDrugStatus == true)
		{
			g_dDailyDrugUsedQuarantineNonSymp += g_dTime-m_dTimeRecord;			
			m_dTimeRecord = static_cast<float>(g_dTime);
		}
 
		if ((m_bQuarantineStatus == true && m_bComplianceStatus == true) || 
			(m_bIsolationStatus == true && 	g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == true))
		{
			g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
			AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
		}
		else if (m_bQuarantineStatus == false && m_bIsolationStatus == false && Probability() < g_dProbReport)
			Report();
	}
	if (g_bIsolationActive == true)
	{
		if (m_bIsolationStatus == true)
		{
			m_dTimeRecord = static_cast<float>(g_dTime);
			AddEvent(CEventListRecord(g_dTime+gc_dIsolationClock, m_iID, ISOLATION_RELEASE));   
		}
		else
		{
			if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
			{
				if (Probability() < g_dProbIsolation)
				{
					// Modification
					AddEvent(CEventListRecord(g_dTime+IsolationDelay(), m_iID, ISOLATION));   
					/*QuarantineRelease();
					Isolation();*/
				}
			}
		}
	}
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToSymptomatic2()
{
#ifdef HISTORY
	addHistory(I_PtoS);
#endif  
 
	if (m_bAdultStatus == false)
	{
		if (Probability() > g_dProbSymActiveChildren)
			SetPeerGroupActive(false);
	}
	else if (Probability() > g_dProbSymActiveAdults)
		SetPeerGroupActive(false);
	SetDiseaseStatus(SYMPTOMATIC);
	AddEvent(CEventListRecord(g_dTime+SymptomaticDuration(), m_iID, PROGRESSION));
	if (g_bQuarantineActive == true)
	{
#ifdef CONTACT_TRACING
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && g_bTracingActive == true && m_bAdultStatus == true)
			TraceContacts();
#endif
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && m_bDrugStatus == true)
		{
			g_dDailyDrugUsedQuarantineNonSymp += g_dTime-m_dTimeRecord;			
			m_dTimeRecord = static_cast<float>(g_dTime);
		}
 
		if ((m_bQuarantineStatus == true && m_bComplianceStatus == true) || 
			(m_bIsolationStatus == true && 	g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == true))
		{
			g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
			AddEvent(CEventListRecord(g_dTime, m_iID+gc_dQuarantineClock, QUARANTINE_RELEASE));
		}
		else if (m_bQuarantineStatus == false && m_bIsolationStatus == false && Probability() < g_dProbReport)
			Report();
	}
	if (g_bIsolationActive == true)
	{
		if (m_bIsolationStatus == true)
		{
			m_dTimeRecord = static_cast<float>(g_dTime);
			AddEvent(CEventListRecord(g_dTime+gc_dIsolationClock, m_iID, ISOLATION_RELEASE));   
		}
		else
		{
			if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
			{
				if (Probability() < g_dProbIsolation)
				{
					// Modification
					AddEvent(CEventListRecord(g_dTime+IsolationDelay(), m_iID, ISOLATION));   
					/*QuarantineRelease();
					Isolation();*/
				}
			}
		}
	}
}
 
 
 
 
void CIndividual::AsymptomaticToRecovered()
{
#ifdef HISTORY
	addHistory(I_AtoR);
#endif  
	SetDiseaseStatus(RECOVERED);
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToRecovered2()
{
#ifdef HISTORY
	addHistory(I_AtoR);
#endif  
	SetDiseaseStatus(RECOVERED);
}
 
 
 
 
void CIndividual::SymptomaticToHospitalized()
{
#ifdef HISTORY
	addHistory(I_StoH);
#endif  
	m_bSpamStatus = false;
#ifdef TESTING
	if (m_bTestActive == true)
		m_bTestResult = true;
#endif
 
	SetDiseaseStatus(HOSPITALIZED);
	if (g_bQuarantineActive == true)
	{
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && m_bDrugStatus == true)
		{
			g_dDailyDrugUsedQuarantineSymp += g_dTime-m_dTimeRecord;			
			m_dTimeRecord = static_cast<float>(g_dTime);
		}
 
		if (m_bIsolationStatus == false)
		{
			if (m_bQuarantineStatus == false)
				Report();
			else 
			{
				g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
				AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
			}
			QuarantineRelease();
		}
	}
 
	if (m_bIsolationStatus == false)
		Isolation();
	AddEvent(CEventListRecord(g_dTime+HospitalizationDuration(), m_iID, PROGRESSION));
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToHospitalized2()
{
#ifdef HISTORY
	addHistory(I_StoH);
#endif  
	m_bSpamStatus = false;
#ifdef TESTING
	if (m_bTestActive == true)
		m_bTestResult = true;
#endif
 
	SetDiseaseStatus(HOSPITALIZED);
	if (g_bQuarantineActive == true)
	{
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true && m_bDrugStatus == true)
		{
			g_dDailyDrugUsedQuarantineSymp += g_dTime-m_dTimeRecord;			
			m_dTimeRecord = static_cast<float>(g_dTime);
		}
 
		if (m_bIsolationStatus == false)
		{
			if (m_bQuarantineStatus == false)
				Report();
			else 
			{
				g_cHousehold[m_iHouseholdID].SetQuarantineTime(static_cast<float>(g_dTime));
				AddEvent(CEventListRecord(g_dTime+gc_dQuarantineClock, m_iID, QUARANTINE_RELEASE));
			}
			QuarantineRelease();
		}
	}
 
	if (m_bIsolationStatus == false)
		Isolation();
	AddEvent(CEventListRecord(g_dTime+HospitalizationDuration(), m_iID, PROGRESSION));
}
 
 
 
 
void CIndividual::SymptomaticToRecovered()
{
#ifdef HISTORY
	addHistory(I_StoR);
#endif  
	if (m_bQuarantineStatus == true && m_bComplianceStatus == true && m_bDrugStatus == true)
	{
		g_dDailyDrugUsedQuarantineSymp += g_dTime-m_dTimeRecord;			
		m_dTimeRecord = static_cast<float>(g_dTime);
	}
 
	SetDiseaseStatus(RECOVERED);
}
 
 
void CIndividual::HospitalizedToRecovered()
{
#ifdef HISTORY
	addHistory(HtoR);
#endif  
	SetDiseaseStatus(RECOVERED);
	m_bImmuneStatus = true;
}
 
 
void CIndividual::HospitalizedToDead()
{
#ifdef HISTORY
	addHistory(HtoD);
#endif  
	g_dDailyDrugUsedIsolation += g_dTime-m_dTimeRecord;
	//g_dDailyDrugUsed += g_dTime-m_dTimeRecord;
	//g_dDailyDrugUsedAll += g_dTime-m_dTimeRecord;
	SetDiseaseStatus(DEAD);
	if (m_bIsolationStatus == true)
	{
#ifdef DURATION_DETAILS
		short iDummy = static_cast<int>(MIN(MAX_DURATION, floor(g_dTime-m_dIsolationEntryTime+0.5)));
		if (iDummy < 0)
		{ 
			cout << "Index below zero 1" << endl;
			Pause();
		}
		m_iTotalIsolationDuration += iDummy;
		++g_iIsolationDurationPDF[iDummy];
#endif
		--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
		--g_iNumIsolated;
//ISOLATION SEPARATED
		--g_iCountyNumIsolated[m_iCountyID];
		++g_iTotalNumIsolationReleased;
		m_bIsolationStatus = false;
		++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	}
	m_bImmuneStatus = true;
}
 
 
//SUBROUTINE FOR INITIALIZATION
void CIndividual::SusceptibleToDead2()
{
#ifdef HISTORY
	addHistory(HtoD);
#endif  
	SetDiseaseStatus(DEAD);
	if (m_bIsolationStatus == true)
	{
		--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
		--g_iNumIsolated;
//ISOLATION SEPARATED
		--g_iCountyNumIsolated[m_iCountyID];
		++g_iTotalNumIsolationReleased;
		m_bIsolationStatus = false;
		++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	}
	m_bImmuneStatus = true;
}
 
 
 
 
void CIndividual::DiseaseProgression()
{
 
	switch (m_iDiseaseStatus)
	{
	case SUSCEPTIBLE:
		SusceptibleToExposed();
		break;
	case EXPOSED: 
		ExposedToPresymptomatic();
		break;
	case PRESYMPTOMATIC:
		{
#ifdef SYMPTOMS_DESTINED
			if (m_bWillBeSymptomatic == true)
#else
			if (Probability() < gc_dAgeProbSymptoms[m_iAgeGroup])
#endif
				PresymptomaticToSymptomatic();
			else
				PresymptomaticToAsymptomatic();
		}
		break;
	case ASYMPTOMATIC:
		AsymptomaticToRecovered();
		break;
	case SYMPTOMATIC:
		{
			if (Probability() < gc_dAgeProbHospitalization[m_iAgeGroup])
				SymptomaticToHospitalized();
			else
				SymptomaticToRecovered();
		}
		break;
	case HOSPITALIZED:
		{
			if (Probability() < gc_dAgeProbDeath[m_iAgeGroup])
				HospitalizedToDead();
			else
				HospitalizedToRecovered();
		}
		break;
	default:
		{
			cout << "Unknown disease stage in Progression(): ID = " << m_iID << ", DiseaseStatus = " << m_iDiseaseStatus << endl;
			Pause();
			exit(0);
		}
		break;
	}
}
 
 
 
void CIndividual::Isolation()
{
#ifdef DURATION_DETAILS
	m_dIsolationEntryTime =  static_cast<float>(g_dTime);	
	++m_iIsolationTimes;
#endif
	int iCounter;
 
	--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	++g_iNumIsolated;
//ISOLATION SEPARATED
	--g_iCountyNumIsolated[m_iCountyID];
	++g_iIsolationIncidence;
 
	double dOldInfectivity[2], dOldSusceptibility[2];
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dOldInfectivity[iCounter] = GetInfectivity(iCounter);
		dOldSusceptibility[iCounter] = GetSusceptibility(iCounter);
	}
	m_bLeadStatus = false;
	m_bIsolationStatus = true;
	m_bQuarantineStatus = false;
	m_bComplianceStatus = false;
	m_dTimeRecord = static_cast<float>(g_dTime);
 
	UpdateFOI(dOldInfectivity, dOldSusceptibility);
	g_cHousehold[m_iHouseholdID].ChangeActiveHouseholdSize(-1);
	if (g_bQuarantineActive == true && g_cHousehold[m_iHouseholdID].ComputeActiveHouseholdSize() == 0)
		--g_iNumHouseholdsQuarantined;
 
	++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	AddEvent(CEventListRecord(g_dTime+gc_dIsolationClock, m_iID, ISOLATION_RELEASE));   
#ifdef HISTORY
	addHistory(isolation);
#endif  
}
 
void CIndividual::IsolationRelease()
{
	if (m_iDiseaseStatus == DEAD)
		return;
 
	if (IsEqual(m_dTimeRecord+gc_dIsolationClock, g_dTime) == false)
		return;
 
	g_dDailyDrugUsedIsolation += g_dTime-m_dTimeRecord;
	//g_dDailyDrugUsed += g_dTime-m_dTimeRecord;
	//g_dDailyDrugUsedAll += g_dTime-m_dTimeRecord;
 
	if ((g_bTestingActive == false && GetSymptomsStatus() == true) || 
		(g_bTestingActive == true && GetFluStatus() == true))
	{
		m_dTimeRecord = static_cast<float>(g_dTime);
		AddEvent(CEventListRecord(g_dTime+gc_dIsolationClock, m_iID, ISOLATION_RELEASE));   
		return;
	}
#ifdef DURATION_DETAILS
	short iDummy = static_cast<int>(MIN(MAX_DURATION, floor(g_dTime-m_dIsolationEntryTime+0.5)));
	if (iDummy < 0)
	{ 
		cout << "Index below zero 1" << endl;
		Pause();
	}
	++m_iTotalIsolationDuration += iDummy;
	++g_iIsolationDurationPDF[iDummy];
#endif
	--g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	--g_iNumIsolated;
//ISOLATION SEPARATED
	--g_iCountyNumIsolated[m_iCountyID];
	++g_iDailyNumIsolationReleased;
 
	int iCounter;
	double dOldInfectivity[2], dOldSusceptibility[2];
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dOldInfectivity[iCounter] = GetInfectivity(iCounter);
		dOldSusceptibility[iCounter] = GetSusceptibility(iCounter);
	}
 
	m_bIsolationStatus = false;
	++g_iHeadCount[m_iDiseaseStatus][m_bQuarantineStatus][m_bComplianceStatus][m_bIsolationStatus][m_iCountyID];
	UpdateFOI(dOldInfectivity, dOldSusceptibility);
 
	m_dTimeRecord = LARGE_NUMBER;
 
	if (IsQuarantinable() == true && g_cHousehold[m_iHouseholdID].GetHouseholdQuarantineStatus() == true)
	{
		Quarantine(false);
		if (g_cHousehold[m_iHouseholdID].GetHouseholdDrugStatus() == true)
		{
			for (iCounter = 0; iCounter < 2; ++iCounter)
			{
				dOldInfectivity[iCounter] = GetInfectivity(iCounter);
				dOldSusceptibility[iCounter] = GetSusceptibility(iCounter);
			}
			m_bDrugStatus = true;
			m_dTimeRecord = static_cast<float>(g_dTime);
			UpdateFOI(dOldInfectivity, dOldSusceptibility);
		}
	}
	g_cHousehold[m_iHouseholdID].ChangeActiveHouseholdSize(1);
}
 
// iGroupType in {HOUSEHOLD, PEERGROUP}
// iGroupSubtype corresponds to the size of the group
void UpdateFOIEngine(const int iGroupType, const int iGroupSubtype)
{
	double dGroupFOI;
	CMySet<int, unsigned int> *pInfectorGroup;
	int iCounter, iCounter2, iGroupID, iPosFOIEngine, iReplaceGroupID;
	// First, remove all old entries 
	for (iCounter = 0; iCounter < g_cFOIPerturbedList[iGroupType][iGroupSubtype].Size(); ++iCounter)
	{
		iGroupID = g_cFOIPerturbedList[iGroupType][iGroupSubtype][iCounter].GetID();
		if (g_cFOIPerturbedList[iGroupType][iGroupSubtype][iCounter].GetOldFOI() > gc_dSmallestFOI)
		{
			if (iGroupType == HOUSEHOLD)
				iPosFOIEngine = g_cHousehold[iGroupID].GetPosFOIEngine();
			else if (iGroupType == PEERGROUP)
				iPosFOIEngine = g_cPeerGroup[iGroupID].GetPosFOIEngine();
 
			pInfectorGroup = g_cFOIEngine[iGroupType][iGroupSubtype][iPosFOIEngine].GetPtrInfectorGroup();
			if (iGroupType == HOUSEHOLD)
			{
				iReplaceGroupID = (*pInfectorGroup).Erase(g_cHousehold[iGroupID].GetPosInfectorGroup());
				g_cHousehold[iReplaceGroupID].SetPosInfectorGroup(g_cHousehold[iGroupID].GetPosInfectorGroup());
			}
			if (iGroupType == PEERGROUP)
			{
				iReplaceGroupID = (*pInfectorGroup).Erase(g_cPeerGroup[iGroupID].GetPosInfectorGroup());
				g_cPeerGroup[iReplaceGroupID].SetPosInfectorGroup(g_cPeerGroup[iGroupID].GetPosInfectorGroup());
			}
			if ((*pInfectorGroup).Empty() == true)
			{
				(*pInfectorGroup).Resize(1);
				g_cEmptyFOIEngineSlot[iGroupType][iGroupSubtype].Push(iPosFOIEngine);
			}
		}
	}
	// Second, put the new entries into the engine 
	bool bHasSlot;
	for (iCounter = 0; iCounter < g_cFOIPerturbedList[iGroupType][iGroupSubtype].Size(); ++iCounter)
	{
		iGroupID = g_cFOIPerturbedList[iGroupType][iGroupSubtype][iCounter].GetID();
		if (iGroupType == HOUSEHOLD)
			dGroupFOI = g_cHousehold[iGroupID].GetFOI();
		else if (iGroupType == PEERGROUP)
			dGroupFOI = g_cPeerGroup[iGroupID].GetFOI();
		if (dGroupFOI > gc_dSmallestFOI)
		{
			for (iCounter2 = 0; iCounter2 < g_cFOIEngine[iGroupType][iGroupSubtype].Size(); ++iCounter2)
			{
				if (IsEqual(g_cFOIEngine[iGroupType][iGroupSubtype][iCounter2].GetFOI(), dGroupFOI) == true)
					break;
			}
			if (iCounter2 < g_cFOIEngine[iGroupType][iGroupSubtype].Size())
			{
				iPosFOIEngine = iCounter2;
				pInfectorGroup = g_cFOIEngine[iGroupType][iGroupSubtype][iPosFOIEngine].GetPtrInfectorGroup();
			}
			else
			{
				bHasSlot = false;
				while (bHasSlot == false && g_cEmptyFOIEngineSlot[iGroupType][iGroupSubtype].Empty() == false)
				{
					iPosFOIEngine = g_cEmptyFOIEngineSlot[iGroupType][iGroupSubtype].Top();
					g_cEmptyFOIEngineSlot[iGroupType][iGroupSubtype].Pop();
					pInfectorGroup = g_cFOIEngine[iGroupType][iGroupSubtype][iPosFOIEngine].GetPtrInfectorGroup();
					if ((*pInfectorGroup).Empty() == true)
						bHasSlot = true;
				}
				if (bHasSlot == false)
				{
					if (g_cFreePtrInfectorGroup.empty() == false)
					{
						pInfectorGroup = g_cFreePtrInfectorGroup[g_cFreePtrInfectorGroup.size()-1];
						g_cFreePtrInfectorGroup.pop_back(); 
					}
					else
						pInfectorGroup = new CMySet<int, unsigned int>;
 
					(*pInfectorGroup).Resize(10);
					CFOIEngineElement x(dGroupFOI, pInfectorGroup);
					iPosFOIEngine = g_cFOIEngine[iGroupType][iGroupSubtype].Push(x);
				}
				else
				{
					g_cFOIEngine[iGroupType][iGroupSubtype][iPosFOIEngine].SetFOI(dGroupFOI);
					g_cFOIEngine[iGroupType][iGroupSubtype][iPosFOIEngine].SetPtrInfectorGroup(pInfectorGroup);
				}
			}
			if (iGroupType == HOUSEHOLD)
			{
				g_cHousehold[iGroupID].SetPosFOIEngine(iPosFOIEngine);
				g_cHousehold[iGroupID].SetPosInfectorGroup((*pInfectorGroup).Push(iGroupID));
			}
			if (iGroupType == PEERGROUP)
			{
				g_cPeerGroup[iGroupID].SetPosFOIEngine(iPosFOIEngine);
				g_cPeerGroup[iGroupID].SetPosInfectorGroup((*pInfectorGroup).Push(iGroupID));
			}
		}
		if (iGroupType == HOUSEHOLD)
			g_cHousehold[iGroupID].SetFOIPerturbedStatus(false);
		else if (iGroupType == PEERGROUP)
			g_cPeerGroup[iGroupID].SetFOIPerturbedStatus(false);
	}
}
 
int SelectInfectee(const int iGroupType, const int iGroupSubtype, double dFOICutOff)
{
	double dCumulativeFOI = 0, dGroupFOI, dInfectorGroupFOI;
	CMySet<int, unsigned int> *pInfectorGroup;
	int iCounter, iChosenID = -1;
 
	dCumulativeFOI = 0;
	int iChosenIndex;
	double dFOICutOffNext;
	if (dFOICutOff < g_dFOI[iGroupType][iGroupSubtype]/2.0)
	{
		for (iCounter = 0; iCounter < g_cFOIEngine[iGroupType][iGroupSubtype].Size(); ++iCounter)
		{
			pInfectorGroup = g_cFOIEngine[iGroupType][iGroupSubtype][iCounter].GetPtrInfectorGroup();
			dGroupFOI = g_cFOIEngine[iGroupType][iGroupSubtype][iCounter].GetFOI();
 
			if ((*pInfectorGroup).Size() > 0)
			{
				dInfectorGroupFOI = dGroupFOI*(*pInfectorGroup).Size();
				dCumulativeFOI += dInfectorGroupFOI;
				if (dCumulativeFOI > dFOICutOff)
				{ 
					iChosenIndex = static_cast<int>(MIN((*pInfectorGroup).Size()-1,
						floor((dFOICutOff-(dCumulativeFOI-dInfectorGroupFOI))/dGroupFOI)));
					dFOICutOffNext = (dFOICutOff-(dCumulativeFOI-dInfectorGroupFOI))-iChosenIndex*dGroupFOI;
					iChosenID = (*pInfectorGroup)[iChosenIndex];
					break;
				}
			}
		}	
	}
	else
	{
		dCumulativeFOI = g_dFOI[iGroupType][iGroupSubtype];
		for (iCounter = g_cFOIEngine[iGroupType][iGroupSubtype].Size()-1; iCounter > -1; --iCounter)
		{
			pInfectorGroup = g_cFOIEngine[iGroupType][iGroupSubtype][iCounter].GetPtrInfectorGroup();
			dGroupFOI = g_cFOIEngine[iGroupType][iGroupSubtype][iCounter].GetFOI();
			if ((*pInfectorGroup).Size() > 0)
			{
				dInfectorGroupFOI = dGroupFOI*(*pInfectorGroup).Size();
				dCumulativeFOI -= dInfectorGroupFOI;
				if (dCumulativeFOI < dFOICutOff)
				{ 
					iChosenIndex = static_cast<int>MIN((*pInfectorGroup).Size()-1, 
						(floor((dFOICutOff-dCumulativeFOI)/dGroupFOI)));
					dFOICutOffNext = (dFOICutOff-dCumulativeFOI)-iChosenIndex*dGroupFOI;
					iChosenID = (*pInfectorGroup)[iChosenIndex];
					break;
				}
			}
		}
	}
 
	if (iChosenID < 0 || iChosenID > gc_iPopulationSizeTotal-1)
	{
		cout << "Error in SelectInfectee()!" << endl;
		cout << "ChosenID = " << iChosenID << " with index " << iChosenIndex << endl;
		cout << "Counter = " << iCounter << " with group size = " << (*pInfectorGroup).Size() << endl;
		cout << "CumulativeFOI = " << dCumulativeFOI << ", FOICutOff = " << dFOICutOff <<  endl;
		Pause();
	}
	if (iGroupType == HOUSEHOLD)
		return g_cHousehold[iChosenID].SelectInfectee(dFOICutOffNext);	
	else if (iGroupType == PEERGROUP)
		return g_cPeerGroup[iChosenID].SelectInfectee(dFOICutOffNext);	
	else
	{
		cout << "Error in SelectInfectee()." << endl;
		Pause();
		exit(0);
	}
}
 
void CheckFOI()
{
	int iCounter;
	double *dHHCumulativeFOI, *dPGCumulativeFOI;
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dHHCumulativeFOI = new double[gc_iNumEngineSlots];
		dPGCumulativeFOI = new double[gc_iNumEngineSlots];
	}
 
	for (iCounter = 0; iCounter < gc_iNumEngineSlots; ++iCounter)
	{
		dHHCumulativeFOI[iCounter] = 0;
		dPGCumulativeFOI[iCounter] = 0;
	}
 
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
		dHHCumulativeFOI[static_cast<int>(floor(iCounter/
		static_cast<double>(g_iNumGroups[HOUSEHOLD]-1)*(gc_iNumEngineSlots-1)))] += 
		g_cHousehold[iCounter].ComputeFOI();
 
	for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
		dPGCumulativeFOI[static_cast<int>(floor(iCounter/
		static_cast<double>(g_iNumGroups[PEERGROUP]-1)*(gc_iNumEngineSlots-1)))] += 
		g_cPeerGroup[iCounter].ComputeFOI();
 
	double dHHTotalFOI = 0, dPGTotalFOI = 0;
	for (iCounter = 0; iCounter < gc_iNumEngineSlots; ++iCounter)
	{
		if (IsEqual(dHHCumulativeFOI[iCounter], g_dFOI[HOUSEHOLD][iCounter]) == false)
		{
			cout << "Error in CheckFOI.  iCounter = " << iCounter << endl;
			cout << "Household: " << dHHCumulativeFOI[iCounter] << " " << g_dFOI[HOUSEHOLD][iCounter] << endl;
			Pause();
		}
		if (IsEqual(dPGCumulativeFOI[iCounter], g_dFOI[PEERGROUP][iCounter]) == false)
		{
			cout << "Error in CheckFOI." << endl;
			cout << "PeerGroup: " << dPGCumulativeFOI[iCounter] << " " << g_dFOI[PEERGROUP][iCounter] << endl;
			Pause();
		}
		dHHTotalFOI += dHHCumulativeFOI[iCounter];
		dPGTotalFOI += dPGCumulativeFOI[iCounter];
	}
	if (IsEqual(dHHTotalFOI, g_dTotalFOI[HOUSEHOLD]) == false)
	{
		cout << "Error in CheckFOI." << endl;
		cout << "Household: " << dHHTotalFOI << " " << g_dTotalFOI[HOUSEHOLD] << endl;
		Pause();
	}
	if (IsEqual(dPGTotalFOI, g_dTotalFOI[PEERGROUP]) == false)
	{
		cout << "Error in CheckFOI." << endl;
		cout << "PeerGroup: " << dPGTotalFOI << " " << g_dTotalFOI[PEERGROUP] << endl;
		Pause();
	}
	delete [] dHHCumulativeFOI;
	delete [] dPGCumulativeFOI;
}
 
 
void RefreshFOI()
{
	int iCounter;
	double *dHHCumulativeFOI, *dPGCumulativeFOI;
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		dHHCumulativeFOI = new double[gc_iNumEngineSlots];
		dPGCumulativeFOI = new double[gc_iNumEngineSlots];
	}
 
	for (iCounter = 0; iCounter < gc_iNumEngineSlots; ++iCounter)
	{
		dHHCumulativeFOI[iCounter] = 0;
		dPGCumulativeFOI[iCounter] = 0;
	}
 
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
		dHHCumulativeFOI[static_cast<int>(floor(iCounter/
		static_cast<double>(g_iNumGroups[HOUSEHOLD]-1)*(gc_iNumEngineSlots-1)))] += 
		g_cHousehold[iCounter].ComputeFOI();
 
	for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
		dPGCumulativeFOI[static_cast<int>(floor(iCounter/
		static_cast<double>(g_iNumGroups[PEERGROUP]-1)*(gc_iNumEngineSlots-1)))] += 
		g_cPeerGroup[iCounter].ComputeFOI();
 
	double dHHTotalFOI = 0, dPGTotalFOI = 0;
	for (iCounter = 0; iCounter < gc_iNumEngineSlots; ++iCounter)
	{
		g_dFOI[HOUSEHOLD][iCounter] = dHHCumulativeFOI[iCounter];
		g_dFOI[PEERGROUP][iCounter] = dPGCumulativeFOI[iCounter];
		dHHTotalFOI += dHHCumulativeFOI[iCounter];
		dPGTotalFOI += dPGCumulativeFOI[iCounter];
	}
	g_dTotalFOI[HOUSEHOLD] = dHHTotalFOI;
	g_dTotalFOI[PEERGROUP] = dPGTotalFOI;
 
	delete [] dHHCumulativeFOI;
	delete [] dPGCumulativeFOI;
}
 
void ProcessCloseInfection()
{
	double dProbability = Probability(), dTotalCloseFOI = g_dTotalFOI[HOUSEHOLD]+g_dTotalFOI[PEERGROUP], dFOICutOff;
	int iCounter, iChosenInfectee, iChosenSubtype, iGroupType;
 
/*
	if (dProbability < g_dTotalFOI[HOUSEHOLD]/dTotalCloseFOI)
	{
		iGroupType = HOUSEHOLD;
		dFOICutOff = dProbability*dTotalCloseFOI;
	}
	else
	{
		iGroupType = PEERGROUP;
		dFOICutOff = dProbability*dTotalCloseFOI-g_dTotalFOI[HOUSEHOLD];
	}
*/
 
//NIGHT DAY DIFFERENTIATION
	iGroupType = selected_group;
	dFOICutOff = dProbability*g_dTotalFOI[iGroupType];
 
	double dCumulativeFOI = 0;
	if (dFOICutOff < g_dTotalFOI[iGroupType]/2.0)
	{
		for (iCounter = 0; iCounter < gc_iNumEngineSlots; ++iCounter)
		{
			dCumulativeFOI += g_dFOI[iGroupType][iCounter];
			if (dCumulativeFOI > dFOICutOff)
			{
				iChosenSubtype = iCounter;
				break;
			}
		}
		dFOICutOff = dFOICutOff-(dCumulativeFOI-g_dFOI[iGroupType][iChosenSubtype]);
	}
	else
	{
		dCumulativeFOI = g_dTotalFOI[iGroupType];
		for (iCounter = gc_iNumEngineSlots-1; iCounter > -1; --iCounter)
		{
			dCumulativeFOI -= g_dFOI[iGroupType][iCounter];
			if (dCumulativeFOI < dFOICutOff)
			{
				iChosenSubtype = iCounter;
				break;
			}
		}
		dFOICutOff = dFOICutOff-dCumulativeFOI;
	}
	UpdateFOIEngine(iGroupType, iChosenSubtype);
	g_cFOIPerturbedList[iGroupType][iChosenSubtype].Clear();
	iChosenInfectee = SelectInfectee(iGroupType, iChosenSubtype, dFOICutOff);
	g_iSelectedSeed = iChosenInfectee;
	g_cIndividual[iChosenInfectee].DiseaseProgression();
}	
 
void ProcessEventOnList(){
	CEventListRecord cEventListRecord = (*(g_pEventList[g_iCurrentEventList])).top();
	int iID = cEventListRecord.GetID();   
	short cEvent = cEventListRecord.GetEvent();
 
	(*(g_pEventList[g_iCurrentEventList])).pop();
	switch (cEvent)
	{
	case MOVE_EVENT_LIST:
		{
			delete g_pEventList[g_iCurrentEventList];
			g_pEventList[g_iCurrentEventList] = NULL;
			++g_iCurrentEventList;
		}
		break;
	case ISOLATION_RELEASE:
		g_cIndividual[iID].IsolationRelease();
		break;
	case ISOLATION:
		{
			if (g_cIndividual[iID].GetQuarantineStatus() == true && 
				(g_cIndividual[iID].GetDiseaseStatus() == SYMPTOMATIC || g_cIndividual[iID].GetSpamStatus() == true))
			{
					// Modification
				g_cIndividual[iID].QuarantineRelease();
				g_cIndividual[iID].Isolation();
			}
		}
		break;
	case SPAM_END:
		{
			g_cIndividual[iID].SetSpamStatus(false);
			if (g_cIndividual[iID].GetDiseaseStatus() != SYMPTOMATIC)
				g_cIndividual[iID].SetPeerGroupActive(true);
		}
		break;
	case QUARANTINE_RELEASE:
		g_cIndividual[iID].CheckQuarantineRelease();
		break;
	case PROGRESSION:
		g_cIndividual[iID].DiseaseProgression();
		break;
	case DRUG_ACTIVATE:
		g_cIndividual[iID].ActivateDrug();
		break;
#ifdef CONTACT_TRACING
	case TRACED:
		g_cIndividual[iID].Traced();
		break;
	case CLEAR_CTLIST_RECORD:
		g_cIndividual[iID].ClearCTListRecord();
		break;
#endif
#ifdef TESTING
	case TEST_RETURN:
		g_cIndividual[iID].CheckTestResult();
		break;
	case RETEST:
		g_cIndividual[iID].Retest();
		break;
#endif
	default: 
		{
			cout << "Error in ProcessEvent().  Invalid event: " << cEvent << endl;
			Pause();
			exit(0);
		}
	} 
}
 
void ProcessNonCloseInfectionAndSpam()
{ 
	int i = 0;
	int iChosenIndex, iChosenID;
	if (g_bQuarantineActive == false || Probability() < (g_dFOICommunity[SelectedCounty]+g_dFOIImport[SelectedCounty]+g_dFOIIsolation[SelectedCounty])/g_dFOINonCloseAndSpam[SelectedCounty])
	{
		bool bFinished = false;
		double dFOIPerCapitaCI, dFOIPerCapitaIso;
		g_iHeadCountTotal[SUSCEPTIBLE][0][0][0]=0;
		g_iHeadCountTotal[SUSCEPTIBLE][1][0][0]=0;
		g_iHeadCountTotal[SUSCEPTIBLE][0][0][1]=0;
		for(i=0;i<number_counties;i++)
		{
			g_iHeadCountTotal[SUSCEPTIBLE][0][0][0]=g_iHeadCountTotal[SUSCEPTIBLE][0][0][0]+g_iHeadCount[SUSCEPTIBLE][0][0][0][i];
			g_iHeadCountTotal[SUSCEPTIBLE][1][0][0]=g_iHeadCountTotal[SUSCEPTIBLE][1][0][0]+g_iHeadCount[SUSCEPTIBLE][1][0][0][i];
			g_iHeadCountTotal[SUSCEPTIBLE][0][0][1]=g_iHeadCountTotal[SUSCEPTIBLE][0][0][1]+g_iHeadCount[SUSCEPTIBLE][0][0][1][i];
		}
 
		dFOIPerCapitaCI = (g_dFOICommunity[SelectedCounty]+g_dFOIImport[SelectedCounty])/(g_iHeadCount[SUSCEPTIBLE][0][0][0][SelectedCounty]+g_iHeadCount[SUSCEPTIBLE][1][0][0][SelectedCounty]);
 
		dFOIPerCapitaIso = g_dFOIIsolation[SelectedCounty]/(g_iHeadCount[SUSCEPTIBLE][0][0][1][SelectedCounty]+0.000000001);
		while (bFinished == false)
		{
			i++;
						
			bool bBaseCI = true;
			if (dFOIPerCapitaCI < dFOIPerCapitaIso)
				bBaseCI = false;
 
			do
			{
				iChosenIndex = DiscreteUniformDeviate(0, g_cSusceptibleList[SelectedCounty].Size()-1);
				iChosenID = g_cSusceptibleList[SelectedCounty][iChosenIndex];
			}while(g_cIndividual[iChosenID].GetCountyID() != SelectedCounty);
 
			if (g_cIndividual[iChosenID].GetDiseaseStatus() != SUSCEPTIBLE)
				g_cSusceptibleList[SelectedCounty].Erase(iChosenIndex);
			else
			{
				if (g_cIndividual[iChosenID].GetIsolationStatus() == false)
				{
					if (g_cIndividual[iChosenID].GetQuarantineStatus() == false || g_cIndividual[iChosenID].GetComplianceStatus() == false)
					{
						if (bBaseCI == true)
							bFinished = true;
						else if (Probability() < dFOIPerCapitaCI/dFOIPerCapitaIso)
							bFinished = true;
					}
					if (bFinished == true)
						if (Probability() < g_dFOIImport[SelectedCounty]/(g_dFOIImport[SelectedCounty]+g_dFOICommunity[SelectedCounty]))
							++g_iTotalNumImport;
				}
				else
				{
					if (bBaseCI == false)
						bFinished = true;
					else if (Probability() < dFOIPerCapitaIso/dFOIPerCapitaCI)
						bFinished = true;
				}
			}
		}
 
		g_iSelectedSeed = iChosenID;
#ifdef CHECK_TARGETS
		++g_iNumInfecteesBySeed[g_cIndividual[g_iSelectedSeed].GetDiseaseStatus()-PRESYMPTOMATIC][COMMUNITY];
		g_dTg += g_dTime;
#endif
		g_cIndividual[iChosenID].DiseaseProgression();
	}
	else
	{
		do
		{
			iChosenIndex = DiscreteUniformDeviate(0, g_cSpamList[SelectedCounty].Size()-1);
			iChosenID = g_cSpamList[SelectedCounty][iChosenIndex];
		}while(g_cIndividual[iChosenID].GetCountyID() != SelectedCounty);
 
#ifdef LOW_SPAM
		while (g_cIndividual[iChosenID].GetDiseaseStatus() != SUSCEPTIBLE || g_cIndividual[iChosenID].GetIsolationStatus() == true ||
			(g_cIndividual[iChosenID].GetQuarantineStatus() == true && g_cIndividual[iChosenID].GetComplianceStatus() == true) || 
			g_cIndividual[iChosenID].GetSpamStatus() == true)
		{
			if (g_cIndividual[iChosenID].GetDiseaseStatus() != SUSCEPTIBLE)
				g_cSpamList[SelectedCounty].Erase(iChosenIndex);
				do
				{
					iChosenIndex = DiscreteUniformDeviate(0, g_cSpamList[SelectedCounty].Size()-1);
					iChosenID = g_cSpamList[SelectedCounty][iChosenIndex];
				}while(g_cIndividual[iChosenID].GetCountyID() != SelectedCounty);
		}
#else
		while ((g_cIndividual[iChosenID].GetDiseaseStatus() != SUSCEPTIBLE && g_cIndividual[iChosenID].GetDiseaseStatus() != RECOVERED) || 
			g_cIndividual[iChosenID].GetIsolationStatus() == true || g_cIndividual[iChosenID].GetSpamStatus() == true ||
			(g_cIndividual[iChosenID].GetQuarantineStatus() == true && g_cIndividual[iChosenID].GetComplianceStatus() == true))
		{
			do
			{
				iChosenID = DiscreteUniformDeviate(0, gc_iPopulationSizeTotal-1);
			}while(g_cIndividual[iChosenID].GetCountyID() != SelectedCounty);
		}
			
			
		if (g_cIndividual[iChosenID].GetImmuneStatus() == true)
			return;
#endif
		if (g_cIndividual[iChosenID].GetAdultStatus() == false)
		{
			if (Probability() > g_dProbSymActiveChildren)
				g_cIndividual[iChosenID].SetPeerGroupActive(false);
		}
		else if (Probability() > g_dProbSymActiveAdults)
			g_cIndividual[iChosenID].SetPeerGroupActive(false);
 
		g_cIndividual[iChosenID].SetSpamStatus(true);
		++g_iTotalNumSpam;
		AddEvent(CEventListRecord(g_dTime+SpamDuration(), iChosenID, SPAM_END));
 
		if (g_bQuarantineActive == true)
		{
			if (g_cIndividual[iChosenID].GetQuarantineStatus() == false && Probability() < g_dProbReport)
			{
				g_cIndividual[iChosenID].Report();   // Spam and truely infected report with the same probability
				if (g_bIsolationActive == true && Probability() < g_dProbIsolation)
				{					
					// Modification
					AddEvent(CEventListRecord(g_dTime+IsolationDelay(), iChosenID, ISOLATION));   
					/*
					g_cIndividual[iChosenID].QuarantineRelease();			
					g_cIndividual[iChosenID].Isolation(); */  // voluntary isolation
				}
			}
		}
	}
}
 
#ifdef PRINT_TIME_SERIES
void PrintTimeSeries(const int iDummy){
 
	char cABCD[] = {"abcd"};
	int iCounter, iCounter2, iCounter3, iCounter4, iCounter5;
	int iHeadCount = 0;
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
	{
		iHeadCount = 0;
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
					for(iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
					iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
		g_ofTimeSeries[0] << iHeadCount << "\t";
	}
 
	g_ofTimeSeries[1] << g_iNumQuarantined << "\t" << g_iNumIsolated << "\t" << g_iInfectionIncidence << "\t" << 
		g_iQuarantineIncidence << "\t" << g_iIsolationIncidence << "\t"; 
 
	g_ofTimeSeries[2] << g_iNumActiveCTServers << "\t" << g_iNumActiveTestServers << "\t" << g_dTotalDrugUsedQuarantineNonSymp << "\t"
		<< g_dTotalDrugUsedQuarantineSymp << "\t" << g_dTotalDrugUsedQuarantineNonComp << "\t" << g_dTotalDrugUsedIsolation << "\t"
		<< g_iTotalNumImport << "\t" << g_iTotalNumSpam << "\t" << g_iNumHouseholdsQuarantined << "\t";  
 
	/*g_ofTimeSeries[0] << g_dFOICommunity << "\t" << 
	g_iHeadCount[SUSCEPTIBLE][0][0][0]+g_iHeadCount[SUSCEPTIBLE][1][0][0] << "\t" <<
	g_iHeadCount[PRESYMPTOMATIC][0][0][0]+g_iHeadCount[PRESYMPTOMATIC][1][0][0] << "\t" <<
	g_iHeadCount[ASYMPTOMATIC][0][0][0]+g_iHeadCount[ASYMPTOMATIC][1][0][0] << "\t" <<
	g_iHeadCount[SYMPTOMATIC][0][0][0]+g_iHeadCount[SYMPTOMATIC][1][0][0] << "\t";*/
 
	//g_ofTimeSeries[1] << g_iNumQuarantined << "\t" << g_iNumIsolated << "\t" << g_iInfectionIncidence << "\t" << 
	//	g_iQuarantineIncidence << "\t" << g_iIsolationIncidence << "\t" << g_iDailyNumQuarantineReleased << "\t" <<
	//	g_iDailyNumIsolationReleased << "\t"; 
 
	//g_ofTimeSeries[2] << g_iNumActiveCTServers << "\t" << g_iNumActiveTestServers << "\t" << g_dTotalDrugUsed << "\t" << 
	//	g_iTotalNumImport << "\t" << g_iTotalNumSpam << "\t" << g_iNumHouseholdsQuarantined << "\t";  
 
	//g_iTotalNumQuarantineReleased += g_iDailyNumQuarantineReleased;
	//g_iTotalLeakage += g_iDailyLeakage;
	//g_ofTimeSeries[3] << (static_cast<double>(g_iDailyLeakage))/MAX(1, g_iDailyNumQuarantineReleased)*100 << "\t" << 
	//	g_dTotalQuarantineDuration/MAX(1, g_iTotalNumQuarantineReleased) << "\t" << 
	//	g_dTotalIsolationDuration/MAX(1, g_iTotalNumIsolationReleased) << "\t" <<
	//	g_iTotalNumQuarantineReleased << "\t" << g_iTotalNumIsolationReleased << "\t";
 
	if (IsEqual(g_dTime, gc_dTimeMax) == true)
		for (iCounter = 0; iCounter < gc_iNumTimeSeries; ++iCounter)
			g_ofTimeSeries[iCounter] << endl;
}
#endif
 
 
void ResetConditions(){
	// Checked 10/6
	int iCounter, iCounter2, iCounter3, iCounter4, iCounter5;
 
	g_iNumFOIUpdates = 0;
	g_iNumTraced = 0;
	g_dTime = 0;
	g_dOldTime = 0;
 
	for(iCounter=0;iCounter<number_counties;iCounter++)
	{
		g_cSpamList[iCounter].Clear();
		g_cSusceptibleList[iCounter].Clear();
	}
 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
	{
		g_cSpamList[g_cIndividual[iCounter].GetCountyID()].Push(iCounter);
		g_cSusceptibleList[g_cIndividual[iCounter].GetCountyID()].Push(iCounter);
	}
 
	g_iMaxNumHospitalized = 0;
	g_iInfectionIncidence = 0;
 
	CMySet<int, unsigned int> *pInfectorGroup;
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		g_dTotalFOI[iCounter] = 0;
		for (iCounter2 = 0; iCounter2 < gc_iNumEngineSlots; ++iCounter2)
		{
			g_dFOI[iCounter][iCounter2] = 0;
			for (iCounter3 = 0; iCounter3 < g_cFOIEngine[iCounter][iCounter2].Size(); ++iCounter3)
			{
				pInfectorGroup = g_cFOIEngine[iCounter][iCounter2][iCounter3].GetPtrInfectorGroup();
				(*pInfectorGroup).Clear();
				g_cFreePtrInfectorGroup.push_back(pInfectorGroup);
			}
			g_cFOIEngine[iCounter][iCounter2].Clear();
			g_cEmptyFOIEngineSlot[iCounter][iCounter2].Clear();
			g_cFOIPerturbedList[iCounter][iCounter2].Clear();
		}
	}
 
 
	g_dTotalCloseFOI = 0;
	g_dOldTotalCloseFOI = 0; 
	for(iCounter=0;iCounter<number_counties;iCounter++)
		g_dFOICommunity[iCounter] = 0;
	for(iCounter=0;iCounter<number_counties;iCounter++)
		g_dFOIIsolation[iCounter] = 0;
	for(iCounter=0;iCounter<number_counties;iCounter++)
		g_dFOINonCloseAndSpam[iCounter] = 0;
 
	g_iTotalNumSpam = 0;
	g_iTotalNumImport = 0;
	g_iMaxInfectionIncidence = 0;
 
	g_iThresholdCounter = 0;
	g_iEventCounter = 0;               
	g_iPrintCounter = 1;
	g_iCurrentEventList = 0;
 
	g_iNumQuarantined = 0;
	g_iMaxNumQuarantined = 0;
	g_iTotalNumQuarantined = 0;
	g_iTotalNumQuarantineReleased = 0;
	g_iDailyNumQuarantineReleased = 0;
	g_iQuarantineIncidence = 0;
	g_iMaxQuarantineIncidence = 0;
	g_dTotalQuarantineDuration = 0;
	g_iNumHouseholdsQuarantined = 0;
	g_iTotalNumHouseholdsQuarantineReleased = 0;
	g_iDailyNumHouseholdsQuarantineReleased = 0;
	g_iMaxNumHouseholdsQuarantined = 0;
 
	g_iNumIsolated = 0;
	g_iMaxNumIsolated = 0;
	g_iTotalNumIsolated = 0;
	g_iTotalNumIsolationReleased = 0;
	g_iDailyNumIsolationReleased = 0;
	g_iIsolationIncidence = 0;
	g_iMaxIsolationIncidence = 0;
	g_dTotalIsolationDuration = 0;
 
	g_dDailyDrugUsedQuarantineSymp = 0;
	g_dDailyDrugUsedQuarantineNonSymp = 0;
	g_dDailyDrugUsedQuarantineNonComp = 0;
	g_dDailyDrugUsedIsolation = 0;
	g_dTotalDrugUsedQuarantineSymp = 0;
	g_dTotalDrugUsedQuarantineNonSymp = 0;
	g_dTotalDrugUsedQuarantineNonComp = 0;
	g_dTotalDrugUsedIsolation = 0;
 
#ifdef CONTACT_TRACING
	g_iNumActiveCTServers = 0;
	g_iNumCTRecordRemoved = 0;
	g_cCTList.clear();
#endif
#ifdef TESTING
	g_iNumActiveTestServers = 0;
	g_bStopTesting = false;
	g_dTimeResumeTesting = LARGE_NUMBER;
#endif
#ifdef DURATION_DETAILS
	//for (iCounter = 0; iCounter < MAX_QI_TIMES; ++iCounter)
	//{
	//	g_iQuarantineTimesPDF[iCounter] = 0;
	//	g_iIsolationTimesPDF[iCounter] = 0;
	//	g_iHouseholdQuarantineTimesPDF[iCounter] = 0;
	//}
	for (iCounter = 0; iCounter < MAX_DURATION+1; ++iCounter)
	{
		g_iQuarantineDurationPDF[iCounter] = 0;
		g_iHouseholdQuarantineDurationPDF[iCounter] = 0;
		g_iIsolationDurationPDF[iCounter] = 0;
	}
#endif
#ifdef PRINT_STATS
	for (iCounter = 0; iCounter < gc_iNumAttackRateThresholds; ++iCounter)
		g_dAttackRateThresholdHittingTime[iCounter] = LARGE_NUMBER;
#endif
 
 
	for (iCounter = 0; iCounter < gc_iNumEventLists; ++iCounter)
	{
		if (g_pEventList[iCounter] != NULL)
		{
			while ((*(g_pEventList[iCounter])).empty() == false)
				(*(g_pEventList[iCounter])).pop();
		}
		else
			g_pEventList[iCounter] = new priority_queue<CEventListRecord>;
	}
 
	for (iCounter = 0; iCounter < gc_iNumEventLists-1; ++iCounter)
		(*(g_pEventList[iCounter])).
		push(CEventListRecord((iCounter+1)*gc_dTimeMax/gc_iNumEventLists, -1, MOVE_EVENT_LIST));
 
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
					for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
						g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5] = 0;
 
 
	for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
		g_iHeadCount[SUSCEPTIBLE][0][0][0][iCounter5] = gc_iPopulationSize[iCounter5]; 
	g_iHeadCountTotal[SUSCEPTIBLE][0][0][0] = gc_iPopulationSizeTotal;	
 
 
	for (iCounter = 0; iCounter < gc_iNumAttackRateThresholds; ++iCounter)
		g_dAttackRateThresholdHittingTime[iCounter] = LARGE_NUMBER;
 
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
	{
		g_cHousehold[iCounter].HouseholdReset(iCounter);
		//		g_cHousehold[iCounter].ResetActiveHouseholdSize();
		//		g_cHousehold[iCounter].SetHouseholdSeen(false);
		g_cHousehold[iCounter].ComputeSusceptibility();
	}
	for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
	{
		g_cPeerGroup[iCounter].Reset(iCounter);
		g_cPeerGroup[iCounter].ComputeSusceptibility();
	}	
#ifdef CHECK_TARGETS
	for (iCounter =0; iCounter < 3; ++iCounter)
		for (iCounter2 =0; iCounter2 < 3; ++iCounter2)
			g_iNumInfecteesBySeed[iCounter][iCounter2] = 0;
	g_dTg = 0;
#endif
}
 
int ComputeNumSusceptible()
{
	int iCounter, iCounter2, iCounter3, iCounter4, iHeadCount = 0;
	for (iCounter = 0; iCounter < 2; ++iCounter)
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)
				for (iCounter4 = 0; iCounter4 < number_counties; ++iCounter4)
					iHeadCount += g_iHeadCount[SUSCEPTIBLE][iCounter][iCounter2][iCounter3][iCounter4];
	return iHeadCount;
}
 
#ifdef PRINT_STATS
void PrintStats(const int iParameterSetIndex)
{
	int iCounter;
	for (iCounter = 0; iCounter < gc_iNumAttackRateThresholds; ++iCounter)
		g_ofStat[0] << g_dAttackRateThresholdHittingTime[iCounter] << "\t";
		
		g_ofStat[0] << ComputeNumSusceptible() << "\t" << g_dTotalDrugUsedQuarantineNonSymp << "\t" << g_dTotalDrugUsedQuarantineSymp << "\t" << 
		g_dTotalDrugUsedQuarantineNonComp << "\t" << g_dTotalDrugUsedIsolation << "\t" << g_iMaxNumHouseholdsQuarantined << "\t" << 
		g_iMaxNumQuarantined << "\t" << g_iMaxNumIsolated << "\t" << g_iTotalNumImport << "\t" << g_iTotalNumSpam << "\t" << g_iMaxInfectionIncidence << "\t" <<
		g_iMaxQuarantineIncidence << "\t" << g_iMaxIsolationIncidence << "\t" << g_iMaxNumHospitalized << endl;
 
#ifdef DURATION_DETAILS
	int iCounter2, iDummy, iDummy2, iNumHouseholds[10], iNumQuarantinedHouseholds[10],
		iQuarantineTimesPDF[MAX_QI_TIMES], iIsolationTimesPDF[MAX_QI_TIMES], iHouseholdQuarantineTimesPDF[MAX_QI_TIMES];
	double dDummy, dQuarantineDurationMoments[2][MAX_QI_TIMES], dIsolationDurationMoments[2][MAX_QI_TIMES], 
		dHouseholdQuarantineDurationMoments[2][MAX_QI_TIMES], dHouseholdQuarantineTimes[10];
 
	for (iCounter = 0; iCounter < MAX_QI_TIMES; ++iCounter)
	{
		iQuarantineTimesPDF[iCounter] = 0;
		iIsolationTimesPDF[iCounter] = 0;
		iHouseholdQuarantineTimesPDF[iCounter] = 0;
 
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
		{
			dQuarantineDurationMoments[iCounter2][iCounter] = 0;
			dIsolationDurationMoments[iCounter2][iCounter] = 0;
			dHouseholdQuarantineDurationMoments[iCounter2][iCounter] = 0;
		}
	}
 
	for (iCounter = 0; iCounter < 10; ++iCounter)
	{
		iNumHouseholds[iCounter] = 0;
		iNumQuarantinedHouseholds[iCounter] = 0;
		dHouseholdQuarantineTimes[iCounter] = 0;
	}
 
	for (iCounter = 0; iCounter < MAX_DURATION+1; ++iCounter)
		g_ofStat[1] << g_iQuarantineDurationPDF[iCounter] << "\t" << g_iIsolationDurationPDF[iCounter] << "\t" << g_iHouseholdQuarantineDurationPDF[iCounter] << "\t ";
 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
	{
		iDummy = static_cast<int>(MIN(MAX_QI_TIMES, g_cIndividual[iCounter].GetQuarantineTimes()));
		++iQuarantineTimesPDF[iDummy];
		dDummy = static_cast<double>(g_cIndividual[iCounter].GetTotalQuarantineDuration());
		/*			if (iDummy == 0 && dDummy > 0.000001)
		cout << dDummy << endl;*/
		dQuarantineDurationMoments[0][iDummy] += dDummy;
		//	dQuarantineDurationMoments[1][iDummy] += dDummy*dDummy;
 
		iDummy = static_cast<int>(MIN(MAX_QI_TIMES, g_cIndividual[iCounter].GetIsolationTimes()));
		++iIsolationTimesPDF[iDummy];
		dDummy = static_cast<double>(g_cIndividual[iCounter].GetTotalIsolationDuration());
		dIsolationDurationMoments[0][iDummy] += dDummy;
		//	dIsolationDurationMoments[1][iDummy] += dDummy*dDummy;
	}
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
	{
		iDummy = static_cast<int>(MIN(MAX_QI_TIMES, g_cHousehold[iCounter].GetQuarantineTimes()));
		++iHouseholdQuarantineTimesPDF[iDummy];
		dDummy = static_cast<double>(g_cHousehold[iCounter].GetTotalQuarantineDuration());
 
		dHouseholdQuarantineDurationMoments[0][iDummy] += dDummy;
		//	dHouseholdQuarantineDurationMoments[1][iDummy] += dDummy*dDummy;
 
		iDummy2 = g_cHousehold[iCounter].GetHouseholdSize();
		if (iDummy > 0)
		{
			dHouseholdQuarantineTimes[iDummy2-1] += iDummy;
			++iNumQuarantinedHouseholds[iDummy2-1];
		}
		++iNumHouseholds[iDummy2-1];
	}
 
	for (iCounter = 0; iCounter < MAX_QI_TIMES; ++iCounter)
		g_ofStat[1] << iQuarantineTimesPDF[iCounter] << "\t" << iIsolationTimesPDF[iCounter] << "\t" << iHouseholdQuarantineTimesPDF[iCounter] << "\t";
	for (iCounter = 0; iCounter < MAX_QI_TIMES; ++iCounter)
	{
		for (iCounter2 = 0; iCounter2 < 1; ++iCounter2)
		{
			g_ofStat[1] << dQuarantineDurationMoments[iCounter2][iCounter] << "\t" << dIsolationDurationMoments[iCounter2][iCounter]
			<< "\t" << dHouseholdQuarantineDurationMoments[iCounter2][iCounter] << "\t";
		}
	}
	for (iCounter = 0; iCounter < 10; ++iCounter)
		g_ofStat[1] << dHouseholdQuarantineTimes[iCounter]/MAX(1,iNumQuarantinedHouseholds[iCounter]) << "\t";
	for (iCounter = 0; iCounter < 10; ++iCounter)
		g_ofStat[1] << static_cast<double>(iNumQuarantinedHouseholds[iCounter])/MAX(1,iNumHouseholds[iCounter]) << "\t";
 
	g_ofStat[1] << g_iTotalNumQuarantineReleased << "\t" << g_iTotalNumIsolationReleased << "\t" << g_iTotalNumHouseholdsQuarantineReleased << "\t" 
		<< g_iNumGroups[HOUSEHOLD] << endl;
#endif
}
#endif
 
int ClassroomSize(const int countyID, const int agegroup)
{ 
	int iClassroomSize = 0;
	while (iClassroomSize == 0 || iClassroomSize > gc_iMaxNumPeers)
	{
//		iClassroomSize = DiscreteUniformDeviate(gc_iMinClassSize, gc_iMaxClassSize);
		iClassroomSize = DiscreteUniformDeviate(MAX(gc_dMeanClassSize[countyID][agegroup]-5,5), gc_dMeanClassSize[countyID][agegroup]+5);
	}
	return iClassroomSize;
}
 
int WorkGroupSize(const int countyID)
{
 
	int iWorkGroupSize = 0;
/*
	int temp =1;
	double dProbability = Probability();
	while (dProbability > worksize[countyID][temp-1])
		++temp;
	if(temp<9)
		iWorkGroupSize = DiscreteUniformDeviate(ranges[temp-1],ranges[temp]-1);
	else
		iWorkGroupSize = 1000;
 
	cout << "SIZE + " << iWorkGroupSize << endl;
*/
	while (iWorkGroupSize == 0 || iWorkGroupSize > gc_iMaxNumPeers)
		iWorkGroupSize = PoissonDeviate(gc_dMeanNumCoworkers1);
 
	return iWorkGroupSize;
}
 
 
int HouseholdSize(const int countyID)
{
	double dProbability = Probability();
	int iHouseholdSize = 1;
	
	while (dProbability > dCDF[countyID][iHouseholdSize-1])
		++iHouseholdSize;
 
	return iHouseholdSize;
}
 
 
 
void ReadChildrenData()
{
 
	int i, j, k, h;
 
	FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/children.txt", "r");
 
	if (!inFile)
	{
		printf("Cannot find children.txt\n");
	}
	else
	{	for(i=0;i<number_counties-1;i++)
			for(j=1;j<6;j++)
			{	for(k=0;k<7;k++)
					fscanf(inFile, "%lf ", &dCDF2[i][j][k]);
				fscanf(inFile, "\n");
			}
	}
	fclose(inFile);
 
	for(i=0;i<number_counties-1;i++)
		for(j=1;j<6;j++)
			for(k=0;k<7;k++)
				if(k+1<= j)
					dCDF2[i][j][k]=0;
 
	for(i=0;i<number_counties-1;i++)
		for(k=0;k<7;k++)
		{	dCDF2[i][0][k]= 1.0;
			for(j=1;j<6;j++)
				dCDF2[i][0][k] -= dCDF2[i][j][k];
		}
 
	for(i=0;i<number_counties-1;i++)
		for(k=0;k<7;k++)
			for(j=5;j>0;j--)
				for(h=0;h<j;h++)
					dCDF2[i][j][k] += dCDF2[i][h][k];
 
}
 
 
 
int NumChildren(const int iHouseholdSize, const int countyID)
{
	double dProbability = Probability();
 
	int iNumberOfChildren = 0;
	switch(iHouseholdSize)
	{
	case 1:
		return 0;
		break;
	case 2:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	case 3:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	case 4:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	case 5:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	case 6:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	case 7:
		while (dProbability > dCDF2[countyID][iNumberOfChildren][iHouseholdSize-1])
			++iNumberOfChildren;
		break;
	default:{
		cout << "Error in NumberOfChildren(): HouseholdSize exceeds 7.  " << endl;
		Pause();
		exit(0);
			}
	}
	return iNumberOfChildren;
};
 
 
 
 
void BuildNetwork(){ 
	int iCounter, iDummy, iThisID;
	int iPopulationCounter = 0, iPeerGroupSize = 0, iPeerGroupCounter = 0;
	bool bChildrenPeerGroup = true;
	int iCounter2, iCounter4, iCounter5, iCounter6, left;
	int iPeerGroupCounterClass = 0;
	int iPeerGroupCounterWork = 0;
	int pop_counter, pop_counter2;
 
	g_iNumClassrooms[0] = 0;
	g_iNumClassrooms[1] = 0;
	g_iNumClassrooms[2] = 0;
	g_iOldGroups = 0;
	iHouseholdCounterTotal=0;
 
	ReadChildrenData();
 
	cout << "------------------------------------------------------------------------------------------" << endl;
	cout << endl << "Running Paremeter Set " << g_iParameterSetIndex << " with seed " << g_iSeed << endl;
 
	for(iCounter=0;iCounter<number_counties;iCounter++)
		for(iCounter2=0;iCounter2<5;iCounter2++)
		{	
			gc_iAgePopulation[iCounter2][iCounter] = static_cast<int>(gc_dPropAgeGroup[iCounter2][iCounter]*gc_iPopulationSize[iCounter]);
			iAgePopulation[iCounter2][iCounter] = 0;
		}
 
	subtotal[0] = gc_iPopulationSize[0];
	for(iCounter=1;iCounter<number_counties;iCounter++)
		subtotal[iCounter]=subtotal[iCounter-1]+ gc_iPopulationSize[iCounter];
 
	//AGE GROUP 1
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		bChildrenPeerGroup = true;
		while(iPopulationCounter < subtotal[iCounter2])
		{
			if(iCounter2==0)
			{	if (bChildrenPeerGroup == true && iPopulationCounter >= gc_iAgePopulation[0][iCounter2])
					bChildrenPeerGroup = false;
			}
			else
			{
				if (bChildrenPeerGroup == true && iPopulationCounter >= gc_iAgePopulation[0][iCounter2] + subtotal[iCounter2-1])
					bChildrenPeerGroup = false;
			}
	
			if (bChildrenPeerGroup == true)
			{
				iDummy = ClassroomSize(iCounter2,0);
				iPeerGroupSize = MIN(gc_iAgePopulation[0][iCounter2]-iAgePopulation[0][iCounter2], iDummy);
				g_iNumClassrooms[0]++;
				g_iNumClassrooms[1]++;
				g_iNumClassrooms[2]++;
				iPeerGroupCounterClass++;
				for (iCounter = 0; iCounter < iPeerGroupSize; ++iCounter)
				{
					iThisID = iPopulationCounter+iCounter;
					g_cIndividual[iThisID].SetAdultStatus(false);
					(iAgePopulation[0][iCounter2])++;
					g_cIndividual[iThisID].SetCountyID(iCounter2);
					g_cIndividual[iThisID].SetPeerGroupID(g_iNumClassrooms[0]-1);
					g_cIndividual[iThisID].SetAgeGroup(0);
				}           
				iPopulationCounter += iPeerGroupSize;
			}
			else
				iPopulationCounter = subtotal[iCounter2];
		}
		if (gc_iAgePopulation[0][iCounter2] != iAgePopulation[0][iCounter2])
		{
			cout << gc_iAgePopulation[0][iCounter2] << " " << iAgePopulation[0][iCounter2] << endl;
			exit(0);
		}
	}
 
 
 
	//AGE GROUP 2
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		bChildrenPeerGroup = true;
		if(iCounter2 == 0)
			iPopulationCounter = iAgePopulation[0][iCounter2];
		else
			iPopulationCounter = iAgePopulation[0][iCounter2] + subtotal[iCounter2-1];
 
		while(iPopulationCounter < subtotal[iCounter2])
		{
			if(iCounter2==0)
			{	if (bChildrenPeerGroup == true && iPopulationCounter >= iAgePopulation[0][iCounter2] + gc_iAgePopulation[1][iCounter2])
					bChildrenPeerGroup = false;
			}
			else
			{
				if (bChildrenPeerGroup == true && iPopulationCounter >= iAgePopulation[0][iCounter2] + gc_iAgePopulation[1][iCounter2] + subtotal[iCounter2-1])
					bChildrenPeerGroup = false;
			}
	
			if (bChildrenPeerGroup == true)
			{
				iDummy = ClassroomSize(iCounter2,1);
				iPeerGroupSize = MIN(gc_iAgePopulation[1][iCounter2]-iAgePopulation[1][iCounter2], iDummy);
				g_iNumClassrooms[1]++;
				g_iNumClassrooms[2]++;
				iPeerGroupCounterClass++;
				for (iCounter = 0; iCounter < iPeerGroupSize; ++iCounter)
				{
					iThisID = iPopulationCounter+iCounter;
					g_cIndividual[iThisID].SetAdultStatus(false);
					(iAgePopulation[1][iCounter2])++;
					g_cIndividual[iThisID].SetCountyID(iCounter2);
					g_cIndividual[iThisID].SetPeerGroupID(g_iNumClassrooms[1]-1);
					g_cIndividual[iThisID].SetAgeGroup(1);
				}           
				iPopulationCounter += iPeerGroupSize;
			}
			else
				iPopulationCounter = subtotal[iCounter2];
		}
		if (gc_iAgePopulation[1][iCounter2] != iAgePopulation[1][iCounter2])
		{
			cout << gc_iAgePopulation[1][iCounter2] << " " << iAgePopulation[1][iCounter2] << endl;
			exit(0);
		}
	}
 
 
 
	//AGE GROUP 3
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		bChildrenPeerGroup = true;
		if(iCounter2 == 0)
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2];
		else
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + subtotal[iCounter2-1];
 
		while(iPopulationCounter < subtotal[iCounter2])
		{
			if(iCounter2==0)
			{	if (bChildrenPeerGroup == true && iPopulationCounter >= iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + gc_iAgePopulation[2][iCounter2])
					bChildrenPeerGroup = false;
			}
			else
			{
				if (bChildrenPeerGroup == true && iPopulationCounter >= iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + gc_iAgePopulation[2][iCounter2] + subtotal[iCounter2-1])
					bChildrenPeerGroup = false;
			}
	
			if (bChildrenPeerGroup == true)
			{
				iDummy = ClassroomSize(iCounter2,2);
				iPeerGroupSize = MIN(gc_iAgePopulation[2][iCounter2]-iAgePopulation[2][iCounter2], iDummy);
				g_iNumClassrooms[2]++;
				iPeerGroupCounterClass++;
				for (iCounter = 0; iCounter < iPeerGroupSize; ++iCounter)
				{
					iThisID = iPopulationCounter+iCounter;
					g_cIndividual[iThisID].SetAdultStatus(false);
					(iAgePopulation[2][iCounter2])++;
					g_cIndividual[iThisID].SetCountyID(iCounter2);
					g_cIndividual[iThisID].SetPeerGroupID(g_iNumClassrooms[2]-1);
					g_cIndividual[iThisID].SetAgeGroup(2);
				}           
				iPopulationCounter += iPeerGroupSize;
			}
			else
			{	g_cIndividual[iPopulationCounter].SetAdultStatus(true);
				g_cIndividual[iPopulationCounter].SetCountyID(iCounter2);
				iPopulationCounter++;
			}
		}
		if (gc_iAgePopulation[2][iCounter2] != iAgePopulation[2][iCounter2])
		{
			cout << gc_iAgePopulation[2][iCounter2] << " " << iAgePopulation[2][iCounter2] << endl;
			exit(0);
		}
	}
 
 
	iPeerGroupCounter = iPeerGroupCounterClass;
	//AGE GROUP 5
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		bChildrenPeerGroup = true;
		if(iCounter2 == 0)
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + iAgePopulation[2][iCounter2];
		else
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + iAgePopulation[2][iCounter2] + subtotal[iCounter2-1];
 
		pop_counter = 0;
		while(pop_counter < gc_iAgePopulation[4][iCounter2])
		{
//			iDummy = WorkGroupSize(iCounter2);
			iDummy = 1;
			iPeerGroupSize = MIN(gc_iAgePopulation[4][iCounter2]-pop_counter, iDummy);
			g_iOldGroups++;
			iPeerGroupCounter++;
			for (iCounter = 0; iCounter < iPeerGroupSize; ++iCounter)
			{
				iThisID = iPopulationCounter+iCounter;
				g_cIndividual[iThisID].SetAdultStatus(true);
				(iAgePopulation[4][iCounter2])++;
				g_cIndividual[iThisID].SetCountyID(iCounter2);
				g_cIndividual[iThisID].SetPeerGroupID(iPeerGroupCounter-1);
				g_cIndividual[iThisID].SetAgeGroup(4);
			}           
			iPopulationCounter += iPeerGroupSize;
			pop_counter += iPeerGroupSize;
		}
		iAgePopulation[4][iCounter2] = gc_iAgePopulation[4][iCounter2];
	}
 
 
	//AGE GROUP 4
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		if(iCounter2 == 0)
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + iAgePopulation[2][iCounter2] + iAgePopulation[4][iCounter2];
		else
			iPopulationCounter = iAgePopulation[0][iCounter2] + iAgePopulation[1][iCounter2] + iAgePopulation[2][iCounter2] + iAgePopulation[4][iCounter2] + subtotal[iCounter2-1];
 
		while(iPopulationCounter < subtotal[iCounter2])
		{
			g_cIndividual[iPopulationCounter].SetAdultStatus(true);
			g_cIndividual[iPopulationCounter].SetCountyID(iCounter2);
			g_cIndividual[iPopulationCounter].SetAgeGroup(3);
			iPopulationCounter++;
		}
	}
 
 
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
		iAgePopulation[3][iCounter2] = gc_iPopulationSize[iCounter2]-iAgePopulation[0][iCounter2]-iAgePopulation[1][iCounter2]-iAgePopulation[2][iCounter2]-iAgePopulation[4][iCounter2];
 
 
	for(iCounter2=subtotal[number_counties-2];iCounter2<subtotal[number_counties-1];iCounter2++)
	{	g_cIndividual[iCounter2].SetAdultStatus(true);
		g_cIndividual[iCounter2].SetCountyID(number_counties-1);
		g_cIndividual[iCounter2].SetAgeGroup(3);
	}
 
 
	for(iCounter = 0; iCounter < number_counties-1; iCounter++)
	{
		iAdultsPopulation[iCounter] = iAgePopulation[3][iCounter] + iAgePopulation[4][iCounter];
		iChildrenPopulation[iCounter] = iAgePopulation[0][iCounter] + iAgePopulation[1][iCounter] + iAgePopulation[2][iCounter]; 
	}
 
	iAdultsPopulation[number_counties-1] = gc_iPopulationSize[number_counties-1];
	iChildrenPopulation[number_counties-1] = 0;
 
/*
	gc_iAdultsTotal = 0;
	for(iCounter=0; iCounter<number_counties; iCounter++)
		gc_iAdultsTotal+= iAdultsPopulation[iCounter];
	cout << "Adulttotal = " << gc_iAdultsTotal << endl;
 
	gc_iAdultsTotal = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
		if(g_cIndividual[iCounter].GetAdultStatus())
			gc_iAdultsTotal++;
	cout << "Adulttotal = " << gc_iAdultsTotal << endl;
*/	
 
 
	//ASSIGNMENT USING THE WORKFLOW DATA
 
	for(iCounter=0;iCounter<number_counties;iCounter++)
	{	sum[iCounter]=0;
		for(iCounter2; iCounter2<number_counties-1;iCounter2++)
			sum[iCounter] += workflow[iCounter][iCounter2];
	}
 
	for(iCounter=0;iCounter<number_counties-1;iCounter++)
		for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
		{	proportion[iCounter][iCounter2]= (double)workflow[iCounter][iCounter2]/(double)sum[iCounter];
			workflow[iCounter][iCounter2] = (int)floor(proportion[iCounter][iCounter2]*(double)iAgePopulation[3][iCounter]);
		}
 
	change1 = 0;
	for(iCounter=0;iCounter<number_counties-1; iCounter++)
	{
		peergroups[iCounter]=0;
 
		if((iCounter == 0)&&(change1==0))
		{	peergroupsizecontrol1 = iPeerGroupCounter;
			change1 = 1;
		}
 
		if(iCounter == 0)
			iCounter2 = iChildrenPopulation[iCounter] + iAgePopulation[4][iCounter];
		else
			iCounter2 = subtotal[iCounter-1] + iChildrenPopulation[iCounter] + iAgePopulation[4][iCounter];
 
		while(iCounter2<subtotal[iCounter])
		{
			iDummy = WorkGroupSize(iCounter);
			iPeerGroupSize = MIN(subtotal[iCounter]-iCounter2, iDummy);
			iCounter4 = 0;
			while(iCounter4 < iPeerGroupSize)
			{	
				g_cIndividual[iCounter2].SetPeerGroupID(iPeerGroupCounter);
				iCounter4++;
				iCounter2++;
			}
			iPeerGroupCounter++;
			peergroups[iCounter]++;
		}
		subtotal_peers[iCounter] = iPeerGroupCounter-1;
 
		if(iCounter == number_counties-2)
			peergroupsizecontrol2 = iPeerGroupCounter-1;
	}
 
 
	pop_counter2 = 0;
	for(iCounter=0; iCounter<subtotal[number_counties-2]; iCounter++)
	{
		if(g_cIndividual[iCounter].GetPeerGroupID()==-1)
			pop_counter2++;
	}
	cout << "UnassignedPeerGroup = "<< pop_counter2 << endl;
 
 
	//ASSIGNMENT FOR OUT OF STATE WORKERS
	for(iCounter=0;iCounter<number_counties-1;iCounter++)
	{ 
		left = iAgePopulation[3][iCounter];
		for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
		{
			iCounter4=0;
			while(iCounter4<workflow[iCounter][iCounter2] && left > 0 && iCounter!=iCounter2)
			{		
				iCounter5 = subtotal[iCounter-1]+iChildrenPopulation[iCounter]-1 + iAgePopulation[4][iCounter];
				chosen1 = subtotal[iCounter-1]+iChildrenPopulation[iCounter] + iAgePopulation[4][iCounter];
				chosen1 += DiscreteUniformDeviate(0,left-1);
				iCounter6 = subtotal[iCounter-1]+iChildrenPopulation[iCounter] + iAgePopulation[4][iCounter];
				do
				{
					if(g_cIndividual[iCounter6].GetPeerGroupID() <= subtotal_peers[iCounter] && g_cIndividual[iCounter6].GetPeerGroupID() > subtotal_peers[iCounter] - peergroups[iCounter])
						iCounter5++;
					iCounter6 ++;
				}while(iCounter5 < chosen1);
				chosen1 = iCounter6-1;
				left--;
 
				temp = DiscreteUniformDeviate(subtotal_peers[iCounter2] - peergroups[iCounter2] + 1, subtotal_peers[iCounter2]);
				g_cIndividual[chosen1].SetPeerGroupID(temp);
				iCounter4++;
			}
		}
	}
 
	iCounter5 = subtotal[number_counties-2];
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{	iCounter4=0;
		while(iCounter4<workflow[number_counties-1][iCounter2])
		{
			temp = DiscreteUniformDeviate(subtotal_peers[iCounter2] - peergroups[iCounter2] + 1, subtotal_peers[iCounter2]);
			g_cIndividual[iCounter5].SetPeerGroupID(temp);
			iCounter4++;
			iCounter5++;
		}
	}
 
 
	pop_counter2 = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
	{
		if(g_cIndividual[iCounter].GetPeerGroupID()==-1)
			pop_counter2++;
	}
	cout << "UnassignedPeerGroup = "<< pop_counter2 << endl;
 
 
	pop_counter = 0;
	for(iCounter=0;iCounter<number_counties-1; iCounter++)
		pop_counter += peergroups[iCounter];
 
	cout << "Total number of peer groups = "<<iPeerGroupCounter << endl;
	cout << "Student peer groups = "<<iPeerGroupCounterClass << endl;
	cout << "Old people peer gropus = "<<g_iOldGroups << endl;
	cout << "Worker peer groups = " << pop_counter << endl;
 
 
	//HOUSEHOLD ASSIGNMENT
 
	int iNumAdults = 0, iNumChildren = 0, iAdultsCounter = 0, iChildrenCounter = 0, 
		iHouseholdSize = 0, iNumHomelessChildren;
	int iHouseholdCounterTotal2 = 0;
 
	for(iCounter4=0;iCounter4<number_counties;++iCounter4)
	{	
		iHouseholdCounter[iCounter4]=0;
		subtotalhouse[iCounter4]=0;
	}
 
 
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		vector<int> vChildrenID, vAdultsID;
		for (iCounter = 0; iCounter < iChildrenPopulation[iCounter2]; ++iCounter)
			vChildrenID.push_back(iCounter);
		for (iCounter = iChildrenPopulation[iCounter2]; iCounter < gc_iPopulationSize[iCounter2]; ++iCounter)
			vAdultsID.push_back(iCounter);
 
		random_shuffle(vChildrenID.begin(), vChildrenID.end(), pointer_to_unary_function<int, int>(DiscreteUniformZeroDeviate));
		random_shuffle(vAdultsID.begin(), vAdultsID.end(), pointer_to_unary_function<int, int>(DiscreteUniformZeroDeviate));	
 
		iAdultsCounter = 0;
		iChildrenCounter = 0;
		iPopulationCounter = 0;
		while (iAdultsCounter != iAdultsPopulation[iCounter2])
		{
			if (iChildrenCounter != iChildrenPopulation[iCounter2])
			{
				iDummy = HouseholdSize(iCounter2);
				iHouseholdSize = MIN(gc_iPopulationSize[iCounter2]-iPopulationCounter, iDummy);
				iDummy = NumChildren(iHouseholdSize, iCounter2);
				iNumChildren = MIN(iChildrenPopulation[iCounter2]-iChildrenCounter, iDummy);
			}
			else
			{
				iDummy = HouseholdSize(iCounter2);
				iHouseholdSize = MIN(gc_iPopulationSize[iCounter2]-iPopulationCounter, iDummy);
				iNumChildren = 0;
			}
			iNumAdults = MIN(iAdultsPopulation[iCounter2]-iAdultsCounter, iHouseholdSize-iNumChildren);
 
			for (iCounter = 0; iCounter < iNumAdults; ++iCounter)
			{		
				if(iCounter2 == 0)
				{
					iThisID = vAdultsID[iAdultsCounter];
					g_cIndividual[iThisID].SetHouseholdID(iHouseholdCounterTotal);
					++iAdultsCounter;
				}
				else
				{
					iThisID = vAdultsID[iAdultsCounter]+subtotal[iCounter2-1];
					g_cIndividual[iThisID].SetHouseholdID(iHouseholdCounterTotal);
					++iAdultsCounter;
				}
			}
 
			for (iCounter = 0; iCounter < iNumChildren; ++iCounter)
			{
				if(iCounter2 == 0)
				{
					iThisID = vChildrenID[iChildrenCounter];
					g_cIndividual[iThisID].SetHouseholdID(iHouseholdCounterTotal);
					++iChildrenCounter;
				}
				else
				{
					iThisID = vChildrenID[iChildrenCounter]+subtotal[iCounter2-1];
					g_cIndividual[iThisID].SetHouseholdID(iHouseholdCounterTotal);
					++iChildrenCounter;
				}
			}
	
			iPopulationCounter += iHouseholdSize;
			iHouseholdCounter[iCounter2]++;
			++iHouseholdCounterTotal;
	
			for(iCounter4=number_counties-1;iCounter4>=iCounter2;iCounter4--)
				subtotalhouse[iCounter4]++;
		}
 
		// Take care of the homeless children
		iNumHomelessChildren = iChildrenPopulation[iCounter2]-iChildrenCounter;
 
		if (iNumHomelessChildren > 0)
		{
			unsigned int iCounter3 = 0, iChosenHousehold;
			while (iChildrenCounter < iChildrenPopulation[iCounter2])
			{
				if(iCounter2 == 0)
					iThisID = vChildrenID[iChildrenCounter];
				else
					iThisID = vChildrenID[iChildrenCounter]+subtotal[iCounter2-1];
 
				iChosenHousehold = static_cast<int>(fmod(static_cast<double>(iCounter3), static_cast<double>(iHouseholdCounter[iCounter2])));
				if(iCounter2 > 0)
					iChosenHousehold += subtotalhouse[iCounter2-1];
				g_cIndividual[iThisID].SetHouseholdID(iChosenHousehold);
				++iChildrenCounter;
				++iCounter3;
			}
		}
	}
 
 
	iHouseholdCounterTotal2 = iHouseholdCounterTotal;
	for(iCounter2=subtotal[number_counties-2];iCounter2<subtotal[number_counties-1];iCounter2++)
	{
		g_cIndividual[iCounter2].SetHouseholdID(iHouseholdCounterTotal2);
		iHouseholdCounterTotal2++;
	}
	subtotalhouse[number_counties-1]=iHouseholdCounterTotal2;
 
 
	if (g_iMaxNumGroups[HOUSEHOLD] < iHouseholdCounterTotal2)
	{
		if (g_cHousehold != NULL)
			delete [] g_cHousehold;
		g_iMaxNumGroups[HOUSEHOLD] = static_cast<int>(1.05*iHouseholdCounterTotal2);
		g_cHousehold = new CHousehold[g_iMaxNumGroups[HOUSEHOLD]];
	}
	g_iNumGroups[HOUSEHOLD] = iHouseholdCounterTotal2;
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
	{
		g_cHousehold[iCounter].ClearMemberList();	
		g_cHousehold[iCounter].Reset(iCounter);
	}
 
 
	cout << "Householdtotal2 = "<< iHouseholdCounterTotal2 <<endl;
	cout << "Householdtotal = "<< iHouseholdCounterTotal <<endl;
	cout << "PeerGroups = " << iPeerGroupCounter <<endl;
 
	if (g_iMaxNumGroups[PEERGROUP] < iPeerGroupCounter)
	{
		if (g_cPeerGroup != NULL)
			delete [] g_cPeerGroup;
		g_iMaxNumGroups[PEERGROUP] = static_cast<int>(1.05*iPeerGroupCounter);
		g_cPeerGroup = new CPeerGroup[g_iMaxNumGroups[PEERGROUP]];
	}
	g_iNumGroups[PEERGROUP] = iPeerGroupCounter;
	for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
	{
		g_cPeerGroup[iCounter].ClearMemberList();
		g_cPeerGroup[iCounter].Reset(iCounter);
	}
 
	pop_counter = 0;
	pop_counter2 = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
	{
		if(g_cIndividual[iCounter].GetHouseholdID()==-1)
			pop_counter++;
		if(g_cIndividual[iCounter].GetPeerGroupID()==-1)
			pop_counter2++;
	}
	cout << "UnassignedHousehold = "<< pop_counter << endl;
	cout << "UnassignedPeerGroup = "<< pop_counter2 << endl;
 
 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
		g_cHousehold[g_cIndividual[iCounter].GetHouseholdID()].AddToMemberList(iCounter);
 
 
	pop_counter = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
		if((g_cIndividual[iCounter].GetPeerGroupID()>iPeerGroupCounter) || (g_cIndividual[iCounter].GetPeerGroupID()<0))
			pop_counter++;
	cout << "Wrongly assigned peer groups = " << pop_counter << endl;
 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
		g_cPeerGroup[g_cIndividual[iCounter].GetPeerGroupID()].AddToMemberList(iCounter);
 
 
	for(iCounter=0;iCounter<number_counties;++iCounter)
	{	
		g_dInfHazardCommunity[iCounter] = 0.58/gc_iPopulationSize[iCounter];		
//		g_dInfHazardCommunity[iCounter] = 0.58/100000;
//		g_dImportRate[iCounter]= 0.0;
//		g_dImportRate[iCounter]= gc_dFlatImportRate/100000;
		g_dImportRate[iCounter]= gc_dFlatImportRate/gc_iHKPopulationSize;
	}
 
 
	pop_counter = 0;
	pop_counter2 = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
	{
		if(g_cIndividual[iCounter].GetHouseholdID()==-1)
			pop_counter++;
		if(g_cIndividual[iCounter].GetPeerGroupID()==-1)
			pop_counter2++;
	}
	cout << "UnassignedHousehold = "<< pop_counter << endl;
	cout << "UnassignedPeerGroup = "<< pop_counter2 << endl;
 
	pop_counter = 0;
	pop_counter2 = 0;
	for(iCounter=0; iCounter<gc_iPopulationSizeTotal; iCounter++)
	{
		if(g_cIndividual[iCounter].GetCountyID()==-1)
			pop_counter++;
		if(g_cIndividual[iCounter].GetAgeGroup()==-1)
			pop_counter2++;
	}
	cout << "UnassignedCounty = "<< pop_counter << endl;
	cout << "UnassignedAgeGroup = "<< pop_counter2 << endl;
 
	cout << "BUILDING FINAL" << endl;
 
}
 
 
 
 
void PrintHouseholdStatistics()
{
	unsigned int iCounter, iCounter2;
	double dHouseholdStatistics[9][10];
	int iHouseholdSize, iNumAdults, iNumChildren;
 
	for (iCounter = 0; iCounter < 9; ++iCounter)
	{
		for (iCounter2 = 0; iCounter2 < 10; ++iCounter2)
			dHouseholdStatistics[iCounter][iCounter2] = 0;
	}
 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
	{
		iHouseholdSize = g_cHousehold[g_cIndividual[iCounter].GetHouseholdID()].GetHouseholdSize();
		iNumAdults = g_cHousehold[g_cIndividual[iCounter].GetHouseholdID()].GetNumAdults();
		iNumChildren = iHouseholdSize-iNumAdults;
		dHouseholdStatistics[iNumChildren][iHouseholdSize-1] += 1.0/static_cast<double>(iHouseholdSize);
	}
 
	ofstream fOutFile("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/HouseholdStatistics.txt");
	for (iCounter = 0; iCounter < 9; ++iCounter)
	{
		for (iCounter2 =0; iCounter2 <10; ++iCounter2)
			fOutFile << dHouseholdStatistics[iCounter][iCounter2]/static_cast<double>(g_iNumGroups[HOUSEHOLD]) << " ";
		fOutFile << endl;
	}
	fOutFile.close();
}
 
int CTListSize()
{
#ifndef CONTACT_TRACING
	return 0;
#else
	return (int)g_cCTList.size()-g_iNumCTRecordRemoved;
#endif
}
 
void DisplayProgress(int day) 
{
	int iEventListSize = 0, iCounter, iCounter2, iCounter3, iCounter4, iCounter5, iHeadCount;
	for (iCounter = 0; iCounter < gc_iNumEventLists; ++iCounter)
		if (g_pEventList[iCounter]!=NULL)
			iEventListSize += static_cast<int>((*(g_pEventList[iCounter])).size());
 
	cout << "------------------------------------------------------------------------------------------" << endl;
	cout << endl << "Running Paremeter Set " << g_iParameterSetIndex << " with seed " << g_iSeed << endl;
 
	cout << "Actual time elapsed for this realization = " << static_cast<int>(time(NULL)-g_tClockStart2) << " seconds" << endl << endl;
	cout << "Policy: " << g_sPolicyString[g_iPolicy] << endl;
	cout << "Time: " << g_dTime+day << endl << endl;
	cout << setw(8) << "SUS" << setw(8) << "EXP" << setw(8) << "PRESYM" << setw(8) << "ASYM" <<
		setw(8) << "SYM" << setw(8) << "RECOV" << setw(8) << "HOSP" << setw(8) << "DEAD" << endl;
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
	{
		iHeadCount = 0;
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
					for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
					iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
		cout << setw(8) << iHeadCount;
	}
	cout << endl << endl;
 
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
	{
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
				{	g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] = 0;
					for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
						g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
				}
	}
 
	cout << "FreeSusceptible = " << g_iHeadCountTotal[SUSCEPTIBLE][0][0][0] << ", QuarantinedSusceptible = " << 
		g_iHeadCountTotal[SUSCEPTIBLE][1][0][0]+g_iHeadCountTotal[SUSCEPTIBLE][1][1][0] << ", IsolatedSusceptible = " << 
		g_iHeadCountTotal[SUSCEPTIBLE][0][0][1] << endl;
	cout << "FreeSymptomatic = " << g_iHeadCountTotal[SYMPTOMATIC][0][0][0] << ", QuarantinedSymptomatic = " << 
		g_iHeadCountTotal[SYMPTOMATIC][1][0][0]+g_iHeadCountTotal[SYMPTOMATIC][1][1][0] << ", IsolatedSymptomatic = " << 
		g_iHeadCountTotal[SYMPTOMATIC][0][0][1] << endl;
	cout << "FreePresymptomatic = " << g_iHeadCountTotal[PRESYMPTOMATIC][0][0][0] << ", QuarantinedPresymptomatic = " << 
		g_iHeadCountTotal[PRESYMPTOMATIC][1][0][0]+g_iHeadCountTotal[PRESYMPTOMATIC][1][1][0] << ", IsolatedPresymptomatic = " << 
		g_iHeadCountTotal[PRESYMPTOMATIC][0][0][1] << endl;
	cout << "FreeAsymptomatic = " << g_iHeadCountTotal[ASYMPTOMATIC][0][0][0] << ", QuarantinedAsymptomatic = " << 
		g_iHeadCountTotal[ASYMPTOMATIC][1][0][0]+g_iHeadCountTotal[ASYMPTOMATIC][1][1][0] << ", IsolatedAsymptomatic = " << 
		g_iHeadCountTotal[ASYMPTOMATIC][0][0][1] << endl;
	cout << "% Leakage = " << static_cast<double>(g_iDailyLeakage)/MAX(1, g_iDailyNumQuarantineReleased)*100 << endl;
 
	cout << "NumQuarantined = " << g_iNumQuarantined << ", MaxNumQuarantined = " << g_iMaxNumQuarantined <<  endl;
	cout << "NumIsolated = " << g_iNumIsolated << ", MaxNumIsolated = " << g_iMaxNumIsolated <<  endl;
	cout << endl;
 
	cout << "TotalNumQuarantineReleased = " << g_iTotalNumQuarantineReleased  << 
		", TotalNumIsolationReleased = " << g_iTotalNumIsolationReleased << endl;
	cout << "ImportRate = " << g_dImportRate[0]*gc_iPopulationSizeTotal << ", TotalNumSpam = " << g_iTotalNumSpam << 
		", TotalNumImport = " << g_iTotalNumImport << endl;
 
	cout << "NumActiveTestServers = " << g_iNumActiveTestServers << endl;
	cout << "NumActiveCTServers = " << g_iNumActiveCTServers << ", CTListSize = " << CTListSize() << endl;
	cout << endl;
 
 
 
	FILE * pFile;
	pFile = fopen ("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/myfile.txt","a");
//	fprintf(pFile, "%f\n", g_dTime);
 
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
	{
		iHeadCount = 0;
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
					for (iCounter5 = 0; iCounter5 < number_counties-1; ++iCounter5)
					iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
		fprintf(pFile,"%d	", iHeadCount);
	}
	fprintf(pFile,"\n");
	fclose (pFile);
 
/*
	pFile = fopen ("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/myfilemetroAtlanta.txt","a");
	for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
	{
		iHeadCount = 0;
		for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
			for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
				for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
					for (iCounter5 = 0; iCounter5 < 15; ++iCounter5)
					iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][metroAtlanta[iCounter5]];
		fprintf(pFile,"%d	", iHeadCount);
	}
	fprintf(pFile,"\n");
	fclose (pFile);
 
 
	char filename[100];
	for(iCounter5 = 0; iCounter5 < 15; iCounter5++)
	{
		sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/individualresults%0.3d.txt",metroAtlanta[iCounter5]);
		pFile = fopen(filename, "a");
		for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
		{
			iHeadCount = 0;
			for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
				for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
					for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
						iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][metroAtlanta[iCounter5]];
			fprintf(pFile,"%d	", iHeadCount);
		}
		fprintf(pFile, "\n");
		fclose (pFile);
	}
*/
 
 
 
/*
	char filename[100];
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/dailyresults%0.3d.txt",(int)(g_dTime));
 
	pFile = fopen(filename, "w");
	for(iCounter5 = 0; iCounter5 < number_counties-1; iCounter5++)
	{
		for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
		{
			iHeadCount = 0;
			for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
				for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
					for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
						iHeadCount += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
			fprintf(pFile,"%d	", iHeadCount);
		}
		fprintf(pFile, "\n");
	}
	fclose (pFile);
*/
 
}
 
/*
void PrintParameters(const bool x){
	char cBuffer[50];
	if (x==true)
		sprintf(cBuffer, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/ParametersBefore%d.txt", g_iParameterSetIndex);
	else
		sprintf(cBuffer, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/ParametersAfter%d.txt", g_iParameterSetIndex);
	ofstream pout(cBuffer);
	pout << "Contact Network Parameters" << endl;
	pout << "Population Size\t" << gc_iPopulationSizeTotal << endl;
	pout << "Family Composition\t HK Census Data" << endl;
	pout << "Class Size\t Uniform(" << gc_iMinClassSize << ", " << gc_iMaxClassSize << ")" << endl;
	pout << "Workplace Size\t Poisson(" << gc_dMeanNumCoworkers << ")" << "\t Poisson conditional on nonzero values" << endl;
	pout << endl;
 
	pout << "Disease Transmission Parameters" << endl;
	pout << "R0star\t" << g_dR0 << endl;
	pout << "Theta (Proportion of Transmission Presymptomatic or Asymptomatic)\t" << g_dTheta << endl;
	pout << "Omega (Proportion of Transmission By Never Symptomatics)\t" << g_dOmega << endl;
	pout << "Gamma (Proportion of Transmission Outside Home)\t" << g_dGamma << endl;
	pout << "Delta (Proportion of Transmission Outside Home Due to Community)\t" << g_dDelta << endl;
	pout << "Proportion of Symptomatic Adults that Go to Work\t" << g_dProbSymActiveAdults << endl;
	pout << "Proportion of Symptomatic Children that Go to School\t" << g_dProbSymActiveChildren << endl;
	pout << "Beta\t " << g_dBeta << endl;
	pout << "Presymptomatic-to-Symptomatic Relative Hazard\t" << g_dInfHazardPresym << endl;
	pout << "Asymptomatic-to-Symptomatic Relative Hazard\t" << g_dInfHazardAsym << endl;
	pout << "Workplace-Household Relative Hazard (Adults Only)\t" << g_dInfHazardPeerGroupAdults << endl;
	pout << "School-Household Relative Hazard (Children Only)\t" << g_dInfHazardPeerGroupChildren << endl;
//	pout << "Community-Household Relative Hazard\t " << g_dInfHazardCommunity << endl;
	pout << "Relative R0 In Isolation\t" << g_dRelativeR0Isolation << endl;
	pout << endl;
 
	pout << "Disease Progression Parameters" << endl;
	pout << "Exposed Duration\t Weibull(" << gc_dMeanExpDuration << ", " << gc_dStdDevExpDuration << ")" << endl;
	pout << "Asymptomatic Duration\t Exp(" << g_dMeanAsymDuration << ")" << endl;
	pout << "Presymptomatic Duration\t " << gc_dMeanPresymDuration << endl;
	pout << "Symptomatic Duration\t Exp(" << g_dMeanSymDuration << ")" << endl;
	pout << "Hospitalization Duration\t Exp(" << gc_dMeanHospDuration << ")" << endl;
	pout << "Probability of Symptoms\t " << gc_dProbSymptoms << endl;
	pout << "Probability of Hospitalization Given Symptoms\t" << gc_dProbHospitalization << endl;
	pout << "Probability of Death Given Hospitalization\t " << gc_dProbDeath << endl;
	pout << endl;
 
	pout << "Intervention Parameters" << endl;
	pout << "Probability of Report Upon Symptoms\t " << g_dProbReport << endl;
	pout << "Probability of Voluntary Isolation Given Compliance\t" << g_dProbIsolation << endl;
	pout << "Mean number of Peers Named as Contacts\t " << gc_dMeanNumContactNamed << endl;
	pout << "Sensitivity of Diagnostic Test\t" << gc_dTestSensitivity << endl;
	pout << "Specificity of Diagnostic Test\t" << gc_dTestSpecificity << endl;
	pout << "Number of CT Servers\t" << gc_iMaxNumCTServers << endl;
	pout << "Number of Test Servers\t" << gc_iMaxNumTestServers << endl;
	pout << "Time to Trace a Household\t Exp(" << gc_dMeanTraceDuration << ")" << endl;
	pout << "Time to Test a Sample\t " << gc_dMeanTestDuration << endl;
	pout << "Relative Susceptibility with Drug\t" << gc_dSusHazardDrug << endl;
	pout << "Relative Infectivity with Drug\t" << gc_dInfHazardDrug << endl;
	pout << "Relative Within-Household Susceptibility with Quarantine\t" << g_dSusHazardHouseholdQuarantine << endl;
	pout << "Relative Within-Household Infectivity with Quarantine\t" << g_dInfHazardHouseholdQuarantine << endl;
	pout << "Relative Within-PeerGroup Susceptibility with Quarantine\t" << gc_dSusHazardPeerGroupQuarantine << endl;
	pout << "Relative Within-PeerGroup Infectivity with Quarantine\t" << gc_dInfHazardPeerGroupQuarantine << endl;
	pout << "Probabilty of Compliance with No Drugs\t" << g_dProbComplianceNoDrugs << endl;
	pout << "Probabilty of Compliance with Drugs\t" << g_dProbComplianceDrugs << endl;
	pout << "Quarantine Clock\t" << gc_dQuarantineClock << endl;
	pout << "Isolation Clock\t" << gc_dIsolationClock << endl;
	pout << "Mean Isolation Delay\t" << g_dMeanIsolationDelay << endl;
	pout << "Mean Antiviral-Prophylaxis Delay\t" << g_dMeanDrugDelay << endl;
	pout << endl;
 
	pout << "Stress Parameters" << endl;
	pout << "Disease Import Rate\t" << gc_dFlatImportRate*gc_iHKPopulationSize << "\t Per 6.8 million" <<endl;
	pout << "Spam Rate\t" << gc_dSpamRate*gc_iHKPopulationSize << "\t Per 6.8 million" << endl;
	pout << endl;
 
	pout << "Time end: " << gc_dTimeMax << endl;
	pout << "Number of samples: " << gc_iNumRealizations  << endl;
	pout << "Policy evaluated:" << endl;
	for (int iCounter = 0; iCounter < gc_iNumPolicies; ++iCounter)
		pout << g_sPolicyString[gc_iPolicySet[iCounter]] << " " << endl;
	pout << endl;
}
*/
 
void ReadParameters(const int iParameterSetIndex){
	char cTemp[10000];
	double dDummy, dRelativeR0Quarantine;
	char *pcEnd;
	int iCurrentIndex = 1;
	ifstream ifParameterFile("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/ParameterListMidGam.txt");
	if (!ifParameterFile)
	{
		cout << "Parameter List not found." << endl; 
		Pause();
	}
	while (iCurrentIndex != iParameterSetIndex)
	{
		ifParameterFile.getline(cTemp, 10000);
		++iCurrentIndex;
	}
	ifParameterFile.getline(cTemp, 100, ' ');
	dDummy = strtod(cTemp, &pcEnd);
	iCurrentIndex = Round(dDummy); 
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dR0 = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dTheta = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dOmega = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dGamma = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');  // grab Tg
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dRelativeR0Isolation = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	dRelativeR0Quarantine = strtod(cTemp, &pcEnd);
	g_dSusHazardHouseholdQuarantine = pow(dRelativeR0Quarantine, 0.5);
	g_dInfHazardHouseholdQuarantine = g_dSusHazardHouseholdQuarantine;
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dProbCompliance = strtod(cTemp, &pcEnd);
	g_dProbComplianceDrugs = g_dProbCompliance;
	g_dProbComplianceNoDrugs = g_dProbCompliance;
	g_dProbReport = g_dProbCompliance;
	g_dProbIsolation = g_dProbCompliance;
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dMeanIsolationDelay = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dMeanDrugDelay = strtod(cTemp, &pcEnd);
 
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dBeta = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dInfHazardPresym = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dInfHazardAsym = strtod(cTemp, &pcEnd);
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dInfHazardPeerGroupAdults = strtod(cTemp, &pcEnd);
	g_dInfHazardPeerGroupChildren = g_dInfHazardPeerGroupAdults;
	ifParameterFile.getline(cTemp, 100, ' ');
//	g_dInfHazardCommunity = strtod(cTemp, &pcEnd);
//	g_dInfHazardCommunity /= gc_iPopulationSizeTotal;
	ifParameterFile.getline(cTemp, 100, ' ');
	g_dMeanSymDuration = strtod(cTemp, &pcEnd);
	g_dMeanAsymDuration = g_dMeanSymDuration/gc_dSymAsymDurationRatio;
 
	g_dBetaIsolation = g_dRelativeR0Isolation*g_dR0/(g_dMeanSymDuration+gc_dProbHospitalization*gc_dMeanHospDuration);
 
	ifParameterFile.close(); 
}
 
void ActivatePolicy(const Policy x)
{
	g_iPolicy = x;
	switch(g_iPolicy)
	{
	case NONE:
		{
			g_bQuarantineActive = false;
			g_bIsolationActive = false;
			g_bTestingActive = false;
			g_bTracingActive = false;
			g_bDrugActive = false;
		}
		break;
	case Q:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = false;
			g_bTestingActive = false;
			g_bTracingActive = false;
			g_bDrugActive = false;
		}
		break;
	case QA:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = false;
			g_bTestingActive = false;
			g_bTracingActive = false;
			g_bDrugActive = true;
		}
		break;
	case QI:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = true;
			g_bTestingActive = false;
			g_bTracingActive = false;
			g_bDrugActive = false;
		}
		break;
	case QIA:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = true;
			g_bTestingActive = false;
			g_bTracingActive = false;
			g_bDrugActive = true;
		}
		break;
//#ifdef TESTING
	case QIAT:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = true;
			g_bTestingActive = true;
			g_bTracingActive = false;
			g_bDrugActive = true;
		}
		break;
//#endif
#ifdef CONTACT_TRACING
	case QIAC:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = true;
			g_bTestingActive = false;
			g_bTracingActive = true;
			g_bDrugActive = true;
		}
		break;
#ifdef TESTING
	case QIATC:
		{
			g_bQuarantineActive = true;
			g_bIsolationActive = true;
			g_bTestingActive = true;
			g_bTracingActive = true;
			g_bDrugActive = true;
		}
		break;
#endif
#endif
	default:
		{
			cout << "Error in ActivatePolicy().  Policy undefined: " <<  g_sPolicyString[g_iPolicy] << endl;
			Pause();
		}
	}
	if (g_bDrugActive==true)
		g_dProbCompliance = g_dProbComplianceDrugs;
	else
		g_dProbCompliance = g_dProbComplianceNoDrugs;
}
 
 
int Rand(int n)
{
    return rand() % n ;
}
 
 
void readOptimizationData(int argChooseFile)
{
	int i=0,j=0;
 
	if(argChooseFile==0)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/CountyDistance.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	for(j=0;j<number_counties-1;j++)
			{	
				fscanf(inFile, "%lf ", &distancecounty[i][j]);
			}
			fscanf(inFile, "\n");
		}
		fclose(inFile);
//		cout<<distancecounty[158][157]<<endl;
	}
	else if(argChooseFile==1)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/facilityCapacity.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	for(j=0;j<MaxNumberFacility2;j++)
			{	
				fscanf(inFile, "%lf ", &capacityFacility[i][j]);
			}
			fscanf(inFile, "\n");
		}
		fclose(inFile);
//		cout<<capacityFacility[158][0]<<endl;
	}
	else if(argChooseFile==2)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/facilityFixedCost.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	for(j=0;j<MaxNumberFacility2;j++)
			{	
				fscanf(inFile, "%lf ", &fixedFacilityCost[i][j]);
			}
			fscanf(inFile, "\n");
		}
		fclose(inFile);
//		cout<<fixedFacilityCost[158][0]<<endl;
	}
	else if(argChooseFile==3)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/facilityOpeningCost.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	for(j=0;j<MaxNumberFacility2;j++)
			{	
				fscanf(inFile, "%lf ", &openFacilityCost[i][j]);
			}
			fscanf(inFile, "\n");
		}
		fclose(inFile);
//		cout<<openFacilityCost[158][0]<<endl;
	}
	else if(argChooseFile==4)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/facilityClosingCost.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	for(j=0;j<MaxNumberFacility2;j++)
			{	
				fscanf(inFile, "%lf ", &closeFacilityCost[i][j]);
			}
			fscanf(inFile, "\n");
		}
		fclose(inFile);
//		cout<<closeFacilityCost[158][0]<<endl;
	}
	else if(argChooseFile==5)
	{
		FILE *inFile = fopen("C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/supply.txt", "r");
		for(i=0;i<number_counties-1;i++)
		{	
			fscanf(inFile, "%lf\n", &supply[i]);
		}
		fclose(inFile);
//		cout<<supply[154]<<endl;
 
	}
	else
		cout<<"Wrong Input again"<<endl;
}
 
int readdata()
{
	int i;
 
	readOptimizationData(0);
	readOptimizationData(1);
	readOptimizationData(2);
	readOptimizationData(3);
	readOptimizationData(4);
	readOptimizationData(5);
 
	supplynodes = 0;
	for(i=0;i<number_counties-1;i++)
	{
		if(supply[i]>0)
		{	
			originalsupplycountyindex[supplynodes]=i;
			supplynodes++;
		}
	}
 
	facilitynodes = 0;
	for(i=0;i<number_counties-1;i++)
	{
		if(capacityFacility[i][0]>0)
		{
			originalfacilitycountyindex[facilitynodes]=i;
			facilitynodes++;
		}
	}
 
	
cout << supplynodes << endl;
cout << facilitynodes << endl;
cout << originalfacilitycountyindex[facilitynodes-1] << endl;
cout << originalsupplycountyindex[supplynodes-1] << endl;
cout << capacityFacility[originalfacilitycountyindex[facilitynodes-1]][0] << endl;
cout << capacityFacility[originalfacilitycountyindex[facilitynodes-1]][1] << endl;
cout << fixedFacilityCost[originalfacilitycountyindex[facilitynodes-1]][0] << endl;
cout << fixedFacilityCost[originalfacilitycountyindex[facilitynodes-1]][1] << endl;
//cout << capacityFacility[originalfacilitycountyindex[facilitynodes-1]][2] << endl;
 
//exit(0);
 
	return 0;
}
 
/*
int finaloptimization(int originalproblem){
 
	cout<<"Reading Data for final Optimization"<<endl;
 
	int numberFacility[number_counties-1];
	int periods;
	double totalcost=0.0;
	double totaldemand=0.0;
	double totaldemand30=0.0;
 
	cout<<"All files read!!"<<endl;
 
	int ii=0,jj, kk, tt;
	periods = TforOpt;
 
//READ ORIGINAL DEMAND DATA
 
	char filename[100];
	FILE *inFile;
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/dailydemand.txt");
	inFile = fopen(filename, "r");
 
	for(ii=0;ii<periodlength*optimizationstart;ii++)
		fscanf(inFile,"\n");	
 
	for(ii=0;ii<maxNumOfDaysForOpt;ii++)
	{	
		for(jj = 0; jj < number_counties-1; jj++)
			fscanf(inFile, "%lf	", &dailyDemand[jj][ii][0]);
		fscanf(inFile,"\n");
	}
	fclose(inFile);
 
 
	//To convert daily demand into weekly demand. We assume that the time interval for opt is 7 days
	for(ii=0;ii<number_counties-1;ii++){
		for(jj=0;jj<periods;jj++){
			demand[ii][jj]=0;
		}
	}
	for(jj=0;jj<number_counties-1;jj++){
		ii=0;
		int periodTracker=0;
		while(periodTracker<periods){
			demand[jj][periodTracker]+=dailyDemand[jj][ii][0];
			ii++;
			if(ii!=0){
				if(ii%periodlength==0)
					periodTracker++;
			}
		}
	}
 
	for(ii=0;ii<number_counties-1;ii++){
		for(jj=0;jj<periods;jj++){
			totaldemand+=demand[ii][jj];
		}
	}
 
 
 
 
	for(ii=0;ii<number_counties-1;ii++)
	{
		numberFacility[ii]=0;
		for(jj=0;jj<MaxNumberFacility2;jj++)
			if(capacityFacility[ii][jj]>0)
				numberFacility[ii]++;
	}
 
	cout<<"All set for CPLEX!!"<<endl;
 
 
 
	IloEnv env;
	try{
		IloModel model(env);
 
		IloNum c_u, c_r, c_o, c_individual, invholdingcost;
//		IloInt truckCapacity;
		IloInt nodes,T;
		int i,t,j,k,s;
		IloInt MaxNumberFacility;
 
		c_u = 1.0;
		c_r = 50.0;
		c_o = 0.5;
		c_individual = 2.0;
		invholdingcost = 0.3;
//		truckCapacity = 500;
//		T=3;
//		nodes = 4;
 
		T=TforOpt;
		nodes = number_counties-1;
		MaxNumberFacility=MaxNumberFacility2;
 
 
 
 
//---------------------Decision variable Definition Starts here---------------------------------------------
 
 
		D3Array y(env,T); 
		for(i=0;i<T;i++){
			y[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++){ 			
				y[i][j] = IloNumVarArray(env,MaxNumberFacility,0,1,ILOINT); 
			}
		}
 
		D3Array w(env,T); 
		for(i=0;i<T;i++){
			w[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++){ 			
				w[i][j] = IloNumVarArray(env,MaxNumberFacility,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		D3Array z(env,T); 
		for(i=0;i<T;i++){
			z[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++){ 			
				z[i][j] = IloNumVarArray(env,MaxNumberFacility,0,IloInfinity,ILOFLOAT); 
			}
		}
 
 
		D3Array x(env,T); 
		for(i=0;i<T;i++){
			x[i] = D2Array(env,supplynodes+facilitynodes);
	 		for(j=0;j<supplynodes+facilitynodes;j++){
				x[i][j] = IloNumVarArray(env,facilitynodes,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		D3Array xx(env,T); 
		for(i=0;i<T;i++){
			xx[i] = D2Array(env,facilitynodes);
	 		for(j=0;j<facilitynodes;j++){
				xx[i][j] = IloNumVarArray(env,nodes,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		
//		D3Array r(env,T); 
//		for(i=0;i<T;i++){
//			r[i] = D2Array(env,2*nodes);
//	 		for(j=0;j<2*nodes;j++){
//				r[i][j] = IloNumVarArray(env,nodes,0,IloInfinity,ILOINT); 
//			}
//		}
		
		D2Array inventory(env,T); 
		for(i=0;i<T;i++){
			inventory[i] = IloNumVarArray(env,facilitynodes,0,IloInfinity,ILOFLOAT); 
		}
 
//---------------------Decision variable Definition Ends here-----------------------------------------------
 
 
 
 
//---------------------Constraint Definition Starts here----------------------------------------------------	
 
		//Supply Constraint
		for(t=0;t<T;t++)
		{
			for(j=0;j<supplynodes;j++)
			{
					IloExpr v(env);
					for(k=0;k<facilitynodes;k++)
						v+=x[t][j][k];
					model.add(v<=supply[originalsupplycountyindex[j]]);
					v.end();
			}
		}
 
		//Demand Constraint
		for(t=0;t<T;t++)
		{
			for(k=0;k<nodes;k++)
			{
				IloExpr v(env);
				for(j=0;j<facilitynodes;j++)
					v+=xx[t][j][k];
				model.add(v>=demand[k][t]);
				v.end();
			}
		}
 
		//Capacity constraint for each facility
		for(t=0;t<T;t++)
		{
			for(k=0;k<facilitynodes;k++)
			{
				IloExpr v1(env);
				IloExpr v2(env);
				for(j=0;j<supplynodes+facilitynodes;j++)
					v1+=x[t][j][k];
 
				for(s=0;s<numberFacility[originalfacilitycountyindex[k]];s++)
					v2+=capacityFacility[originalfacilitycountyindex[k]][s]*y[t][k][s];
				if(t==0)
					model.add(v1<=v2);
				else
					model.add(inventory[t-1][k]+v1<=v2);
				v1.end();
				v2.end();
			}
		}
 
		//Flow balance constraint
		for(t=0;t<T;t++)
		{
			for(k=0;k<facilitynodes;k++)
			{
				IloExpr v1(env);
				IloExpr v2(env);
				for(j=0;j<supplynodes+facilitynodes;j++)
					v1+=x[t][j][k];
 
				for(j=0;j<facilitynodes;j++)
					v2+=x[t][k+supplynodes][j];
 
				for(j=0;j<nodes;j++)
					v2+=xx[t][k][j];
 
				if(t==0)
					model.add(v1-inventory[t][k]-v2==0);
				else
					model.add(inventory[t-1][k]+v1-inventory[t][k]-v2==0);
				v1.end();
				v2.end();
			}
		}
 
		
		//No of Trucks constraint
//		for(t=0;t<T;t++){
//			for(j=0;j<2*nodes;j++){
//				for(k=0;k<nodes;k++){
//					if(j<nodes)
//					{	
//						if(supply[j]>0 && numberFacility[k]>0)
//						if(supply[j]>0 && numberFacility[k]>0)
//							model.add(x[t][j][k]-truckCapacity*r[t][j][k]<=0);
//					}
//					else
//					{	if(numberFacility[j-nodes]>0 && numberFacility[k]>0)
//							model.add(x[t][j][k]-truckCapacity*r[t][j][k]<=0);
//					}
//				}
//			}
//		}
 
		//Facility open/close constraint
		for(t=0;t<T;t++)
		{
			for(j=0;j<facilitynodes;j++)
			{
				for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				{
					if(t==0)
						model.add(w[t][j][s]-y[t][j][s]>=0);
					else
						model.add(w[t][j][s]-y[t][j][s]+y[t-1][j][s]>=0);
 
					if(t+1==T)
						model.add(z[t][j][s]-y[t][j][s]>=0);
					else
						model.add(z[t][j][s]-y[t][j][s]+y[t+1][j][s]>=0);
				}
			}
		}
 
		//Final Inventory should be zero
		for(j=0;j<facilitynodes;j++)
		{
				model.add(inventory[T-1][j]==0);
		}
 
		//Additional Value Setting
		//If you don't use this you'll get an IloExtractable exception as values for 
		//these indices are not defined anywhere else in the problem.
 
		for(t=0;t<T;t++)
		{
			for(j=0;j<facilitynodes;j++)
			{
				for(k=numberFacility[originalfacilitycountyindex[j]];k<MaxNumberFacility;k++)
				{
					model.add(z[t][j][k]==0);
					model.add(y[t][j][k]==0);
					model.add(w[t][j][k]==0);
				}
			}
		}
 
 
		//SETTING Y VALUES
		if(originalproblem == 0)
		{
			for(t=0;t<T;t++)
				for(j=0;j<facilitynodes;j++)
					for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
						model.add(y[t][j][s]==initial_y[t+1][j][s]);
		}
 
 
//---------------------Constraint Definition Ends here-------------------------------------------------------
 
 
 
//---------------------Objective Function--------------------------------------------------------------------
		IloExpr obj(env);
	
		for(t=0;t<T;t++)
		{
			for(j=0;j<supplynodes+facilitynodes;j++)
			{
				for(k=0;k<facilitynodes;k++)
				{
					if(j<supplynodes)
						obj+=distancecounty[originalsupplycountyindex[j]][originalfacilitycountyindex[k]]*c_u*x[t][j][k]+c_o*x[t][j][k];
					else
						obj+=distancecounty[originalfacilitycountyindex[j-supplynodes]][originalfacilitycountyindex[k]]*c_u*x[t][j][k]+c_o*x[t][j][k];
				}
			}
			for(j=0;j<facilitynodes;j++)
			{
				for(k=0;k<nodes;k++)
				{
					obj+=distancecounty[originalfacilitycountyindex[j]][k]*c_individual*xx[t][j][k];
				}
			}
			for(j=0;j<facilitynodes;j++)
			{
				obj+=invholdingcost*inventory[t][j];
				for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				{
					obj+=fixedFacilityCost[originalfacilitycountyindex[j]][s]*y[t][j][s]+openFacilityCost[originalfacilitycountyindex[j]][s]*w[t][j][s]+closeFacilityCost[originalfacilitycountyindex[j]][s]*z[t][j][s];
				}
			}
		}
		
		model.add(IloMinimize(env, obj));		
//---------------------Objective Function Def ends here----------------------------------------------------------
 
 
	
//---------------------Solving the model-------------------------------------------------------------------------  
		//IloCplex cplex(env);
		//cplex.extract(model);
		IloCplex cplex(model);
		//cplex.exportModel("transport.lp");
		if(originalproblem == 0)
			cplex.setParam(IloCplex::EpGap, 0.01);
		else
			cplex.setParam(IloCplex::EpGap, 0.02);
 
		cplex.solve();
 
 
		
//----------------------Extracting results for output-------------------------------------------------------------
 
 
		for(t=0;t<T;t++)
			for(j=0;j<facilitynodes;j++)
				for(k=0;k<MaxNumberFacility;k++)
					y_values[t][j][k] = ceil(cplex.getValue(y[t][j][k])-0.01);
 
 
		for(t=0;t<T;t++)
			for(j=0;j<facilitynodes;j++)
				for(k=0;k<nodes;k++)
					xx_values[t][j][k] = cplex.getValue(xx[t][j][k]);
 
 
		totalcost = cplex.getObjValue(); 
 
//-----------------------------------Done----------------------------------------------------------------------------
 
 
	}
	catch (IloException& e) 
	{
		totalcost = -2.0;
		cerr << "Concert exception caught: " << e << endl;
 
    }
    catch (...) 
	{
		totalcost = -3.0;
		cerr << "Unknown exception caught" << endl;
    }
 
   env.end();
 
 
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/y_values.txt");
	inFile = fopen(filename, "a");
	for(jj=0;jj<facilitynodes;jj++)
		fprintf(inFile,"%d	", originalfacilitycountyindex[jj]+1);
	fprintf(inFile,"\n");
 
	for(tt=0;tt<periods;tt++)
	{	
		for(kk=0;kk<MaxNumberFacility2;kk++)
		{	for(jj=0;jj<facilitynodes;jj++)
				fprintf(inFile,"%f	", y_values[tt][jj][kk]);
			fprintf(inFile,"\n");
		}
		fprintf(inFile,"\n");
	}
	fclose (inFile);
 
	for(tt=0;tt<periods;tt++)
		for(jj=0;jj<facilitynodes;jj++)
			for(kk=0;kk<number_counties-1;kk++)
				if(distancecounty[originalfacilitycountyindex[jj]][kk]>30)
					totaldemand30 += xx_values[tt][jj][kk];
 
 
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/morethan30.txt");
	inFile = fopen(filename, "a");
	fprintf(inFile,"Total demand = %f\n", totaldemand);
	fprintf(inFile,"Total demand more than 30 miles= %f\n", totaldemand30);
	fclose (inFile);
 
 
	if(originalproblem == 0)
	{
		sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/optimizationresults.txt");
		inFile = fopen(filename, "a");
		fprintf(inFile,"Original cost with current simulation\n");
		fprintf(inFile,"%f\n", totalcost);
		fclose (inFile);
	}
	else
	{
		sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/optimizationresults.txt");
		inFile = fopen(filename, "a");
		fprintf(inFile,"Original cost with original simulation\n");
		fprintf(inFile,"%f\n", totalcost);
		fclose (inFile);
	}
 
	return 0;
}
 
 
 
 
 
int optimizeNetwork(int starttime){
 
	int numberFacility[number_counties-1];
	int periods;
	double totalcost=-1.0;
 
 
	cout<<"All files read!!"<<endl;
 
	int ii,jj,kk;
	periods = TforOpt-(int)(starttime/periodlength-optimizationstart);
 
	//To convert daily demand into weekly demand. We assume that the time interval for opt is 7 days
	for(ii=0;ii<number_counties-1;ii++){
		for(jj=0;jj<periods;jj++){
			demand[ii][jj]=0;
		}
	}
 
	for(jj=0;jj<number_counties-1;jj++)
	{
		ii=0;
		int periodTracker=0;
		while(periodTracker<periods)
		{
			for(kk=0;kk<gc_iNumRealizationsPerNetwork+additionalruns;kk++)
				demand[jj][periodTracker]+=dailyDemand[jj][ii][kk];
			ii++;
			if(ii!=0)
			{
				if(ii%periodlength==0)
					periodTracker++;
			}
		}
	}
 
 
  	for(jj=0;jj<number_counties-1;jj++)
		for(ii=0;ii<periods;ii++)
			demand[jj][ii]=demand[jj][ii]/(double)(gc_iNumRealizationsPerNetwork+additionalruns);
 
 
	for(ii=0;ii<number_counties-1;ii++)
	{
		numberFacility[ii]=0;
		for(jj=0;jj<MaxNumberFacility2;jj++)
			if(capacityFacility[ii][jj]>0)
				numberFacility[ii]++;
	}
 
	cout << starttime/periodlength << endl;
 
 
	cout<<"All set for CPLEX!!"<<endl;
 
 
	IloEnv env;
	try{
		IloModel model(env);
 
		IloNum c_u, c_r, c_o, c_individual, invholdingcost;
//		IloInt truckCapacity;
		IloInt nodes,T;
		int i,t,j,k,s;
		IloInt MaxNumberFacility;
 
		c_u = 1.0;
		c_r = 50.0;
		c_o = 0.5;
		c_individual = 2.0;
		invholdingcost = 0.3;
//		truckCapacity = 500;
//		T=3;
//		nodes = 4;
 
		T=TforOpt-(int)(starttime/periodlength-optimizationstart);
		nodes = number_counties-1;
		MaxNumberFacility=MaxNumberFacility2;
 
 
 
 
//---------------------Decision variable Definition Starts here---------------------------------------------
 
		D3Array y(env,T); 
		for(i=0;i<T;i++)
		{
			y[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++)
			{ 			
				y[i][j] = IloNumVarArray(env,MaxNumberFacility,0,1,ILOINT); 
			}
		}
 
		D3Array w(env,T); 
		for(i=0;i<T;i++)
		{
			w[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++)
			{ 			
				w[i][j] = IloNumVarArray(env,MaxNumberFacility,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		D3Array z(env,T+1); 
		for(i=0;i<T+1;i++)
		{
			z[i] = D2Array(env,facilitynodes);
			for(j=0;j<facilitynodes;j++)
			{ 			
				z[i][j] = IloNumVarArray(env,MaxNumberFacility,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		D3Array x(env,T); 
		for(i=0;i<T;i++)
		{
			x[i] = D2Array(env,supplynodes+facilitynodes);
	 		for(j=0;j<supplynodes+facilitynodes;j++)
			{
				x[i][j] = IloNumVarArray(env,facilitynodes,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		D3Array xx(env,T); 
		for(i=0;i<T;i++)
		{
			xx[i] = D2Array(env,facilitynodes);
	 		for(j=0;j<facilitynodes;j++)
			{
				xx[i][j] = IloNumVarArray(env,nodes,0,IloInfinity,ILOFLOAT); 
			}
		}
 
		
//		D3Array r(env,T); 
//		for(i=0;i<T;i++){
//			r[i] = D2Array(env,2*nodes);
//	 		for(j=0;j<2*nodes;j++){
//				r[i][j] = IloNumVarArray(env,nodes,0,IloInfinity,ILOINT); 
//			}
//		}
		
		D2Array inventory(env,T); 
		for(i=0;i<T;i++)
		{
			inventory[i] = IloNumVarArray(env,facilitynodes,0,IloInfinity,ILOFLOAT); 
		}
//---------------------Decision variable Definition Ends here-----------------------------------------------
 
 
 
 
//---------------------Constraint Definition Starts here----------------------------------------------------	
 
		//Supply Constraint
		for(t=0;t<T;t++)
		{
			for(j=0;j<supplynodes;j++)
			{	IloExpr v(env);
				for(k=0;k<facilitynodes;k++)
						v+=x[t][j][k];
				model.add(v<=supply[originalsupplycountyindex[j]]);
				v.end();
			}
		}
 
		//Demand Constraint
		for(t=0;t<T;t++)
		{
			for(k=0;k<nodes;k++)
			{
				IloExpr v(env);
				for(j=0;j<facilitynodes;j++)
					v+=xx[t][j][k];
				model.add(v>=demand[k][t]);
				v.end();
			}
		}
 
		//Capacity constraint for each facility
		for(t=0;t<T;t++)
		{
			for(k=0;k<facilitynodes;k++)
			{
				IloExpr v1(env);
				IloExpr v2(env);
				for(j=0;j<supplynodes+facilitynodes;j++)
					v1+=x[t][j][k];
 
				for(s=0;s<numberFacility[originalfacilitycountyindex[k]];s++)
					v2+=capacityFacility[originalfacilitycountyindex[k]][s]*y[t][k][s];
 
				if(t==0)
					model.add(initial_inventory[k]+v1<=v2);
				else
					model.add(inventory[t-1][k]+v1<=v2);
				v1.end();
				v2.end();
			}
		}
 
		
		//Flow balance constraint
		for(t=0;t<T;t++)
		{
			for(k=0;k<facilitynodes;k++)
			{
				IloExpr v1(env);
				IloExpr v2(env);
				for(j=0;j<supplynodes+facilitynodes;j++)
					v1+=x[t][j][k];
 
				for(j=0;j<facilitynodes;j++)
					v2+=x[t][k+supplynodes][j];
 
				for(j=0;j<nodes;j++)
					v2+=xx[t][k][j];
 
				if(t==0)
					model.add(initial_inventory[k]+v1-inventory[t][k]-v2==0);
				else
					model.add(inventory[t-1][k]+v1-inventory[t][k]-v2==0);
				v1.end();
				v2.end();
			}
		}
 
		
		//No of Trucks constraint
//		for(t=0;t<T;t++){
//			for(j=0;j<2*nodes;j++){
//				for(k=0;k<nodes;k++){
//					if(j<nodes)
//					{	
//						if(supply[j]>0 && numberFacility[k]>0)
//						if(supply[j]>0 && numberFacility[k]>0)
//							model.add(x[t][j][k]-truckCapacity*r[t][j][k]<=0);
//					}
//					else
//					{	if(numberFacility[j-nodes]>0 && numberFacility[k]>0)
//							model.add(x[t][j][k]-truckCapacity*r[t][j][k]<=0);
//					}
//				}
//			}
//		}
 
		//Facility open constraint
		for(t=0;t<T;t++)
		{
			for(j=0;j<facilitynodes;j++)
			{	
				for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				{
					if(t==0)
						model.add(w[t][j][s]-y[t][j][s]+initial_y[t+(int)(starttime/periodlength-optimizationstart)][j][s]>=0);
					else
						model.add(w[t][j][s]-y[t][j][s]+y[t-1][j][s]>=0);
				}
			}
		}
 
		//Facility close constraint
		for(t=0;t<T+1;t++)
		{
			for(j=0;j<facilitynodes;j++)
			{
				for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				{
					if(t==T)
						model.add(z[t][j][s]-y[t-1][j][s]>=0);
					else if(t>0)
						model.add(z[t][j][s]-y[t-1][j][s]+y[t][j][s]>=0);
					else
						model.add(z[t][j][s]-initial_y[t+(int)(starttime/periodlength-optimizationstart)][j][s]+y[t][j][s]>=0);
				}
			}
		}
 
		//Final Inventory should be zero
		for(j=0;j<facilitynodes;j++)
		{
				model.add(inventory[T-1][j]==0);
		}
 
		//Additional Value Setting
		//If you don't use this you'll get an IloExtractable exception as values for these indices are not defined
		//anywhere else in the problem.
 
		for(t=0;t<T+1;t++)
			for(j=0;j<facilitynodes;j++)
				for(k=numberFacility[originalfacilitycountyindex[j]];k<MaxNumberFacility;k++)
					model.add(z[t][j][k]==0);
 
		for(t=0;t<T;t++)
		{
			for(j=0;j<facilitynodes;j++)
			{
				for(k=numberFacility[originalfacilitycountyindex[j]];k<MaxNumberFacility;k++)
				{
					model.add(y[t][j][k]==0);
					model.add(w[t][j][k]==0);
				}
			}
		}
 
 
//---------------------Constraint Definition Ends here-------------------------------------------------------
 
 
//---------------------Objective Function--------------------------------------------------------------------
		IloExpr obj(env);
		
		for(t=0;t<T;t++)
		{
			for(j=0;j<supplynodes+facilitynodes;j++)
			{
				for(k=0;k<facilitynodes;k++)
				{
					if(j<supplynodes)
						obj+=distancecounty[originalsupplycountyindex[j]][originalfacilitycountyindex[k]]*c_u*x[t][j][k]+c_o*x[t][j][k];
					else
						obj+=distancecounty[originalfacilitycountyindex[j-supplynodes]][originalfacilitycountyindex[k]]*c_u*x[t][j][k]+c_o*x[t][j][k];
				}
			}
			for(j=0;j<facilitynodes;j++)
			{
				for(k=0;k<nodes;k++)
				{
					obj+=distancecounty[originalfacilitycountyindex[j]][k]*c_individual*xx[t][j][k];
				}
			}
			for(j=0;j<facilitynodes;j++)
			{
				obj+=invholdingcost*inventory[t][j];
				for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				{
					obj+=fixedFacilityCost[originalfacilitycountyindex[j]][s]*y[t][j][s]+openFacilityCost[originalfacilitycountyindex[j]][s]*w[t][j][s]+closeFacilityCost[originalfacilitycountyindex[j]][s]*z[t][j][s];
				}
			}
		}
 
		for(j=0;j<facilitynodes;j++)
			for(s=0;s<numberFacility[originalfacilitycountyindex[j]];s++)
				obj+=closeFacilityCost[originalfacilitycountyindex[j]][s]*z[T][j][s];
 
		
		model.add(IloMinimize(env, obj));		
//---------------------Objective Function Def ends here----------------------------------------------------------
 
 
	
//---------------------Solving the model-------------------------------------------------------------------------  
		//IloCplex cplex(env);
		//cplex.extract(model);
		IloCplex cplex(model);
		//cplex.exportModel("transport.lp");
		//SETTING THE OPTIMALITY GAP
		cplex.setParam(IloCplex::EpGap, 0.10);
 
		cplex.solve();
 
 
		for(j=0;j<facilitynodes;j++)
			initial_inventory[j] = cplex.getValue(inventory[0][j]);
 
		for(j=0;j<facilitynodes;j++)
			for(k=0;k<numberFacility[originalfacilitycountyindex[j]];k++)
				initial_y[(int)(starttime/periodlength-optimizationstart)+1][j][k] = (int)(ceil(cplex.getValue(y[0][j][k])-0.01));
 
		if(starttime/periodlength-optimizationstart==0)
			for(i=1;i<TforOpt+1;i++)
				for(j=0;j<facilitynodes;j++)
					for(k=0;k<numberFacility[originalfacilitycountyindex[j]];k++)
						initial_y[i][j][k] = (int)(ceil(cplex.getValue(y[i-1][j][k])-0.01));
			
		
//----------------------Extracting results for output-------------------------------------------------------------
 
		totalcost = cplex.getObjValue();
 
//-----------------------------------Done----------------------------------------------------------------------------
 
 
	}
	catch (IloException& e) 
	{
		totalcost = -2.0;
		cerr << "Concert exception caught: " << e << endl;
    }
    catch (...) 
	{
		totalcost = -3.0;
		cerr << "Unknown exception caught" << endl;
    }
   env.end();
 
	char filename[100];
	FILE *inFile;
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/optimizationresults.txt");
	inFile = fopen(filename, "a");
	fprintf(inFile,"Total cost for the remaining days at day %d\n", starttime);
	fprintf(inFile,"%f\n", totalcost);
	fclose (inFile);
 
	if(starttime/periodlength-optimizationstart==0)
		finaloptimization(0);
 
	return 0;
}
*/
 
 
 
int setinitialconditions(int day)
{
 
	int iCounter,iCounter2,iCounter5, iCounter3, iCounter4, chosen;
	int selectedindividual;
 
	char filename[100];
	FILE *inFile;
 
	sprintf(filename, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/dailyresults%0.3d.txt",day);
	inFile = fopen(filename, "r");
 
 
	for(iCounter5 = 0; iCounter5 < number_counties; iCounter5++)
	{
		for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
		{
			fscanf(inFile, "%d	", &initialstatus[iCounter][iCounter5]);
		}
		fscanf(inFile,"\n");
	}
	fclose(inFile);
 
 
	for(iCounter=0;iCounter<number_counties;iCounter++)
	{
		for(iCounter2=1;iCounter2<NUM_DISEASE_STAGES;iCounter2++)
		{
			iCounter5=0;
			while(iCounter5<initialstatus[iCounter2][iCounter])
			{
				chosen = DiscreteUniformDeviate(0, g_iHeadCount[SUSCEPTIBLE][0][0][0][iCounter]-1);
				iCounter4=0;
				if(iCounter==0)
					iCounter3=0;
				else
					iCounter3=subtotal[iCounter-1];
 
				do
				{
					if(g_cIndividual[iCounter3].GetDiseaseStatus()==SUSCEPTIBLE)
						iCounter4++;
					iCounter3++;
				}while(iCounter4<=chosen);
				selectedindividual = iCounter3-1;
 
				if(iCounter2==1)
				{
					g_cIndividual[selectedindividual].DiseaseProgression();
				}
				else if(iCounter2==2)
				{
					g_cIndividual[selectedindividual].SusceptibleToPresymptomatic2();
				}
				else if(iCounter2==3)
				{
					g_cIndividual[selectedindividual].SusceptibleToAsymptomatic2();
				}
				else if(iCounter2==4)
				{
					g_cIndividual[selectedindividual].SusceptibleToSymptomatic2();
				}
				else if(iCounter2==5)
				{
					g_cIndividual[selectedindividual].SusceptibleToRecovered2();
				}
				else if(iCounter2==6)
				{
					g_cIndividual[selectedindividual].SusceptibleToHospitalized2();
				}
				else if(iCounter2==7)
				{
					g_cIndividual[selectedindividual].SusceptibleToDead2();
				}
				else
				{
					cout << "Unknown disease stage: " << iCounter2 << endl;
					Pause();
					exit(0);
				}
 
				iCounter5++;
			}
			if(iCounter5 != initialstatus[iCounter2][iCounter])
			{
				cout << iCounter5 << "  " << initialstatus[iCounter2][iCounter] << endl;
				Pause();
				exit(0);
			}
		}
	}
 
	for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
	{
		g_cHousehold[iCounter].ComputeInfectivity();
		g_cHousehold[iCounter].ComputeSusceptibility();
	}
	for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
	{
		g_cPeerGroup[iCounter].ComputeInfectivity();
		g_cPeerGroup[iCounter].ComputeSusceptibility();
	}	
 
	RefreshFOI();
 
	return 0;
}
 
 
int main(int argc, char *argv[])
{   
 
	char *cBuffer;
	int i, j, k, control = 0;
	double initialtime;
	int periodcounter, iChosenID;
	
	double g_dTime_Previous;
	double TotalNonClose, temp1;
	int iCounter, iRealizationCounter = 0, iNetworkCounter, iPolicyCounter;
	int iCounter2, iCounter3, iCounter4, iCounter5, count, counter;
 
	for(iCounter2=0;iCounter2<number_counties-1;iCounter2++)
	{
		initial_inventory[iCounter2]=0.0;
		for(iCounter=0;iCounter<(int)(maxNumOfDaysForOpt/periodlength)+1;iCounter++)
			for(iCounter3=0;iCounter3<MaxNumberFacility2;iCounter3++)
				initial_y[iCounter][iCounter2][iCounter3]=0;
	}
 
	readdata();
	workflowdata();
 
 
for(i=0;i<number_counties-1;i++)
	gc_iPopulationSize[i]=gc_iPopulationSize[i]/10;
 
gc_iPopulationSizeTotal = 0;
for(i=0;i<number_counties;i++)
	gc_iPopulationSizeTotal += gc_iPopulationSize[i];
 
cout << "TotalPop =" << gc_iPopulationSizeTotal << endl;
 
 
	if (argc == 3)
	{
		g_iParameterSetIndexStart = static_cast<int>(strtod(argv[1], &cBuffer)+0.5);
		g_iParameterSetIndexEnd = static_cast<int>(strtod(argv[2], &cBuffer)+0.5);
	}
	else if (argc!=1)
	{
		cout << "Wrong number of arguments!  Program terminated." << endl;
		Pause();
		exit(0);
	}
 
	g_iSeed = static_cast<int>(time(NULL));
	nag_random_init_repeatable(g_iSeed);
 
	cout << "Allocating memory for objects... " << endl;	
	g_pEventList = new priority_queue<CEventListRecord>*[gc_iNumEventLists];
	for (iCounter = 0; iCounter < gc_iNumEventLists; ++iCounter)
		g_pEventList[iCounter] = NULL;
 
	for (iCounter = 0; iCounter < 2; ++iCounter)
	{
		g_cFOIEngine[iCounter] = new CMySet<CFOIEngineElement, unsigned int>[gc_iNumEngineSlots];
		g_cEmptyFOIEngineSlot[iCounter] = new CMySet<int, unsigned int>[gc_iNumEngineSlots];
		g_cFOIPerturbedList[iCounter] = new CMySet<CFOIPerturbedListElement, unsigned int>[gc_iNumEngineSlots];
		g_dFOI[iCounter] = new double[gc_iNumEngineSlots];
	}
 
	cout << "Allocating memory for Individuals... " << endl;
	g_cIndividual = new CIndividual[gc_iPopulationSizeTotal]; 
	for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
		g_cIndividual[iCounter].Initialize(iCounter);
 
 
	char cBuffer2[100], cABCD[] = {"abcd"};
	for (g_iParameterSetIndex = g_iParameterSetIndexStart; g_iParameterSetIndex <= g_iParameterSetIndexEnd; ++g_iParameterSetIndex)
	{ 
		g_tClockStart = time(NULL);
#ifdef READ_PARAMETERS
		ReadParameters(g_iParameterSetIndex);
		sprintf(cBuffer2, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/ParametersBefore%d.txt", g_iParameterSetIndex);
		ifstream ifp;
		ifp.open(cBuffer2);
		if (ifp.is_open())
			continue;
#endif
		iRealizationCounter = 0;
//		PrintParameters(true);
#ifdef CHECK_TARGETS
		char cBuffer3[1000];
		sprintf(cBuffer3, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/Targets%d.txt", g_iParameterSetIndex);
		ofstream Tout(cBuffer3);
		//ofstream Tout("Targets.txt");
		Tout.close();
#endif
#ifdef PRINT_STATS
		for (iCounter = 0; iCounter < gc_iNumStat; ++iCounter)
		{
			sprintf(cBuffer2, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/Stat%d%c.txt", g_iParameterSetIndex, cABCD[iCounter]);
			g_ofStat[iCounter].open(cBuffer2);
		}
#endif
#ifdef PRINT_TIME_SERIES
		for (iCounter = 0; iCounter < gc_iNumTimeSeries; ++iCounter)
		{
			sprintf(cBuffer2, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/TimeSeries%d%c.txt", g_iParameterSetIndex, cABCD[iCounter]);
			g_ofTimeSeries[iCounter].open(cBuffer2);
		}
#endif
 
		g_iSeed = DiscreteUniformDeviate(1000000000, 2000000000);
		nag_random_init_repeatable(g_iSeed);
 
 
//		BuildNetwork();
//		for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
//			g_cIndividual[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
//			g_cHousehold[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
//			g_cPeerGroup[iCounter].Reset(iCounter);
//		ResetConditions();
//		BuildNetwork();
//		for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
//			g_cIndividual[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
//			g_cHousehold[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
//			g_cPeerGroup[iCounter].Reset(iCounter);
//		ResetConditions();
//		BuildNetwork();
//		for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
//			g_cIndividual[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
//			g_cHousehold[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
//			g_cPeerGroup[iCounter].Reset(iCounter);
//		ResetConditions();
//		BuildNetwork();
//		for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
//			g_cIndividual[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
//			g_cHousehold[iCounter].Reset(iCounter);
//		for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
//			g_cPeerGroup[iCounter].Reset(iCounter);
//		ResetConditions();
 
 
		while (iRealizationCounter < gc_iNumRealizations*gc_iNumPolicies)
		{
 
for(counter=0;counter<5;counter++)
{
 
			g_iSeed = DiscreteUniformDeviate(1000000000, 2000000000);
			nag_random_init_repeatable(g_iSeed);
 
 
			BuildNetwork();
 
 
//			for(periodcounter=0;periodcounter<TforOpt;periodcounter++)
			for(periodcounter=0;periodcounter<1;periodcounter++)
			{
 
				if(periodcounter == 0)
					additionalruns = ExtraRuns;
				else
					additionalruns = 0;
 
 
				//Initializing daily demand
				for(i=0;i<number_counties-1;i++)
					for(j=0;j<maxNumOfDaysForOpt;j++)
						for(k=0;k<gc_iNumRealizationsPerNetwork+additionalruns;k++)
							dailyDemand[i][j][k]=0;
				
 
				for (iNetworkCounter = 0; iNetworkCounter < gc_iNumRealizationsPerNetwork+additionalruns; ++iNetworkCounter)
				{
					for (iPolicyCounter = 0; iPolicyCounter < gc_iNumPolicies; ++iPolicyCounter)
					{
 
#ifdef DISPLAY		
						g_tClockStart2 = time(NULL);
						if (iRealizationCounter > 1)
							cout << endl << "Estimated remaining run-time for this parameter set = " << static_cast<double>(time(NULL)-g_tClockStart)/iRealizationCounter*(gc_iNumPolicies*gc_iNumRealizations-iRealizationCounter)/60 << " minutes." << endl;
#endif
 
						ActivatePolicy(gc_iPolicySet[iPolicyCounter]);
 
//						initialtime = (periodcounter+optimizationstart)*periodlength;
						initialtime = 0.0;
						gc_dTimeMax = gc_dTimeMax1 - initialtime;
						ResetConditions();
						g_dTime_Previous = 0.0;
 
						control = 0;
 
						g_iHeadCountTotal[EXPOSED][0][0][0]=0;
						for (iCounter=0;iCounter<number_counties;++iCounter)
							g_iHeadCountTotal[EXPOSED][0][0][0] += g_iHeadCount[EXPOSED][0][0][0][iCounter];
/*
						if(periodcounter>=0)
						{
							cout << "INITIAL SETTING" << endl;
							setinitialconditions((int)(initialtime));
							DisplayProgress((int)initialtime);
						}
*/						
 
						if(periodcounter==0)
						{
							while (g_iHeadCountTotal[EXPOSED][0][0][0] < gc_iInitialNumSeeds)
							{
								iChosenID = DiscreteUniformDeviate(0, gc_iPopulationSizeTotal-1);
 
								if ((g_cIndividual[iChosenID].GetDiseaseStatus() == SUSCEPTIBLE))
								{	
									g_iSelectedSeed = iChosenID;
									g_cIndividual[iChosenID].DiseaseProgression();
								}
 
								g_iHeadCountTotal[EXPOSED][0][0][0]=0;
								for (iCounter=0;iCounter<number_counties;++iCounter)
									g_iHeadCountTotal[EXPOSED][0][0][0] += g_iHeadCount[EXPOSED][0][0][0][iCounter];
							}
						}
 
						while (g_dTime < gc_dTimeMax)
						{                 
#ifdef TESTING
							if (g_bTestingActive == true && g_bStopTesting == true && g_dTime > g_dTimeResumeTesting 
								&& g_iNumActiveTestServers < (gc_iMaxNumTestServers-10))
							{
								/*if (g_bTracingActive == true)
									ActivatePolicy(QIATC);
								else
									ActivatePolicy(QIAT);*/
								g_bStopTesting = false;
								g_dTimeResumeTesting = LARGE_NUMBER;
							}
#endif
						
							// ***************** Time Until Next Infection ********************
							g_dTotalCloseFOI = g_dTotalFOI[HOUSEHOLD]+g_dTotalFOI[PEERGROUP];
							if (g_dTotalCloseFOI > gc_dSmallestFOI)
								g_dTimeToCloseInfection = g_dTime+ExponentialDeviate(1.0/g_dTotalCloseFOI);
							else 
								g_dTimeToCloseInfection = LARGE_NUMBER;
 
							/* NIGHT DAY DIFFERENTIATION */
							if((int)floor(g_dTime/0.5)%2 == 0)
							{
								if (g_dTotalFOI[HOUSEHOLD] > gc_dSmallestFOI)
								{	
									g_dTimeToCloseInfection = g_dTime+ExponentialDeviate(1.0/g_dTotalFOI[HOUSEHOLD]);
									selected_group = HOUSEHOLD;
								}
								else 
									g_dTimeToCloseInfection = LARGE_NUMBER;
							}
							else
							{
								if (g_dTotalFOI[PEERGROUP] > gc_dSmallestFOI)
								{	
									g_dTimeToCloseInfection = g_dTime+ExponentialDeviate(1.0/g_dTotalFOI[PEERGROUP]);
									selected_group = PEERGROUP;
								}
								else 
									g_dTimeToCloseInfection = LARGE_NUMBER;
							}
 
 
							//**************** Time Until Next Import or Spam or Random Transmission
							for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
							{
								for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
									for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
										for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
										{	
											g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] = 0;
											for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
												g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
										}
							}
 
							g_dFOICommunityTotal = 0.0;
							g_dFOIIsolationTotal = 0.0;
							for(count=0;count<number_counties;count++)
							{
								g_dFOICommunity[count] = g_dBeta*g_dInfHazardCommunity[count]*(g_iHeadCount[SUSCEPTIBLE][0][0][0][count]+g_iHeadCount[SUSCEPTIBLE][1][0][0][count])*
									((g_iHeadCount[SYMPTOMATIC][0][0][0][count]+g_iHeadCount[SYMPTOMATIC][1][0][0][count])+
									g_dInfHazardPresym*(g_iHeadCount[PRESYMPTOMATIC][0][0][0][count]+g_iHeadCount[PRESYMPTOMATIC][1][0][0][count])+
									g_dInfHazardAsym*(g_iHeadCount[ASYMPTOMATIC][0][0][0][count]+g_iHeadCount[ASYMPTOMATIC][1][0][0][count]));
					
								g_dFOICommunityTotal += g_dFOICommunity[count];
//ISOLATION SEPARATED
								g_dFOIIsolation[count] = g_dBetaIsolation*gc_dInfHazardDrug*gc_dSusHazardDrug*g_iHeadCount[SUSCEPTIBLE][0][0][1][count]*(g_iHeadCount[SYMPTOMATIC][0][0][1][count]+
									g_dInfHazardPresym*g_iHeadCount[PRESYMPTOMATIC][0][0][1][count]+g_dInfHazardAsym*g_iHeadCount[ASYMPTOMATIC][0][0][1][count])/
									MAX(1, g_iCountyNumIsolated[count]);	
							
								g_dFOIIsolationTotal += g_dFOIIsolation[count];
							}
 
							if (MIN(g_dFOIIsolationTotal, g_dFOICommunityTotal) < -gc_dSmallestFOI)
							{
								cout << "Negative g_dFOICommunity or g_dFOIIsolation!" << endl;
								Pause();
							}
 
 
							for(count=0;count<number_counties;count++)
							{
								g_dFOIImport[count] = g_dImportRate[count]*(g_iHeadCount[SUSCEPTIBLE][0][0][0][count]+g_iHeadCount[SUSCEPTIBLE][1][0][0][count]);
								g_dFOINonCloseAndSpam[count] = g_dFOICommunity[count]+g_dFOIImport[count]+g_dFOIIsolation[count];
							}
	
							for(count=0;count<number_counties;count++)
							{	if (g_iPolicy != NONE)
#ifdef LOW_SPAM
									g_dFOINonCloseAndSpam[count] += gc_dSpamRate*(g_iHeadCount[SUSCEPTIBLE][0][0][0][count]+g_iHeadCount[SUSCEPTIBLE][1][0][0][count]);
#else
									g_dFOINonCloseAndSpam[count] += gc_dSpamRate*(g_iHeadCount[SUSCEPTIBLE][0][0][0][count]+g_iHeadCount[SUSCEPTIBLE][1][0][0][count]+
									g_iHeadCount[RECOVERED][0][0][0][count]+g_iHeadCount[RECOVERED][1][0][0][count]);
#endif
							}
			
 
							g_dTimeToNonCloseInfectionAndSpamMin = LARGE_NUMBER;
							SelectedCounty = 0;
							for(count=0;count<number_counties;count++)
							{
								if (g_dFOINonCloseAndSpam[count] > 1e-5)
									g_dTimeToNonCloseInfectionAndSpam[count] = g_dTime+ExponentialDeviate(1.0/g_dFOINonCloseAndSpam[count]);
								else
									g_dTimeToNonCloseInfectionAndSpam[count] = LARGE_NUMBER;
 
								if(g_dTimeToNonCloseInfectionAndSpamMin > g_dTimeToNonCloseInfectionAndSpam[count])
								{
									g_dTimeToNonCloseInfectionAndSpamMin = g_dTimeToNonCloseInfectionAndSpam[count];
									SelectedCounty = count;
								}
							}
 
 
							TotalNonClose = 0.0;
							for(count=0;count<number_counties;count++)
								TotalNonClose += g_dFOINonCloseAndSpam[count];
 
							tempor = Probability()*TotalNonClose;
							temp1 = 0.0;
							count = 0;
 
							do
							{
								temp1 += g_dFOINonCloseAndSpam[count];
								count++;
							}while(temp1 < tempor);
 
							SelectedCounty = count-1;
							g_dTimeToNonCloseInfectionAndSpamMin = g_dTime+ExponentialDeviate(1.0/TotalNonClose);
 
 
							// *************** Time Until Next Event on the EventList ***************
							if (g_iCurrentEventList < gc_iNumEventLists && (*(g_pEventList[g_iCurrentEventList])).empty() == false)
								g_dTimeToEventOnList = ((*(g_pEventList[g_iCurrentEventList])).top()).GetTime();
							else
								g_dTimeToEventOnList = LARGE_NUMBER;
 
							// ************* Pick the next job
							if (g_dTimeToCloseInfection < g_dTimeToEventOnList && g_dTimeToCloseInfection < g_dTimeToNonCloseInfectionAndSpamMin)
							{
								if (g_dTimeToCloseInfection < gc_dTimeMax)
								{
									g_dTime_Previous = g_dTime;
									g_dTime = g_dTimeToCloseInfection;
									//	cout << "Infection: " << endl;
									ProcessCloseInfection();
								}
								else
								{	g_dTime_Previous = g_dTime;
									g_dTime = gc_dTimeMax;
								}
							}
							else if (g_dTimeToEventOnList < g_dTimeToNonCloseInfectionAndSpamMin)
							{
								if (g_dTimeToEventOnList < gc_dTimeMax)
								{
									g_dTime_Previous = g_dTime;
									g_dTime = g_dTimeToEventOnList;
									ProcessEventOnList();
								}
								else
								{	g_dTime_Previous = g_dTime;
									g_dTime = gc_dTimeMax;
								}
							}
							else 
							{
								if (g_dTimeToNonCloseInfectionAndSpamMin < gc_dTimeMax)
								{
									//	cout << "ImportSpam" << endl;
									g_dTime_Previous = g_dTime;
									g_dTime = g_dTimeToNonCloseInfectionAndSpamMin;
									ProcessNonCloseInfectionAndSpam();
								}
								else
								{	g_dTime_Previous = g_dTime;
									g_dTime = gc_dTimeMax;
								}
							}
 
							if (g_dTimeToEventOnList > gc_dTimeMax && g_dTimeToNonCloseInfectionAndSpamMin > gc_dTimeMax &&
								g_dTimeToNonCloseInfectionAndSpamMin > gc_dTimeMax)
								g_dTime = gc_dTimeMax;
 
//							if (g_iNumFOIUpdates > 10e3)
//							{
//								RefreshFOI();
//								g_iNumFOIUpdates = 0;
//							}
 
 
							if((int)ceil((double)g_dTime_Previous /(double)1) != (int)ceil((double)g_dTime /(double)1) && g_dTime_Previous > 0)
							{								
								temp = (int)ceil(g_dTime_Previous)-1;
								for (iCounter2 = 0; iCounter2 < number_counties-1; ++iCounter2)
								{
									for (iCounter3 = subtotalhouse[iCounter2]-iHouseholdCounter[iCounter2]; iCounter3 < subtotalhouse[iCounter2]; ++iCounter3)
									{
										familysize = g_cHousehold[iCounter3].GetHouseholdSize();
										for(iCounter4=0; iCounter4<familysize ;iCounter4++)
										{										
											if((g_cIndividual[g_cHousehold[iCounter3].GetMemberList()[iCounter4]].GetDiseaseStatus()==SYMPTOMATIC)/*||(g_cIndividual[g_cHousehold[iCounter3].GetMemberList()[iCounter4]].GetDiseaseStatus()==ASYMPTOMATIC)*/)
											{
												iCounter4=familysize;
												dailyDemand[iCounter2][temp][iNetworkCounter] += 3*g_cHousehold[iCounter3].GetActiveHouseholdSize();
											}
										}
									}
								}
							}
 
 
 
							if((int)ceil((double)g_dTime_Previous /(double)1) != (int)ceil((double)g_dTime /(double)1) && g_dTime_Previous > 0)
								DisplayProgress((int)initialtime);
 
 
//CLOSING SCHOOLS
/*
							if ((g_dTime > 7) && (control == 0))
							{	control = 1;
								for(i=0;i<gc_iPopulationSizeTotal;i++)
									if(g_cIndividual[i].GetAdultStatus()==false)
										g_cIndividual[i].SetPeerGroupActive(false);
							}
*/
 
 
#ifdef TESTING
							if (g_bTestingActive == true && g_bStopTesting == false && g_iNumActiveTestServers > (gc_iMaxNumTestServers-10))
							{
								g_dTimeResumeTesting = g_dTime+0.5;
								g_bStopTesting = true;
							/*	if (g_iPolicy == QIAT)
									ActivatePolicy(QIA);
								else if (g_iPolicy == QIATC)
									ActivatePolicy(QIAC);*/
							}
#endif
 
							for (iCounter = 0; iCounter < NUM_DISEASE_STAGES; ++iCounter)
							{
								for (iCounter2 = 0; iCounter2 < 2; ++iCounter2)
									for (iCounter3 = 0; iCounter3 < 2; ++iCounter3)		
										for (iCounter4 = 0; iCounter4 < 2; ++iCounter4)
										{	g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] = 0;
											for (iCounter5 = 0; iCounter5 < number_counties; ++iCounter5)
												g_iHeadCountTotal[iCounter][iCounter2][iCounter3][iCounter4] += g_iHeadCount[iCounter][iCounter2][iCounter3][iCounter4][iCounter5];
										}
							}
 
 
							g_iDisruptiveness = g_iHeadCountTotal[DEAD][0][0][0]+g_iNumQuarantined+g_iNumIsolated;
							g_iMaxDisruptiveness = MAX(g_iMaxDisruptiveness, g_iDisruptiveness);
							g_iMaxNumHospitalized = MAX(g_iMaxNumHospitalized, g_iHeadCountTotal[HOSPITALIZED][0][0][1]);
							g_iMaxNumQuarantined = MAX(g_iMaxNumQuarantined, g_iNumQuarantined);
							g_iMaxNumHouseholdsQuarantined = MAX(g_iMaxNumHouseholdsQuarantined, g_iNumHouseholdsQuarantined);
							g_iMaxNumIsolated = MAX(g_iMaxNumIsolated, g_iNumIsolated);
							g_dOldTime = g_dTime;
							g_iOldNumQuarantined = g_iNumQuarantined;
							g_iOldNumIsolated = g_iNumIsolated;
 
							if (g_dOldTime > g_dTime || g_dTotalFOI[HOUSEHOLD] < -gc_dSmallestFOI || g_dTotalFOI[PEERGROUP] < -gc_dSmallestFOI)
							{
								cout << "Policy: " << g_sPolicyString[g_iPolicy] << endl;
								cout << "g_dOldTime = " << g_dOldTime << ", g_dTime = " << g_dTime << endl;
								cout <<  "g_dTotalFOI[HOUSEHOLD] = " << g_dTotalFOI[HOUSEHOLD] << ", g_dTotalFOI[PEERGROUP] = " << g_dTotalFOI[PEERGROUP] << endl;
								RefreshFOI();
							}
 
 
							if (g_dTime > g_iPrintCounter*gc_iPrintInterval)
							{
								g_iMaxInfectionIncidence = MAX(g_iInfectionIncidence, g_iMaxInfectionIncidence);
								g_iMaxQuarantineIncidence = MAX(g_iQuarantineIncidence, g_iMaxQuarantineIncidence);
								g_iMaxIsolationIncidence = MAX(g_iIsolationIncidence, g_iMaxIsolationIncidence);
								g_dTotalDrugUsedQuarantineSymp += g_dDailyDrugUsedQuarantineSymp;
								g_dTotalDrugUsedQuarantineNonSymp += g_dDailyDrugUsedQuarantineNonSymp;
								g_dTotalDrugUsedQuarantineNonComp += g_dDailyDrugUsedQuarantineNonComp;
								g_dTotalDrugUsedIsolation += g_dDailyDrugUsedIsolation;
								g_iTotalNumQuarantineReleased += g_iDailyNumQuarantineReleased;
								g_iTotalNumHouseholdsQuarantineReleased += g_iDailyNumHouseholdsQuarantineReleased;
								g_iTotalNumIsolationReleased += g_iDailyNumIsolationReleased;
#ifdef PRINT_TIME_SERIES                        
								PrintTimeSeries(iNetworkCounter+iPolicyCounter);
#endif
								g_iInfectionIncidence = 0;
								g_iQuarantineIncidence = 0;
								g_iIsolationIncidence = 0;
								g_dDailyDrugUsedQuarantineSymp = 0;
								g_dDailyDrugUsedQuarantineNonSymp = 0;
								g_dDailyDrugUsedQuarantineNonComp = 0;
								g_dDailyDrugUsedIsolation = 0;
								g_iDailyLeakage = 0;
								g_iDailyNumHouseholdsQuarantineReleased = 0;
								g_iDailyNumQuarantineReleased = 0;
								g_iDailyNumIsolationReleased = 0;
								++g_iPrintCounter;
							}
 
#ifdef PRINT_STATS
							if (g_iThresholdCounter < gc_iNumAttackRateThresholds &&
								(gc_iPopulationSizeTotal-ComputeNumSusceptible()) > gc_dAttackRateThreshold[g_iThresholdCounter]*gc_iPopulationSizeTotal)
							{
								g_dAttackRateThresholdHittingTime[g_iThresholdCounter] = g_dTime;
								++g_iThresholdCounter;
							}
#endif
						}	
//END OF SIMULATION (INNER WHILE LOOP)
 
#ifdef CHECK_TARGETS
						char cBuffer3[1000];
						sprintf(cBuffer3, "C:/Users/Daniel Park/Documents/Visual Studio 2008/Projects/Measles Simulation/spread_code_census_tract/Targets%d.txt", g_iParameterSetIndex);
						ofstream Tout(cBuffer3, ios::app);
						//ofstream Tout("Targets.txt", ios::app);
						for (iCounter = 0; iCounter < 3; ++iCounter)
							for (int iCounter2 = 0; iCounter2 < 3; ++iCounter2)
								Tout << g_iNumInfecteesBySeed[iCounter][iCounter2] << " ";
						Tout << g_cIndividual[g_iSelectedSeed].GetWillBeSymptomatic() << " " << g_dTg << endl;
						Tout.close();
#endif
#ifdef PRINT_TIME_SERIES    
						while (g_iPrintCounter*gc_iPrintInterval < gc_dTimeMax)
						{
							PrintTimeSeries(1);          
							++g_iPrintCounter;
						}
#endif
#ifdef DISPLAY
						DisplayProgress((int)initialtime);
#endif
 
//						PrintParameters(false);
#ifdef PRINT_STATS
						PrintStats(g_iParameterSetIndex);
#endif
 
						for (iCounter = 0; iCounter < gc_iPopulationSizeTotal; ++iCounter)
							g_cIndividual[iCounter].Reset(iCounter);
						for (iCounter = 0; iCounter < g_iNumGroups[HOUSEHOLD]; ++iCounter)
							g_cHousehold[iCounter].Reset(iCounter);
						for (iCounter = 0; iCounter < g_iNumGroups[PEERGROUP]; ++iCounter)
							g_cPeerGroup[iCounter].Reset(iCounter);
					}
				}
 
				//CALL FOR OPTIMIZATION
//				optimizeNetwork((int)(initialtime));
 
			}
 
//			finaloptimization(0);
//			finaloptimization(1);
 
}
//OUTER FOR LOOP
			
			++iRealizationCounter;
		}
 
#ifdef PRINT_STATS
		for (iCounter = 0; iCounter < gc_iNumStat; ++iCounter)
			g_ofStat[iCounter].close();
#endif
#ifdef PRINT_TIME_SERIES
		for (iCounter = 0; iCounter < gc_iNumTimeSeries; ++iCounter)
			g_ofTimeSeries[iCounter].close();
#endif
	}
 
 
	cout << "Simulation Finished." << endl;
 
 
 
#ifdef DISPLAY
	Pause();
#endif
	return 0;
};

Open in new window

0
 

Author Comment

by:ltdanp22
ID: 22736931
#include <ctime>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <queue>
#include <algorithm>
#include <string>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <windows.h>//DP2
#include <vector>//DP2
#include <time.h>//DP2
using namespace std;
/*
#include <nag.h>//DP2
#include <stdio.h>
#include <nag_stdlib.h>
#include <nagg05.h>
*/
#include <stdlib.h>
//#include <ilcplex/ilocplex.h>
//ILOSTLBEGIN
//typedef IloArray<IloNumVarArray> D2Array;
//typedef IloArray<D2Array> D3Array;
//#include <nag.h>
//#include <nagg05.h>
//#include <nag_stdlib.h>
/*************************************/
/* Faram's Macros to avoid using nag */
/*************************************/
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
double nag_random_continuous_uniform() //nag random continuous uniform (g05cac) returns a pseudo-random number taken from a uniform distribution between 0 and 1.
{
double rval = (double) rand();
rval = (rval+1.0)/((double) RAND_MAX+2.0);
return rval;
}
double random_continuous_uniform_ab(const double a, const double b)//DP2
{
srand((unsigned)time(0));
double rval;
double lowest=a, highest=b;
double range=(highest-lowest)+1;
rval = lowest+int(range*rand()/(RAND_MAX + 1.0));
return rval;
}
double getRandom(double lower, double upper, double granularity) {//DP2
int width = 1 + ((upper - lower) / granularity);
return lower + ((rand() % width) * granularity);
}
double nag_random_exp(const double a)
{
if (fabs (a) < 1E-6)
return 0.0;
else
return (-1.0 * a * log (nag_random_continuous_uniform()));
}
int nag_random_discrete_uniform (const int a, const int b)
{
double f = nag_random_continuous_uniform();
f = f * (b-a+1);
int rval = a + f;
return rval;
}
float RoundToNearestQuarter (float num)//DP2
{
int n = num * 4;
return (float)n/4;
}
double factorial(int i)
{
if (i > 150)
{
fprintf (stderr, "Warning: large factorials, required %d!\n", i);
}
double f = 1.0;
while (i != 0)
{
f = i * f;
i--;
}
return f;
}
void nag_ref_vec_poisson(const double a, double **r, void *NAGERR_DEFAULT)
{
double sum = 0.0;
*r = (double *) malloc (sizeof (double) * 100);
(*r[0]) = 0.0;
for (int i = 1; i < 100; i++)
{
(*r)[i] = ((double)(pow(a,i))*((double)exp(-a)))/((double) factorial(i));
sum += (*r)[i];
}
(*r)[99] = 0.0;
if (sum < 1.0-1E-3)
{
fprintf (stderr, "Warning: improve nag_ref_vec_poisson, sum < 1-E-3\n");
}
}
int nag_return_discrete(double *r)
{
double x = nag_random_continuous_uniform();
double sum = 0.0;
for (int i = 0; i < 100; i++)
{
if ((sum+r[i] >= x) && (sum < x))
{
return i;
}
sum += r[i];
}
return 99;
}
#define NAG_FREE(r) (free(r))
#define nag_random_init_repeatable(s) (srand(s))
/******************************/
#ifdef CHECK_TARGETS
#define SYMPTOMS_DESTINED
#endif
#define LARGE_NUMBER 1e10
#define LARGE_INTEGER 12345678
#define IS_EQUAL_MARGIN 0.0001
#define SMALLEST_DOUBLE 0.0000001
#define HOUSEHOLD 0
#define PEERGROUP 1
#define COMMUNITY 2
// Fermi - added variable for number of age groups - increased to 8 age groups
# define NUM_AGE_GROUPS 8
// Disease Stages
#define NUM_DISEASE_STATES 8
#define SUSCEPTIBLE 0
#define EXPOSED 1
#define PRESYMPTOMATIC 2
#define ASYMPTOMATIC 3
#define SYMPTOMATIC 4
#define RECOVERED 5
#define HOSPITALIZED 6
#define DEAD 7
//measels control vaccination schedule
#define MCV1_9 0
#define MCV1_12 1
#define MCV2_2 2
#define MCV2_3 3
#define MCV2_4 4
#define MCV2_5 5
#define MCV2_6 6
#define MCV2_7 7
// EventList m_iEvents
#define NO_EVENT 0
#define PROGRESSION 1
#define MOVE_EVENT_LIST 2
#define ISOLATION_RELEASE 3
#define REPORT 4
#define QUARANTINE_RELEASE 5
#define SPAM_END 6
#define CLEAR_CTLIST_RECORD 7
#define TRACED 8
#define ISOLATION 9
#define DRUG_ACTIVATE 10
#define TEST_RETURN 11
#define RETEST 12
//#define BIRTH 13
#define DEATH 14 //tuba
#define VACCINATION 15
#define VACCINATION2 16
//#define AGING 17
//#define SUMMER_BEGIN 18
//#define SUMMER_END 19
#define NAG
#define DEBUG
#define DISPLAY
//#define PRINT_STATS
//#define READ_PARAMETERS
//#define PRINT_TIME_SERIES
#define IMPORT
//#define SINGLE_SEED
#define CHECK_TARGETS
#define CONTACT_TRACING
#define DURATION_DETAILS
#define LOW_SPAM
#define TESTING
#define SYMPTOMS_DESTINED
//#define NEW_PEER_GROUP
//#define SET_INITIAL_CONDITIONS_2
#define EQUILIBRIUM2
//#define SEASONALITY
//#define NEW_HOUSEHOLD
#ifdef DURATION_DETAILS
#define MAX_DURATION 100
#define MAX_QI_TIMES 10
#endif
enum Policy {NONE, Q, QA, QI, QIA, QIAC, QIAT, QIATC};
string g_sPolicyString[] = {"NONE", "Q", "QA", "QI", "QIA", "QIAC", "QIAT", "QIATC"};
const int gc_iPrintInterval = 1;
#ifdef CHECK_TARGETS
const double gc_dTimeMax1 = 3650+1e-10; // in days; why add all the 365.0000000001
#else
const double gc_dTimeMax1 = 365+1e-10; // in days;
#endif
double gc_dTimeMax = gc_dTimeMax1;
int g_iParameterSetIndexStart = 1, g_iParameterSetIndexEnd = 1, g_iParameterSetIndex = 1;
const int gc_iNumPolicies = 1;
const Policy gc_iPolicySet[] = {NONE}; //, QA, QI, QIA, QIAC, QIAT, QIATC};
Policy g_iPolicy;
const int gc_iNumRealizationsPerNetwork = 1, gc_iNumRealizations = 1, gc_iNumEventsBetweenDisplay = 1000000;
const int gc_iNumAttackRateThresholds = 4;
const double gc_dAttackRateThreshold[] = {0.05, 0.1, 0.15, 0.2};
double g_dTime, g_dOldTime, g_dAttackRateThresholdHittingTime[4];
bool g_bQuarantineActive = false, g_bIsolationActive = false, g_bTestingActive = false, g_bTracingActive = false, g_bDrugActive = false;
int g_iSeed = 10000000;
int OutOfStatePop = 0;
//vaccination parameters DP
int g_vScheduleV1;
int g_vScheduleV2;
double g_vMCV1;
double g_vMCV2;//DP4 deleted former def of MCV2 as fcn of MCV1
double g_vTimeToV1;
double g_vTimeToV2;
double g_vProbProtectedV1 = 0.95;//at 9 mos. = 0.85 and at 12-15 mos. = 0.85 acc. CDC
double g_vProbProtectedV2 = 0.99//at 4-6 yrs acc. CDC
;//at acc. 4-6 years CDC
//delete once equilibrium is done
const double g_ProbRecovered[NUM_AGE_GROUPS] = {0.99, 0.6, 0.6, 0.6, 0.7, 0.8, 0.9, 0.98};//DP Made this an array below; LATER make it user inputtable
const double g_ProbExposed[NUM_AGE_GROUPS] = {0.0, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.0};
/*//delete these g_vProbCoveredAgeGrp1 = X% after equilibrium2 is running
double g_vProbCoveredAgeGrp1 = 0.1;
double g_vProbCoveredAgeGrp2 = 0.1;
double g_vProbCoveredAgeGrp3 = 0.1;
double g_vProbCoveredAgeGrp4 = 0.1;
double g_vProbCoveredAgeGrp5 = 0.1;
double g_vProbCoveredAgeGrp6 = 0.1;
*///DP3 Equilibrium States
/*Delete when Equil2 is running const double PropDiseaseState[NUM_AGE_GROUPS][NUM_DISEASE_STATES] =
//each row is an age group, each column a disease state; note Recovered states always 1 b/c overwritten by other states
{
{ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}
};
*/
int interval=0;
int peergroupsizecontrol1, peergroupsizecontrol2;
int iHouseholdCounterTotal = 0;
// ************************* Parameters *************************************************
 
 
// Contact Network Parameters
const int number_counties = 160;
double Infected_ppl[number_counties];
//CENSUS
const int NUM_CENSUS_TRACTS = 1616;
//const int NUM_CENSUS_TRACTS = 400;
const int metroAtlanta[] = {17, 21, 27, 30, 32, 43, 47, 55, 59, 66, 70, 74, 106, 109, 121};
 
const int gc_iHKPopulationSize = 6800000;
int gc_iPopulationSizeTotal;
int gc_iPopulationSizeRunningTotal;
//Birth and death parameters DP CHANGED
const double g_dMeanBirthInterval = 365 / (10.54 / 1000 * gc_iPopulationSizeTotal);//Later (gc_iPopulationSizeRunningTotal-NumDead)
//10.54 births/1,000 population per year
const int gc_iMinClassSize = 25, gc_iMaxClassSize = 35, gc_iMaxNumPeers = 1000, gc_iMaxNumClassrooms = gc_iPopulationSizeTotal/gc_iMinClassSize;
const double gc_dAgeMeanNaturalDeathInterval[] = {3.33, 67.3192, 33.8452, 66.22812, 62.13556, 5.53493, 0.369088, 0.075203}; //tuba
int gc_iChildrenTotal;
int gc_iAdultsTotal;
double gc_dMeanClassSize1 = (gc_iMinClassSize+gc_iMaxClassSize)/2.0;
double gc_dMeanNumCoworkers1 = 20;
//CENSUS
int number_CT[number_counties]={0};//number counties = 160, this declares and array with 160 elements that will hold number of CTs in each county
double scale[number_counties]={0.0};
int subtotal[NUM_CENSUS_TRACTS];
int subtotal_county[number_counties];
//int county_age_population[5][number_counties]={0};
//int county_population[number_counties]={0};
int combinedcountyindex[NUM_CENSUS_TRACTS];
int combinedCTID[NUM_CENSUS_TRACTS];
int combined_population[NUM_CENSUS_TRACTS];
double combined_age_ratios[NUM_CENSUS_TRACTS][NUM_AGE_GROUPS];
double combined_census_location[NUM_CENSUS_TRACTS][2];
int gc_iPopulationSize[NUM_CENSUS_TRACTS];
int gc_iAgePopulation[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];//this and next, next line redundant? What's diff.
double gc_dPropAgeGroup[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];
int iAgePopulation[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];
int iAgeGroupSubtotal[NUM_AGE_GROUPS];
double gc_dMeanClassSize[]={0,0,14,14, 20,30}; // Fermi - Added Pre-kindergarten; No class for 0-9months & 9m-2 yr old kids
//double gc_dMeanClassSize[]={14,79,128};
static int workflow[NUM_CENSUS_TRACTS][NUM_CENSUS_TRACTS-1];
static double proportion[NUM_CENSUS_TRACTS][NUM_CENSUS_TRACTS-1];
double ratio[NUM_CENSUS_TRACTS-1];
int sum[NUM_CENSUS_TRACTS];
int gc_iAdultsPopulation[NUM_CENSUS_TRACTS];
int iChildrenPopulation[NUM_CENSUS_TRACTS], iAdultsPopulation[NUM_CENSUS_TRACTS];
double householdsizestat[NUM_CENSUS_TRACTS-1][7];
double householdfamilystatus[NUM_CENSUS_TRACTS-1][6];
double hhchildrenstatus[NUM_CENSUS_TRACTS-1][6];
int iHouseholdCounter[NUM_CENSUS_TRACTS];
int subtotalhouse[NUM_CENSUS_TRACTS];
int peergroups[NUM_CENSUS_TRACTS];
int iPopPerAgeGroupCounter[NUM_AGE_GROUPS];
int subtotal_peers[NUM_CENSUS_TRACTS];
//ISOLATION SEPARATED
int g_iCountyNumIsolated[NUM_CENSUS_TRACTS];
int hhsizecheck[8]={0};
 
// Fermi - increase all these for all the age groups
double g_dInfHazardPeerGroup[]={0.074, 0.074, 0.074,0.074, 0.074, 0.074, 0.037, 0.037};// Fermi
double dAgeSusceptibility[] = {1.15, 1.15, 1.15,1.15, 1.15, 1.15, 1.0, 1.0}; //Fermi
const double gc_dAgeProbSymptoms[] = {1.0, 1.0, 1.0,1.0, 1.0, 1.0, 1.0, 1.0};//CHANGED DP AGE Added more here for more age groups - Fermi
const double gc_dAgeProbHospitalization[] = {0.18,0.18,0.18,0.18,0.06, 0.06, 0.06, 0.12}; // Fermi
const double gc_dAgeProbDeath[] = {0.344,0.344,0.344,0.344, 0.172, 0.172, 0.172, 0.344}; // Fermi
double g_dAgeBeta[] = {0.525, 0.525, 0.525,0.525, 0.525, 0.525, 0.525, 0.525}; // Fermi
double g_dAgeInfHazardSym[] = {1.5, 1.5, 1.5,1.5, 1.5, 1.5, 1.0, 1.0}; // Fermi
double g_dAgeInfHazardPresym[] = {0.6544, 0.6544, 0.6544,0.6544, 0.6544, 0.6544, 0.6544, 0.6544}; // Fermi
double g_dAgeInfHazardAsym[] = {0.2237, 0.2237, 0.2237,0.2237, 0.2237, 0.2237, 0.2237, 0.2237}; //Fermi
/*
double g_dInfHazardPeerGroup[]={0.037, 0.037, 0.037, 0.037, 0.037};
double dAgeSusceptibility[] = {1.0, 1.0, 1.0, 1.0, 1.0};
const double gc_dAgeProbSymptoms[] = {0.67, 0.67, 0.67, 0.67, 0.67};
const double gc_dAgeProbHospitalization[] = {0.06, 0.06, 0.06, 0.06, 0.06};
const double gc_dAgeProbDeath[] = {0.172, 0.172, 0.172, 0.172, 0.172};
double g_dAgeBeta[] = {0.525, 0.525, 0.525, 0.525, 0.525};
double g_dAgeInfHazardSym[] = {1.0, 1.0, 1.0, 1.0, 1.0};
double g_dAgeInfHazardPresym[] = {0.6544, 0.6544, 0.6544, 0.6544, 0.6544};
double g_dAgeInfHazardAsym[] = {0.2237, 0.2237, 0.2237, 0.2237, 0.2237};
*/
const int ExtraRuns=0;
 
 
 
 
//THESE WILL BE CHANGED
//FOR INITIAL CONDITIONS
int initialstatus[NUM_DISEASE_STATES][number_counties];
//Optimization Definitions
#define MaxNumberFacility2 2 //means only at most 2 facility can be opened at each node
#define truckCapacity 500
#define TforOpt 30
#define maxNumOfDaysForOpt 210
#define periodlength 7
#define optimizationstart 5
double dailyDemand[number_counties-1][maxNumOfDaysForOpt][gc_iNumRealizationsPerNetwork+ExtraRuns];
double distancecounty[number_counties-1][number_counties-1];
double capacityFacility[number_counties-1][MaxNumberFacility2];
double fixedFacilityCost[number_counties-1][MaxNumberFacility2];
double openFacilityCost[number_counties-1][MaxNumberFacility2];
double closeFacilityCost[number_counties-1][MaxNumberFacility2];
double demand[number_counties-1][TforOpt];
double supply[number_counties-1];
double y_values[TforOpt][number_counties-1][MaxNumberFacility2];
double xx_values[TforOpt][number_counties-1][number_counties-1];
//INITIAL VALUES FOR OPTIMIZATION
double initial_inventory[number_counties-1];
int initial_y[(int)(maxNumOfDaysForOpt/periodlength)+1][number_counties-1][MaxNumberFacility2];
int familysize;
int additionalruns;
//FOR IMPROVING THE CODE
int supplynodes;
int facilitynodes;
int originalsupplycountyindex[number_counties-1];
int originalfacilitycountyindex[number_counties-1];
 
 
 
#ifdef SINGLE_SEED
const int gc_iInitialNumSeeds = 1;
#else
const int gc_iInitialNumSeeds = 0;
#endif
//Seasonality Declarations & Parameters DPS
void SummerDates(double);
double UserFOIFactor;
int g_dFirstSummer;
int FOIFactor = 1;
// Disease Progression Parameters CHANGED DP
const double gc_dMeanExpDuration = 7.94; /* also see line 373 which defines exposedduration as fcn of meanpresymduration */
const double gc_dStdDevExpDuration = 1.32, gc_dMeanHospDuration = 14, gc_dMeanPresymDuration = 4.0;
const double gc_dProbSymptoms = 1.00, gc_dProbDeath = 0.14, gc_dProbHospitalization = 0.06, gc_dSymAsymDurationRatio = 5.0/3;//DP need to find if ProbDeath is for a one age group and scaled for other age groups
// Disease Transmission Parameters
// Base Case
double g_dTheta = 0.3, g_dOmega = 0.5*g_dTheta, g_dGamma = 0.7, g_dDelta = 0.5;
double g_dProbSymActiveChildren = 0, g_dProbSymActiveAdults = 0.5;
double g_dBeta = 0.875, g_dR0 = 15, g_dInfHazardCommunityTotal = 0.0;
double g_dInfHazardPeerGroupAdults = 0.037, g_dInfHazardPeerGroupChildren = g_dInfHazardPeerGroupAdults, gc_dInfHazardHousehold = 1.0;
double g_dInfHazardPresym = 0.6544, g_dInfHazardAsym = 0.2237, g_dInfHazardSym = 1.0;
double g_dMeanSymDuration = 4.0, g_dMeanAsymDuration = g_dMeanSymDuration/gc_dSymAsymDurationRatio;
double g_dRelativeR0Isolation = 1, g_dBetaIsolation = g_dRelativeR0Isolation*g_dR0/(g_dMeanSymDuration+gc_dProbHospitalization*gc_dMeanHospDuration);
// Intervention Parameters
const short gc_iMaxRiskIndex = 3;
const double gc_dTestSensitivity = 0.9, gc_dTestSpecificity = 1.0;
double g_dProbComplianceDrugs = 0.5, g_dProbComplianceNoDrugs = g_dProbComplianceDrugs, g_dProbIsolation = 0.5;
double g_dProbCompliance = g_dProbComplianceNoDrugs, g_dProbReport = g_dProbCompliance;
const double gc_dSusHazardDrug = 0.3, gc_dInfHazardDrug = 0.69, gc_dMeanNumContactNamed = 5;
double g_dSusHazardHouseholdQuarantine = pow(2.0, 0.5), g_dInfHazardHouseholdQuarantine = g_dSusHazardHouseholdQuarantine;
const double gc_dSusHazardPeerGroupQuarantine = 0.25, gc_dInfHazardPeerGroupQuarantine = 0.25;
const double gc_dIsolationClock = 3, gc_dQuarantineClock = 7, gc_dMaxCTListDuration = 5;
const int gc_iMaxNumCTServers = 10000000, gc_iMaxNumTestServers = static_cast<int>(1e6*4000.0/gc_iHKPopulationSize*gc_iPopulationSizeTotal);
const double gc_dMeanTraceDuration = 1, gc_dMeanTestDuration = 1.5, gc_dMeanRetestDuration = 4;
double g_dMeanIsolationDelay = 1, g_dMeanDrugDelay = 1;
// Stress Parameters
#ifdef IMPORT
const double gc_dUnimodalImportPeak = 270, gc_dFlatImportRate = 100.0, gc_dSpamRate = 5000.0/gc_iHKPopulationSize;
#else
const double gc_dUnimodalImportPeak = 0, gc_dFlatImportRate = 0, gc_dSpamRate = 0;
#endif
const double gc_dMeanSpamDuration = 3;
const double
gc_dSmallestInfectivity = MAX(1e-7, g_dBeta*g_dInfHazardPeerGroupAdults*g_dInfHazardAsym*gc_dInfHazardPeerGroupQuarantine*gc_dInfHazardDrug/10.0),//MAX(tiny# OR (0.875*0.037*0.2237*0.25*0.69)/10)=0.000124929459)
gc_dSmallestSusceptibility = MAX(1e-7, gc_dSusHazardPeerGroupQuarantine*gc_dSusHazardDrug/10.0), //MAX(tiny# OR (.25*.3)/10=0.0075
gc_dSmallestFOI = MAX(1e-7, gc_dSmallestInfectivity*gc_dSmallestSusceptibility);//MAX(tiny# OR (0.0075*0.000124929459)
//#ifdef CHECK_TARGETS
int g_iSelectedSeed, g_iNumInfecteesBySeed[3][3];
double g_dTg;
//#endif
inline int Round(const double x){return static_cast<int>(floor(x+0.5));}
inline double Probability() {return nag_random_continuous_uniform();} //UNIFORM DRAW used a ton with if then to make decisions based on draws from distributions
inline double ExponentialDeviate(const double a){ return nag_random_exp(a);}//EXPONENTIAL DRAW
inline int PoissonDeviate(const double a)
{
int dDeviate;
double *r;
nag_ref_vec_poisson(a, &r, NULL);
dDeviate = nag_return_discrete(r);
NAG_FREE(r);
return dDeviate;
}
inline double ExposedDuration()
{
return 4.0+pow(-1.25*log(nag_random_continuous_uniform()), 1.0/2.2012)-gc_dMeanPresymDuration;//CHANGED DP
/* nag_random_continuous_uniform returns a pseudo-random number taken from a uniform distribution between 0 and 1
therefore exposedDuration = 0.5 plus some pos number between 0 and infinity to the power of approx 0.45 minus meanPresymDur */
/* purpose of the 0.5 (same as original meanPreSymDuration for flu) out front seems to be to keep ExposedDuration Positive so changed to 4.0 */
/* nag_random_... redefined around line 32 presumably because psuedo random isn't good enough */
}
inline double PresymptomaticDuration() {return ExponentialDeviate(gc_dMeanPresymDuration);}//CHANGED DP Missing Exponential Deviate
inline double AsymptomaticDuration() {return ExponentialDeviate(g_dMeanAsymDuration);}
//exponentialDeviate simply draws a number for a exp'l distrib'n with mean given by the param.
inline double SymptomaticDuration() {return ExponentialDeviate(g_dMeanSymDuration);}
inline double HospitalizationDuration() {return ExponentialDeviate(gc_dMeanHospDuration);}
inline int DiscreteUniformDeviate(const int a, const int b){ return nag_random_discrete_uniform(a, b);}
inline double ContinuousUniformDeviate(const double a, const double b){ return random_continuous_uniform_ab(a, b);}//DP2; does not work
inline int DiscreteUniformZeroDeviate(int a){ return nag_random_discrete_uniform(0, a-1);}
inline double SpamDuration() {return ExponentialDeviate(gc_dMeanSpamDuration);}
inline double TraceDuration() {return ExponentialDeviate(gc_dMeanTraceDuration);}
inline double TestDuration(){ return gc_dMeanTestDuration;}
inline double IsolationDelay() {return g_dMeanIsolationDelay;}
inline double DrugDelay() {return g_dMeanDrugDelay;}
inline bool IsEqual(const double x, const double y){
if (fabs(x) < SMALLEST_DOUBLE && fabs(y) < SMALLEST_DOUBLE)
return true;
else if (fabs(x) < SMALLEST_DOUBLE)
{
if (fabs(y) > SMALLEST_DOUBLE)
return false;
return true;
}
else if (fabs(y) < SMALLEST_DOUBLE)
{
if (fabs(x) > SMALLEST_DOUBLE)
return false;
return true;
}
else if (fabs(1-x/y) > IS_EQUAL_MARGIN)
return false;
else
return true;
}
 
 
//a type denotes a data structure and the meanings of operations that make sense for that data structure
template<class ElementType, class CounterType>//template header tells implementation we are defining a "template fcn" below this header and that the fcn will take a "type parameter"
//type parameters are like fcn parameters: they define names that can be used within the scope of the fcn; however, type parameters refer to types, not to variables; wherever ElementType and CounterType appear in the fcn, the implementation will assume that ElementType and CounterType name "types"
class CMySet
{
private:
CounterType m_iCurrentSize, m_iMaxSize;
ElementType* m_cMember;
public:
CMySet()//"default constructor"
{
m_iCurrentSize = 0;
m_iMaxSize = 2;
m_cMember = new ElementType[m_iMaxSize];
}

CMySet(const CounterType iInitialSize)//"constructor" w/ arguments
{
m_iCurrentSize = 0;
m_iMaxSize = (CounterType) MAX(2, iInitialSize);
m_cMember = new ElementType[m_iMaxSize];
}
CMySet(const CMySet& other)//DP2 08-13-08
{
m_iCurrentSize = other.m_iCurrentSize;
m_iMaxSize = other.m_iMaxSize;
m_cMember = new ElementType[m_iMaxSize];
std::copy(other.m_cMember, other.m_cMember+m_iMaxSize-1, m_cMember);
}
~CMySet(){ delete [] m_cMember;}
void Initialize()
{
m_iCurrentSize = 0;
m_iMaxSize = 2;
m_cMember = new ElementType[m_iMaxSize];
}
CMySet<ElementType, CounterType>& operator=(CMySet<ElementType, CounterType>& rhs)
{
//(*this).Clear();
(*this).Resize(rhs.Size());
for (CounterType iCounter = 0; iCounter < rhs.Size(); ++iCounter)
(*this).Push(rhs[iCounter]);
return *this;
}
ElementType& operator[](const CounterType iIndex) const
{
return m_cMember[iIndex];
}
int Find(const ElementType cTarget)//use to create removefromlistfcn
{
for (CounterType iCounter = 0; iCounter < m_iCurrentSize; ++iCounter)
{
if (m_cMember[iCounter] == cTarget){//compares two pointers to the IDs in the vector and if there's a match returns the !index!
cout << "Individual to be removed found. cTarget = " << cTarget << "; iCounter = " << iCounter << endl;
return iCounter;
}
}
return -1;
}
bool Empty()
{
if (m_iCurrentSize == 0)
return true;
return false;
}
int GetMaxSize(){ return m_iMaxSize;}
void Pop(){ m_iCurrentSize--;}
ElementType Top(){ return m_cMember[m_iCurrentSize-1];}
int Size(){ return m_iCurrentSize; }
void Clear(){ m_iCurrentSize = 0;}
int Push(const ElementType cTarget)//cTarget here is the individual id
{
// input: object to be inserted
// output: position of insertion
if (m_iCurrentSize == m_iMaxSize){//allocate more memory if at maxSize
ElementType *pElement;
m_iMaxSize = (CounterType) MAX(m_iMaxSize+1, m_iMaxSize*1.1);
pElement = new ElementType[m_iMaxSize];
for (CounterType iCounter = 0; iCounter < m_iCurrentSize; ++iCounter)
pElement[iCounter] = m_cMember[iCounter];
delete [] m_cMember;
m_cMember = pElement;
}
//cout << "cTarget: " << cTarget << endl;
cout << "Size: " << m_iCurrentSize << endl;
m_cMember[m_iCurrentSize++] = cTarget;//otherwisemake
return m_iCurrentSize-1;
}
ElementType Erase(const CounterType iIndex)
{
// input: position of removal
// output: object that replaces the object removed
if (iIndex < 0 || iIndex > m_iCurrentSize-1)
{
cout << "Error in CMySet::Erase" << endl;
exit(0);
}
m_cMember[iIndex] = m_cMember[--m_iCurrentSize];//This is super elegant; no need to move things around. Just take the last element and use it to replace the one you want to get rid of; no need to erase the last element beausee it'll be ignored b/c won't search past the current m_icurrentsize
}
void Resize(const CounterType iSize)
{
m_iCurrentSize = 0;
m_iMaxSize = (CounterType) MAX(2, iSize);
delete [] m_cMember;
m_cMember = new ElementType[m_iMaxSize];
}
};
class CFOIEngineElement
{
private:
double m_dFOI;
CMySet<int, unsigned int> *m_pInfectorGroup;
public:
CFOIEngineElement(): m_dFOI(0), m_pInfectorGroup(NULL){}
CFOIEngineElement(double x, CMySet<int, unsigned int> *y): m_dFOI(x), m_pInfectorGroup(y){}
CFOIEngineElement(CFOIEngineElement &e): m_dFOI(e.m_dFOI), m_pInfectorGroup(e.m_pInfectorGroup) {} // copy constructor
~CFOIEngineElement(){};
double GetFOI() { return m_dFOI;}
CMySet<int, unsigned int> *GetPtrInfectorGroup() { return m_pInfectorGroup;}
void SetFOI(const double x) { m_dFOI = x;}
void SetPtrInfectorGroup(CMySet<int, unsigned int> *x) { m_pInfectorGroup = x;}
};
class CFOIPerturbedListElement
{
private:
int m_iID;
double m_dOldFOI;
public:
CFOIPerturbedListElement(): m_iID(-1), m_dOldFOI(0) {}
CFOIPerturbedListElement(int x, double y): m_iID(x), m_dOldFOI(y) {}
~CFOIPerturbedListElement(){};
int GetID(){ return m_iID;}
double GetOldFOI(){ return m_dOldFOI;}
};
 
#ifdef HISTORY
// History m_iEvents
enum HistoryEvent {StoE, PtoA, AtoR, EtoP, PtoI, ItoR, ItoH, HtoD, HtoR, Report, QuaLead, QuaFollow, QuaExtend, QuaRelease,
IsoVol, IsoForced, IsoRelease, IsoExtend, NoEvent};
#endif
inline void Pause() {
cout << "Press ENTER to continue" << endl;
getchar();
}
// Each entry in the EventList is an EventListRecord object
#ifdef HISTORY
class CHistoryRecord
{
private:
HistoryEvent m_iEvent;
double m_dTime;
short m_iDiseaseStatus;
bool m_bIsolationStatus, m_bQuarantineStatus, m_bComplianceStatus;
public:
CHistoryRecord(): m_dTime(LARGE_NUMBER), m_iEvent(NoEvent), m_iDiseaseStatus(SUSCEPTIBLE), m_bIsolationStatus(false),
m_bQuarantineStatus(false), m_bComplianceStatus(false){};
CHistoryRecord(const double dtime, const HistoryEvent iEvent, const short iDiseaseStatus, const bool bIsolationStatus,
const bool bQuarantineStatus, const bool bComplianceStatus): m_dTime(dTime), m_iEvent(iEvent), m_iDiseaseStatus(iDiseaseStatus),
m_bIsolationStatus(bIsolationStatus),m_bQuarantineStatus(bQuarantineStatus), m_bComplianceStatus(bComplianceStatus){};
CHistoryRecord(const HistoryRecord& e): m_dTime(e.m_dTime), m_iEvent(e.m_iEvent), m_iDiseaseStatus(e.m_iDiseaseStatus),
m_bIsolationStatus(e.m_bIsolationStatus), m_bQuarantineStatus(e.m_bQuarantineStatus), m_bComplianceStatus(e.m_bComplianceStatus){};
~CHistoryRecord(){};
friend bool operator<(const CHistoryRecord& x, const CHistoryRecord& y)
{
if (x.m_dTime < y.m_dTime)
return true;
else if(x.m_dTime > y.m_dTime)
return false;
else
{
if (x.m_iEvent < y.m_iEvent)
return true;
return false;
}
}
friend ostream& operator<<(ostream& os, const CHistoryRecord& e)
{
string sEventName;
switch (e.iEvent)
{
case StoE: sEventName ="StoE";
break;
case PtoA: sEventName ="PtoA";
break;
case EtoP: sEventName ="EtoP";
break;
case PtoI: sEventName ="PtoI";
break;
case ItoR: sEventName ="ItoR";
break;
case ItoH: sEventName ="ItoH";
break;
case HtoD: sEventName ="HtoD";
break;
case HtoR: sEventName ="HtoR";
break;
case AtoR: sEventName ="AtoR";
break;
case IsoVol: sEventName = "IsoVol";
break;
case IsoForced: sEventName = "IsoForced";
break;
case QuaLead: sEventName = "QuaLead";
break;
case QuaFollow: sEventName = "QuaFollow";
break;
case IsoExtend: sEventName = "IsoExtend";
break;
case QuaExtend: sEventName = "QuaExtend";
break;
case QuaRelease: sEventName = "QuaRelease";
break;
case IsoRelease: sEventName = "IsoRelease";
break;
case Report: sEventName = "Report";
break;
default:
{
cout << endl << "Error: Unknown m_iEvent." << endl;
exit(0);
}
}
return os << setw(15) << e.m_dTime << setw(15) << sEventName << setw(5) << e.m_iDiseaseStatus << setw(5) << 
e.m_bIsolationStatus << setw(5) << e.m_bQuarantineStatus << setw(5) << e.m_bComplianceStatus << endl;
}
};
#endif
class CEventListRecord
{
private:
int m_iID;
short m_iEvent;
double m_dTime;
public:
CEventListRecord(): m_dTime(LARGE_NUMBER), m_iID(-1), m_iEvent(NO_EVENT) {}//"default (no arguments) constructor (no return type and same name as class)" ensures that EventListRecord object's data members are properly initialized
//instantiate a non-event, very far in future, with nonsense iID (maybe to allocate memory for events)
//The single semicolon initializes a member when a method is called. It's usually used to initialize constants in the constructor
CEventListRecord(double dTime, int iID, short iEvent): m_dTime(dTime), m_iID(iID), m_iEvent(iEvent) {} //constructor called if time, individual, and event type are passed
CEventListRecord(const CEventListRecord& e): m_dTime(e.m_dTime), m_iID(e.m_iID), m_iEvent(e.m_iEvent) {}//constructor called if eventListRecord is passed: pass attributes of existing eventListRecord into new eventListRecord object; used to update an event based on current event parameters
~CEventListRecord(){}//when the tilde is used as the first character in a class's method name (where the rest of the name must be the same name as the class) to indicate a destructor - a special method which is called at the end of the object's life.
void printt() { cout<<"PRINTING FROM CLASS\n"; }
void Initialize()//CEventListRecord.Initialize called when a new event needs to be created!!!; except never found in .cpp!
{
m_dTime = LARGE_NUMBER;//LARGE-NUMBER = 1e10 def'd above
m_iID = -1;
m_iEvent = NO_EVENT;
}
short GetEvent(){return m_iEvent;}
double GetTime() const{return m_dTime;}
int GetID() const {return m_iID;}
friend bool operator==(const CEventListRecord& x, const CEventListRecord& y)
//checks if EventRecords x and y have the same individual, time, and event type
// a class can allow non-member fcns to access private data by making them friends
{
if (IsEqual(x.m_dTime, y.m_dTime) == true && x.m_iID == y.m_iID && x.m_iEvent == y.m_iEvent)
return true;
return false;
}
friend bool operator<(const CEventListRecord& x, const CEventListRecord& y) // This is for priority queue;
/* This is for comparing priority of events in main fcn; implementation will pass two arguments
operator<() overloads (give special meanings to operators, when they are used with user-defined class) the < operator;
says when operator < has operand CEventListRecord, run this code instead of simply comparing the left and right operand and returning true or false
*/
{
if(x.m_dTime > y.m_dTime)//compare time of events
return true;
else if (x.m_dTime < y.m_dTime)
return false;
else
{
if (x.m_iID < y.m_iID)//if same time, then compare individual involved and type of event; if event has all three attributes the same, return false
return true;
else if (x.m_iID > y.m_iID)
return false;
else
{
if (x.m_iEvent < y.m_iEvent)
return true;
else if (x.m_iEvent > y.m_iEvent)
return false;
else
return false;
}
}
}
friend ostream& operator<<(ostream& os, const CEventListRecord& e)
{
string sEventName;
switch (e.m_iEvent)
{
case PROGRESSION: sEventName ="Progression";
break;
case NO_EVENT: sEventName = "No Event";
break;
case REPORT: sEventName = "Report";
break;
case QUARANTINE_RELEASE: sEventName = "Quarantine Release";
break;
case ISOLATION_RELEASE: sEventName = "Isolation Release";
break;
case MOVE_EVENT_LIST: sEventName = "Move EventList";
break;
default:
{
cout << endl << "Error in printing EventList events: Unknown m_iEvent." << endl;
exit(0);
}
}
return os << sEventName << " for Individual " << e.m_iID << " at time " << e.m_dTime << endl;
}
};
#ifdef CONTACT_TRACING
class CCTRecord
{
private:
int m_iID;
float m_dCTRecordTime;
public:
CCTRecord(const int x, const float y): m_iID(x), m_dCTRecordTime(y) {}
CCTRecord(const CCTRecord& c): m_iID(c.m_iID), m_dCTRecordTime(c.m_dCTRecordTime) {} // copy constructor
~CCTRecord(){}; // destructor
int GetID() const { return m_iID;}
float GetCTRecordTime() const {return m_dCTRecordTime;}
friend bool operator ==(const CCTRecord& x, const CCTRecord& y)
{
if (x.m_iID == y.m_iID && x.m_dCTRecordTime == y.m_dCTRecordTime)
return true;
return false;
}
};
#endif
 
 
class CIndividual
{
private:
int m_iID, m_iHouseholdID, m_iPeerGroupID, m_iCountyID;
double m_iAge;//DP2
int m_iAgeGroup;//DP2
short m_iDiseaseStatus;
float m_dTimeRecord;
bool m_bAdultStatus, m_bSpamStatus, m_bComplianceStatus, m_bQuarantineStatus, m_bIsolationStatus,
m_bImmuneStatus, m_bLeadStatus, m_bPeerGroupActive, m_bDrugStatus;
#ifdef SYMPTOMS_DESTINED
bool m_bWillBeSymptomatic;
#endif
#ifdef TESTING
bool m_bTestListStatus, m_bTestActive, m_bTestResult;
#endif
#ifdef CONTACT_TRACING
bool m_bCTListStatus, m_bCTActive, m_bCTInterviewed;
short m_iCTMultiplicity;
CMySet<short, unsigned short> m_cContactIndexList;
#endif
#ifdef DURATION_DETAILS
short m_iQuarantineTimes, m_iIsolationTimes, m_iTotalQuarantineDuration, m_iTotalIsolationDuration; // total number of times an individual was quarantined over the course of the epidemic
float m_dQuarantineEntryTime, m_dIsolationEntryTime;
#endif
#ifdef HISTORY
vector<cHistoryRecord> m_cHistory;
#endif
public:
 
CIndividual& operator=(CIndividual& y)
/* &y is a reference: means the class CIndiv is the type for any of the variables that are referenced by what follows
operator= overloads the = operator (give special meanings to operators, when they are used with user-defined class CIndividual)
The ampersand operator between the data type and the variable name can assume one of three positions as follows:
int& nbr;
int & nbr;
int &nbr;
As long as the & symbol is between a valid data type and a variable name, the compiler knows that the variable name (in this case Nbr) is a reference.
*/
{
m_iID = y.m_iID;
m_iAge = y.m_iAge;//DP2 Add reference LATER
m_iAgeGroup = y.m_iAgeGroup;
m_iHouseholdID = y.m_iHouseholdID;
m_iPeerGroupID = y.m_iPeerGroupID;
m_iCountyID = y.m_iCountyID;
m_iDiseaseStatus = y.m_iDiseaseStatus;
m_dTimeRecord = y.m_dTimeRecord;
m_bAdultStatus = y.m_bAdultStatus;
m_bDrugStatus = y.m_bDrugStatus;
m_bSpamStatus = y.m_bSpamStatus;
m_bComplianceStatus = y.m_bComplianceStatus;
m_bQuarantineStatus = y.m_bQuarantineStatus;
m_bIsolationStatus = y.m_bIsolationStatus;
m_bImmuneStatus = y.m_bImmuneStatus;
m_bLeadStatus = y.m_bLeadStatus;
m_bPeerGroupActive = y.m_bPeerGroupActive;
#ifdef SYMPTOMS_DESTINED
m_bWillBeSymptomatic = y.m_bWillBeSymptomatic;
#endif
#ifdef TESTING
m_bTestListStatus = y.m_bTestListStatus;
m_bTestActive = y.m_bTestActive;
m_bTestResult = y.m_bTestResult;
#endif
#ifdef CONTACT_TRACING
m_bCTListStatus = y.m_bCTListStatus;
m_bCTActive = y.m_bCTActive;
m_bCTInterviewed = y.m_bCTInterviewed;
m_iCTMultiplicity = y.m_iCTMultiplicity;
#endif
#ifdef DURATION_DETAILS
m_iQuarantineTimes = y.m_iQuarantineTimes; // total number of times an individual was quarantined over the course of the epidemic
m_iIsolationTimes = y.m_iIsolationTimes;
m_dQuarantineEntryTime = y.m_dQuarantineEntryTime;
m_dIsolationEntryTime = y.m_dIsolationEntryTime;
#endif
return *this;
}
void Print()
{
cout << "m_iID: " << m_iID << endl;
cout << "m_iAge " << m_iAge << endl;//DP
cout << "m_iAgeGroup" << m_iAgeGroup << endl;
cout << "m_iHouseholdID: " << m_iHouseholdID << endl;
cout << "m_iPeerGroupID: " << m_iPeerGroupID << endl;
cout << "m_iCountyID: " << m_iCountyID << endl;
cout << "m_iDiseaseStatus: " << m_iDiseaseStatus << endl;
cout << "m_dTimeRecord: " << m_dTimeRecord << endl;
cout << "m_bAdultStatus: " << m_bAdultStatus << endl;
cout << "m_bSpamStatus: " << m_bSpamStatus << endl;
cout << "m_bComplianceStatus: " << m_bComplianceStatus << endl;
cout << "m_bQuarantineStatus: " << m_bQuarantineStatus << endl;
cout << "m_bIsolationStatus: " << m_bIsolationStatus << endl;
cout << "m_bImmuneStatus: " << m_bImmuneStatus << endl;
cout << "m_bLeadStatus: " << m_bLeadStatus << endl;
cout << "x.m_bPeerGroupActive: " << m_bPeerGroupActive << endl;
return;
}
friend bool operator ==(const CIndividual& x, const CIndividual& y)
{
if (x.m_iID != y.m_iID)
cout << "m_iID: " << x.m_iID << " " << y.m_iID << endl;
if (x.m_iAge != y.m_iAge)
cout << "m_iAge: " << x.m_iAge << " " << y.m_iAge << endl;//DP2
if (x.m_iAgeGroup != y.m_iAgeGroup)
cout << "m_iAgeGroup: " << x.m_iAgeGroup << " " << y.m_iAgeGroup << endl;
if (x.m_iHouseholdID != y.m_iHouseholdID)
cout << "m_iHouseholdID: " << x.m_iHouseholdID << " " << y.m_iHouseholdID << endl;
if (x.m_iPeerGroupID != y.m_iPeerGroupID)
cout << "m_iPeerGroupID: " << x.m_iPeerGroupID << " " << y.m_iPeerGroupID << endl;
if (x.m_iCountyID != y.m_iCountyID)
cout << "m_iCountyID: " << x.m_iCountyID << " " << y.m_iPeerGroupID << endl;
if (x.m_iDiseaseStatus != y.m_iDiseaseStatus)
cout << "m_iDiseaseStatus: " << x.m_iDiseaseStatus << " " << y.m_iDiseaseStatus << endl;
if (x.m_dTimeRecord != y.m_dTimeRecord)
cout << "m_dTimeRecord: " << x.m_dTimeRecord << " " << y.m_dTimeRecord << endl;
if (x.m_bAdultStatus != y.m_bAdultStatus)
cout << "m_bAdultStatus: " << x.m_bAdultStatus << " " << y.m_bAdultStatus << endl;
if (x.m_bSpamStatus != y.m_bSpamStatus)
cout << "m_bSpamStatus: " << x.m_bSpamStatus << " " << y.m_bSpamStatus << endl;
if (x.m_bComplianceStatus != y.m_bComplianceStatus)
cout << "m_bComplianceStatus: " << x.m_bComplianceStatus << " " << y.m_bComplianceStatus << endl;
if (x.m_bQuarantineStatus != y.m_bQuarantineStatus)
cout << "m_bQuarantineStatus: " << x.m_bQuarantineStatus << " " << y.m_bQuarantineStatus << endl;
if (x.m_bIsolationStatus != y.m_bIsolationStatus)
cout << "m_bIsolationStatus: " << x.m_bIsolationStatus << " " << y.m_bIsolationStatus << endl;
if (x.m_bImmuneStatus != y.m_bImmuneStatus)
cout << "m_bImmuneStatus: " << x.m_bImmuneStatus << " " << y.m_bImmuneStatus << endl;
if (x.m_bLeadStatus != y.m_bLeadStatus)
cout << "m_bLeadStatus: " << x.m_bLeadStatus << " " << y.m_bLeadStatus << endl;
if (x.m_bPeerGroupActive != y.m_bPeerGroupActive)
cout << "x.m_bPeerGroupActive: " << x.m_bPeerGroupActive << " " << y.m_bPeerGroupActive << endl;
if (x.m_iID != y.m_iID || x.m_iAgeGroup != y.m_iAgeGroup || x.m_iHouseholdID != y.m_iHouseholdID || x.m_iPeerGroupID != y.m_iPeerGroupID || x.m_iCountyID != y.m_iCountyID ||
x.m_iDiseaseStatus != y.m_iDiseaseStatus || x.m_dTimeRecord != y.m_dTimeRecord || x.m_bAdultStatus != y.m_bAdultStatus ||
x.m_bSpamStatus != y.m_bSpamStatus || x.m_bComplianceStatus != y.m_bComplianceStatus || x.m_bQuarantineStatus != y.m_bQuarantineStatus ||
x.m_bIsolationStatus != y.m_bIsolationStatus || x.m_bImmuneStatus != y.m_bImmuneStatus || x.m_bLeadStatus != y.m_bLeadStatus ||
x.m_bPeerGroupActive != y.m_bPeerGroupActive)
return false;
#ifdef SYMPTOMS_DESTINED
if (x.m_bWillBeSymptomatic != y.m_bWillBeSymptomatic)
return false;
#endif
#ifdef TESTING
if (x.m_bTestListStatus != y.m_bTestListStatus || x.m_bTestActive != y.m_bTestActive || x.m_bTestResult != y.m_bTestResult)
return false;
#endif
#ifdef CONTACT_TRACING
if (x.m_bCTListStatus != y.m_bCTListStatus || x.m_bCTActive != y.m_bCTActive || x.m_bCTInterviewed != y.m_bCTInterviewed ||
x.m_iCTMultiplicity != y.m_iCTMultiplicity)
return false;
#endif
return true;
}
void Initialize(const int x)//called in line 5427 of main function when allocating memory for all individuals in pop
{
m_iHouseholdID = -1;
m_iPeerGroupID = -1;
m_iCountyID = -1;
m_iAge = -1;//DP2
m_iAgeGroup = -1;
Reset(x);
}
void Reset(const int x)//called in line 6392 at top of each realization/policy
{
m_iID = x;
m_dTimeRecord = LARGE_NUMBER;
m_iDiseaseStatus = SUSCEPTIBLE;
m_bQuarantineStatus = false;
m_bComplianceStatus = false;
m_bLeadStatus = false;
m_bSpamStatus = false;
m_bIsolationStatus = false;
m_bImmuneStatus = false;
m_bPeerGroupActive = true;
m_bDrugStatus = false;
#ifdef SYMPTOMS_DESTINED
m_bWillBeSymptomatic = false;
#endif
#ifdef TESTING
//m_bTestListStatus = false;
m_bTestActive = false;
m_bTestResult = false;
#endif
#ifdef CONTACT_TRACING
m_cContactIndexList.Clear();
m_bCTActive = false;
m_bCTListStatus = false;
m_iCTMultiplicity = 0;
m_bCTInterviewed = false;
#endif
#ifdef DURATION_DETAILS
m_iQuarantineTimes = 0;
m_iIsolationTimes = 0;
m_dQuarantineEntryTime = LARGE_NUMBER;
m_dIsolationEntryTime = LARGE_NUMBER;
m_iTotalQuarantineDuration = 0;
m_iTotalIsolationDuration = 0;
#endif
#ifdef HISTORY
m_cHistory.clear();
#endif
}
#ifdef SYMPTOMS_DESTINED
bool GetWillBeSymptomatic(){ return m_bWillBeSymptomatic;}
#endif
bool GetHouseholdActiveStatus()
{
if (m_iDiseaseStatus == DEAD || m_bIsolationStatus == true)
return false;
return true;
}
int GetID(){ return m_iID;}
void SetTimeRecord(const float x){ m_dTimeRecord = x;}
float GetTimeRecord(){ return m_dTimeRecord;}
bool GetAdultStatus(){ return m_bAdultStatus;}
bool GetQuarantineStatus(){ return m_bQuarantineStatus;}
bool GetComplianceStatus(){ return m_bComplianceStatus;}
bool GetIsolationStatus(){ return m_bIsolationStatus;}
bool GetImmuneStatus(){ return m_bImmuneStatus;}
short GetDiseaseStatus(){ return m_iDiseaseStatus;}
bool GetSymptomsStatus()
{
if (m_iDiseaseStatus == SYMPTOMATIC || m_iDiseaseStatus == HOSPITALIZED || m_bSpamStatus == true)
return true;
return false;
}
bool GetFluStatus()
{
if (m_iDiseaseStatus == PRESYMPTOMATIC || m_iDiseaseStatus == ASYMPTOMATIC ||
m_iDiseaseStatus == SYMPTOMATIC || m_iDiseaseStatus == HOSPITALIZED)
return true;
return false;
}
// void SetPeerGroupActive(const bool x){m_bPeerGroupActive = x;}
bool GetSpamStatus(){ return m_bSpamStatus;}
void SetSpamStatus(const bool x){ m_bSpamStatus = x;}
void SetPeerGroupActive(const bool x);
void SetLeadStatus(const bool x){ m_bLeadStatus = x;}
#ifdef TESTING
void TakeTest();
void Retest();
void CheckTestResult();
bool GetTestActive(){ return m_bTestActive;}
void SetTestActive(const bool x){ m_bTestActive = x;}
bool GetTestResult(){ return m_bTestResult;}
void SetTestResult(const bool x){ m_bTestResult = x;}
#endif
double GetInfectivity(const int iGroupType)
{
#ifdef CHECK_TARGETS
if (m_iID != g_iSelectedSeed)
return 0;
#endif
if (m_iDiseaseStatus == SUSCEPTIBLE || m_bIsolationStatus == true)
return 0;
if (iGroupType == PEERGROUP && m_bPeerGroupActive == false)
return 0;
double dInfectivity = g_dAgeBeta[m_iAgeGroup];
switch (m_iDiseaseStatus)
{
case PRESYMPTOMATIC:
dInfectivity *= g_dAgeInfHazardPresym[m_iAgeGroup];
break;
case ASYMPTOMATIC:
dInfectivity *= g_dAgeInfHazardAsym[m_iAgeGroup];
break;
case SYMPTOMATIC:
dInfectivity *= g_dAgeInfHazardSym[m_iAgeGroup];
break;
case HOSPITALIZED:
dInfectivity *= g_dAgeInfHazardSym[m_iAgeGroup];
break;
default:
return 0;
}
if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
{
// 999if (g_bDrugActive == true)
if (m_bDrugStatus == true)
dInfectivity *= gc_dInfHazardDrug;
if (iGroupType == HOUSEHOLD)
dInfectivity *= g_dInfHazardHouseholdQuarantine;
else if (iGroupType == PEERGROUP)
dInfectivity *= gc_dInfHazardPeerGroupQuarantine;
}
return dInfectivity;
}
double GetSusceptibility(const int iGroupType)
{
if (m_iDiseaseStatus != SUSCEPTIBLE || m_bIsolationStatus == true)//error check: person must be susceptible (and not be isolated)
return 0;
if (iGroupType == PEERGROUP && m_bPeerGroupActive == false)//error check
return 0;
// double dSusceptibility = 1.0;
double dSusceptibility = dAgeSusceptibility[m_iAgeGroup];//GetSusc just returns constant from array
if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
{
// 999if (g_bDrugActive == true)
if (m_bDrugStatus == true)
dSusceptibility *= gc_dSusHazardDrug;
if (iGroupType == HOUSEHOLD)
dSusceptibility *= g_dSusHazardHouseholdQuarantine;//mult HH by a factor if quarantined
else if (iGroupType == PEERGROUP)
dSusceptibility *= gc_dSusHazardPeerGroupQuarantine;//mult PG by a factor if quarantined
}
return dSusceptibility;
}
//this is the key set of functions that are called from BuildNetwork
int GetHouseholdID(){ return m_iHouseholdID;}
int GetPeerGroupID(){ return m_iPeerGroupID;}
int GetCountyID(){ return m_iCountyID;}//mis-named; actually gets ct id
int GetAgeGroup(){ return m_iAgeGroup;}//fcn that return age group attribute of this person (m_iAgeGroup???)
void SetAdultStatus(const bool x){ m_bAdultStatus = x;}
void SetAge(double iAge){ m_iAge = iAge;}//DP2 iAge is the number that's passed when you call this fcn
double GetAge(){ return m_iAge;}//DP2
void SetAgeGroup(const int iAgeGroup){ m_iAgeGroup = iAgeGroup;}//fcn that sets agegroup to iAgeGroup; where iAgeGroup is the constant that's passed when you call this fcn
void SetHouseholdID(const int iGroupID){ m_iHouseholdID = iGroupID;}
void SetPeerGroupID(const int iGroupID){ m_iPeerGroupID = iGroupID;}
void SetCountyID(const int iGroupID){ m_iCountyID = iGroupID;}
void SetDiseaseState(const int iNewDiseaseStatus);
void SusceptibleToExposed();
void ExposedToPresymptomatic();
void PresymptomaticToAsymptomatic();
void PresymptomaticToSymptomatic();
void AsymptomaticToRecovered();
void SymptomaticToHospitalized();
void SymptomaticToRecovered();
void HospitalizedToRecovered();
void HospitalizedToDead();
void DiseaseProgression();
void Isolation();
void IsolationRelease();
void Report();
int GetHouseholdMember(const int iIndex);
int GetPeerGroupMember(const int iIndex);
void CheckQuarantineRelease();
void QuarantineRelease();
void Quarantine(bool x);
void ActivateDrug();
void UpdateFOI(double dOldInfectivity[], double dOldSusceptibility[]);
bool IsQuarantinable()
{
if (m_bQuarantineStatus == false && m_bIsolationStatus == false && m_bImmuneStatus == false)
return true;
return false;
}
// FOR INITIALIZATION PURPOSES
void SusceptibleToExposed2();
void SusceptibleToPresymptomatic2();
void SusceptibleToAsymptomatic2();
void SusceptibleToSymptomatic2();
void SusceptibleToRecovered2();
void SusceptibleToHospitalized2();
void SusceptibleToDead2();
void RecoveredToSusceptible();
#ifdef CONTACT_TRACING
void ChangeCTMultiplicity(const int iDelta){ m_iCTMultiplicity += iDelta;}
void AddedToCTList(const bool x);
void RemovedFromCTList(const bool x);
void ActivateTracing();
void PushCTList();
void SetCTActive(const bool x){ m_bCTActive = x;}
bool GetCTActive(){ return m_bCTActive;}
void SetDrugStatus(const bool x){ m_bDrugStatus = x;}
bool GetDrugStatus(){ return m_bDrugStatus;}
void TraceContacts();
void Traced();
bool FindFamilyMember(const int x);
bool GetCTListStatus(){ return m_bCTListStatus;}
void SetCTListStatus(const bool x){ m_bCTListStatus = x;}
void ClearCTListRecord();
bool GetHouseholdCTActive();
int GetPeerGroupIndex()
{
for (int iCounter = 0; iCounter < GetPeerGroupSize(); ++iCounter)
{
if (GetPeerGroupMember(iCounter) == m_iID)
return iCounter;
}
return -1;
}
void AddToContactIndexList(const int x)
{
if (m_cContactIndexList.Find(x) == -1)
m_cContactIndexList.Push(x);
}
int GetContactListSize(){ return m_cContactIndexList.Size();}
#endif
int GetHouseholdSize();
int GetPeerGroupSize();
#ifdef DURATION_DETAILS
void SetQuarantineTimes(const int x){ m_iQuarantineTimes = x;}
void SetIsolationTimes(const int x){ m_iIsolationTimes = x;}
void SetQuarantineEntryTime(const float x){ m_dQuarantineEntryTime = x;}
void SetIsolationEntryTime(const float x){ m_dIsolationEntryTime = x;}
short GetQuarantineTimes(){ return m_iQuarantineTimes;}
short GetIsolationTimes(){ return m_iIsolationTimes;}
float GetQuarantineEntryTime(){ return m_dQuarantineEntryTime;}
float GetIsolationEntryTime(){ return m_dIsolationEntryTime;}
short GetTotalQuarantineDuration(){ return m_iTotalQuarantineDuration;}
short GetTotalIsolationDuration(){ return m_iTotalIsolationDuration;}
#endif
};
class CSocialGroup
{
private:
short m_iGroupType;
int m_iGroupID, m_iPosFOIEngine, m_iPosInfectorGroup;
bool m_bFOIPerturbedStatus;
CMySet<int, unsigned short> m_cMemberList;
double m_dInfectivity, m_dSusceptibility;
public:
CSocialGroup()
{
m_iGroupID = -1;
m_iGroupType = -1;
m_iPosFOIEngine = -1;
m_iPosInfectorGroup = -1;
m_bFOIPerturbedStatus = false;
m_dInfectivity = 0;
m_dSusceptibility = 0;
}
CSocialGroup(const int iGroupID)
{
m_iGroupID = iGroupID;
m_iGroupType = -1;
m_iPosFOIEngine = -1;
m_iPosInfectorGroup = -1;
m_bFOIPerturbedStatus = false;
m_dInfectivity = 0;
m_dSusceptibility = 0;
}
void SetGroupID(const int iGroupID){ m_iGroupID = iGroupID;}
int GetGroupID(){ return m_iGroupID;}
void SetGroupType(const short iGroupType){ m_iGroupType = iGroupType; }
short GetGroupType(){ return m_iGroupType;}
CMySet<int, unsigned short>& GetMemberList()
{
return m_cMemberList;
}
 
void Reset(const int ID)
{
m_iGroupID = ID;
m_iPosFOIEngine = -1;
m_iPosInfectorGroup = -1;
m_bFOIPerturbedStatus = false;
m_dInfectivity = 0;
m_dSusceptibility = 0;
}
void PrintData()
{
cout << "GroupID = " << m_iGroupID << endl;
cout << "MemeberListSize = " << m_cMemberList.Size() << endl;
cout << "Infectivity = " << m_dInfectivity << ", Susceptibility = " << m_dSusceptibility << ", InfHazardGroup = " << GetInfHazardGroup() << 
", FOIDenominator = " << GetFOIDenominator() << endl;
cout << "FOI = " << ComputeFOI() << endl;
}
void SetPosFOIEngine(const int x){ m_iPosFOIEngine = x;}
int GetPosFOIEngine(){ return m_iPosFOIEngine;}
void SetPosInfectorGroup(const int x){ m_iPosInfectorGroup = x;}
int GetPosInfectorGroup(){ return m_iPosInfectorGroup;}
void ClearMemberList(){ m_cMemberList.Clear(); }
void AddToMemberList(const int iIndividual){
m_cMemberList.Push(iIndividual);
}
void RemoveFromMemberList(const int iIndividual){//DP3//This code is taking forever!!!!
cout << "RemoveFromMemList called!" << endl;
int iCounter = m_cMemberList.Find(iIndividual);
cout << "Size: " << m_cMemberList.Size();
cout << "iCounter " << iCounter << " erased." << endl;
m_cMemberList.Erase(iCounter);

}
/*DELETE AFTER OCTOBER 1st DP3
void RemoveFromMemberList(const int iIndividual){
for (int iCounter = 0 ; iCounter < m_cMemberList.Size() ; iCounter++) {
if( m_cMemberList[iCounter] == iIndividual) {
m_cMemberList.Erase(m_cMemberList.begin()+iCounter, m_cMemberList.begin()+(iCounter+1));
}
}
}

void RemoveFromMemberList(const int iIndividualID){
vector<int>::iterator new_end = remove(m_cMemberList.begin(), m_cMemberList.end(), iIndividualID);
}
*/
void SetFOIPerturbedStatus(const bool x){ m_bFOIPerturbedStatus = x;}
bool GetFOIPerturbedStatus(){ return m_bFOIPerturbedStatus;}
double GetInfectivity(){ return m_dInfectivity;}
double GetSusceptibility(){ return m_dSusceptibility;}
double GetFOI(){ return m_dInfectivity*m_dSusceptibility/GetFOIDenominator()*GetInfHazardGroup();}
double ComputeFOI(){ return ComputeInfectivity()*ComputeSusceptibility()/GetFOIDenominator()*GetInfHazardGroup();}
virtual double GetInfHazardGroup(){ return 1.0;}
virtual double GetFOIDenominator(){ return 1.0;}
int SelectInfectee(const double dFOICutOff);//fcn declaration for SelectInfectee
// Just fcn declarations
double ComputeInfectivity();
double ComputeSusceptibility();
double ChangeInfectivity(const double dDelta);
double ChangeSusceptibility(const double dDelta);
};
class CHousehold: public CSocialGroup
{
private:
short m_iActiveHouseholdSize;
float m_dQuarantineTime, m_dDrugTime;
#ifdef CONTACT_TRACING
bool m_bHouseholdSeen;
#endif
#ifdef TESTING
bool m_bTestActive;
#endif
#ifdef DURATION_DETAILS
short m_iQuarantineTimes, m_iTotalQuarantineDuration; // total number of times a household was quarantined over the course of the epidemic
float m_dQuarantineEntryTime;
#endif
public:
CHousehold()
{
SetGroupType(HOUSEHOLD);
m_iActiveHouseholdSize = 0;
m_dQuarantineTime = LARGE_NUMBER;
m_dDrugTime = LARGE_NUMBER;
#ifdef CONTACT_TRACING
m_bHouseholdSeen = false;
#endif
#ifdef TESTING
m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
m_iQuarantineTimes = 0; // total number of times a household was quarantined over the course of the epidemic
m_dQuarantineEntryTime = LARGE_NUMBER;
m_iTotalQuarantineDuration = 0;
#endif
}
CHousehold(int iGroupID)
{
SetGroupID(iGroupID);
SetGroupType(HOUSEHOLD);
m_iActiveHouseholdSize = GetMemberList().Size();
m_dQuarantineTime = LARGE_NUMBER;
m_dDrugTime = LARGE_NUMBER;
#ifdef CONTACT_TRACING
m_bHouseholdSeen = false;
#endif
#ifdef TESTING
m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
m_iQuarantineTimes = 0; // total number of times a household was quarantined over the course of the epidemic
m_dQuarantineEntryTime = LARGE_NUMBER;
m_iTotalQuarantineDuration = 0;
#endif
}
~CHousehold(){}
void HouseholdReset(const int ID)
{
Reset(ID);
m_dQuarantineTime = LARGE_NUMBER;
m_dDrugTime = LARGE_NUMBER;
m_iActiveHouseholdSize = GetMemberList().Size();
#ifdef CONTACT_TRACING
m_bHouseholdSeen = false;
#endif
#ifdef TESTING
m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
m_iQuarantineTimes = 0;
m_dQuarantineEntryTime = LARGE_NUMBER;
m_iTotalQuarantineDuration = 0;
#endif
}
int GetHouseholdSize();
int GetPeerGroupSize();
int GetNumAdults();
void SetQuarantineTime(const float x){ m_dQuarantineTime = x;}
float GetQuarantineTime(){ return m_dQuarantineTime;}
void SetDrugTime(const float x){ m_dDrugTime = x;}
float GetDrugTime(){ return m_dDrugTime;}
bool GetHouseholdQuarantineStatus();
bool GetHouseholdDrugStatus();
int GetHouseholdQuarantineSize();
double GetInfHazardGroup(){ return gc_dInfHazardHousehold; }
double GetFOIDenominator(){ return MAX(1, static_cast<double>(m_iActiveHouseholdSize));}
void ResetActiveHouseholdSize(){ m_iActiveHouseholdSize = GetMemberList().Size();}
bool IsQuarantineReleasable();
int ComputeActiveHouseholdSize();
int GetActiveHouseholdSize(){ return m_iActiveHouseholdSize;}
int ChangeActiveHouseholdSize(const int iDelta);
#ifdef CONTACT_TRACING
void SetHouseholdSeen(const bool x){ m_bHouseholdSeen = x;}
bool GetHouseholdSeen(){ return m_bHouseholdSeen;}
#endif
#ifdef TESTING
bool GetTestActive(){ return m_bTestActive;}
void SetTestActive(const bool x){ m_bTestActive = x;}
#endif
#ifdef DURATION_DETAILS
void SetQuarantineTimes(const int x){ m_iQuarantineTimes = x;} // total number of times a household was quarantined over the course of the epidemic
void SetQuarantineEntryTime(const float x){ m_dQuarantineEntryTime = x;}
void IncreaseQuarantineTimes(){ ++m_iQuarantineTimes;}
short GetQuarantineTimes(){ return m_iQuarantineTimes;}
float GetQuarantineEntryTime(){ return m_dQuarantineEntryTime;}
short GetTotalQuarantineDuration(){ return m_iTotalQuarantineDuration;}
void ChangeTotalQuarantineDuration(const int x){ m_iTotalQuarantineDuration += x; }
#endif
};
/*
In order to derive a class from another, we use a colon (:) in the declaration of the derived class using the following format:
class derived_class_name: public base_class_name
{ ... };
Where derived_class_name is the name of the derived class and base_class_name is the name of the class on which it is based.
*/
class CPeerGroup: public CSocialGroup
{
private:
int m_iPeerGroupID, m_iCTOrCountyID, m_iAgeGroup;
bool m_bAdultStatus;//Var. to differentiate btw CT and county level PGs; not currently used
public:
CPeerGroup()
{
SetGroupType(PEERGROUP);
SetPeerGroupID(-1);
SetAgeGroup(-1);
SetCTorCountyID(-1);
}
CPeerGroup(const int iGroupID)
{
SetGroupID(iGroupID);
SetGroupType(PEERGROUP);
}
~CPeerGroup(){}
int GetPeerGroupSize();
double GetInfHazardGroup();
double GetFOIDenominator(){ return 1.0;}
// Assignment operator must take a const CPeerGroup
// Needed for push_back a CPeerGroup to a std::vector
CPeerGroup& operator=(const CPeerGroup& y)//DP2
{
m_iPeerGroupID = y.m_iPeerGroupID;
m_iAgeGroup = y.m_iAgeGroup;
m_bAdultStatus = y.m_bAdultStatus;//Not currently used

return *this;
}
// DP2 block: std::find uses operater== and cannot operate without it
bool operator==(const CPeerGroup& y)
{
return GetPeerGroupID() == y.GetPeerGroupID() && GetCTorCountyID() == y.GetCTorCountyID() && GetAgeGroup() == y.GetAgeGroup();
}
// These three "Get" methods must indicate they do not modify the instance
// (hence are typed const) to satisfy (const CPeerGroup& y) argument to operator==
int GetPeerGroupID()const { return m_iPeerGroupID;}//DP2
int GetCTorCountyID() const { return m_iCTOrCountyID;}//DP2; mis-named; actually gets ct id
int GetAgeGroup() const { return m_iAgeGroup;}//DP2; fcn that return age group attribute of this person (m_iAgeGroup???)
void SetAgeGroup(const int iAgeGroup){ m_iAgeGroup = iAgeGroup;}//fcn that sets agegroup to iAgeGroup; where iAgeGroup is the constant that's passed when you call this fcn
void SetPeerGroupID(const int iGroupID){ m_iPeerGroupID = iGroupID;}
void SetCTorCountyID(const int iCTorCountyID){ m_iCTOrCountyID = iCTorCountyID;}//DP2
};
 
std::vector<CPeerGroup>& get_vector();
priority_queue<CEventListRecord> **g_pEventList;
//priority_queue<CEventListRecord> g_pEventList;
//**g_pEventList is the size but it's defined here and not initialized with any value.
CIndividual *g_cIndividual =NULL; //DP BIRTHS pointers! standard syntax for declaring a pointer: type *x
CHousehold *g_cHousehold = NULL;
CPeerGroup *g_cPeerGroup = NULL;
 
int g_iNumGroups[] = {0, 0}, g_iMaxNumGroups[] = {0, 0};
int g_iCurrentEventList = 0; // There's more than one EventList!!!
const int gc_iNumEventLists = static_cast<int>(100*gc_dTimeMax);//This var is CONSTANT (36,500)!!! so 100 eventLists per day. Am I exceeding this? Such an arbitrary number? So you can't just add events willy nilly without running an event. static cast for any normal conversion between types (need b/c timeMax not an int)
vector<CMySet<int, unsigned int>*> g_cFreePtrInfectorGroup;//what is the asterisk after the CMySet<> doing?
const int gc_iNumEngineSlots = static_cast<int>(10*pow(static_cast<double>(gc_iPopulationSizeTotal), 0.5));
double g_dTotalFOI[2], *g_dFOI[2];
CMySet<CFOIPerturbedListElement, unsigned int> *g_cFOIPerturbedList[2];
CMySet<CFOIEngineElement, unsigned int> *g_cFOIEngine[2];
CMySet<int, unsigned int> *g_cEmptyFOIEngineSlot[2];
//CMySet<int, unsigned int> g_cSusceptibleList, g_cSpamList;
 
#ifdef CONTACT_TRACING
deque<CCTRecord> g_cCTList;
#endif
time_t g_tClockStart, g_tClockStart2;
int g_iInfectionIncidence, g_iMaxInfectionIncidence;
int g_iNumQuarantined, g_iOldNumQuarantined, g_iMaxNumQuarantined, g_iQuarantineIncidence, g_iMaxQuarantineIncidence;
int g_iNumHouseholdsQuarantined, g_iMaxNumHouseholdsQuarantined, g_iTotalNumHouseholdsQuarantined;
int g_iTotalNumHouseholdsQuarantineReleased, g_iDailyNumHouseholdsQuarantineReleased;
int g_iTotalNumQuarantined, g_iTotalNumQuarantineReleased, g_iDailyNumQuarantineReleased, g_iDisruptiveness, g_iMaxDisruptiveness;
int g_iNumIsolated, g_iOldNumIsolated, g_iMaxNumIsolated, g_iIsolationIncidence, g_iMaxIsolationIncidence;
int g_iTotalNumIsolated, g_iTotalNumIsolationReleased, g_iDailyNumIsolationReleased, g_iDailyLeakage, g_iTotalLeakage;
double g_dTotalQuarantineDuration, g_dTotalIsolationDuration;
double g_dTotalDrugUsedQuarantineNonSymp, g_dTotalDrugUsedQuarantineSymp, g_dTotalDrugUsedQuarantineNonComp, g_dTotalDrugUsedIsolation;
double g_dDailyDrugUsedQuarantineNonSymp, g_dDailyDrugUsedQuarantineSymp, g_dDailyDrugUsedQuarantineNonComp, g_dDailyDrugUsedIsolation;
int g_iTotalNumImport, g_iTotalNumSpam, g_iMaxNumHospitalized;
int g_iNumActiveCTServers, g_iNumActiveTestServers, g_iNumCTRecordRemoved;
double g_dTotalCloseFOI, g_dOldTotalCloseFOI;
double g_dTimeToCloseInfection, g_dTimeToEventOnList;
double g_dTimeToCloseInfection1, g_dTimeToCloseInfection2;
int selected_group;
double g_dTimeResumeTesting;
//CENSUS
double g_dImportRate[NUM_CENSUS_TRACTS];
int SelectedCounty;
double g_dFOIImport[NUM_CENSUS_TRACTS], g_dFOICommunity[NUM_CENSUS_TRACTS], g_dInfHazardCommunity[NUM_CENSUS_TRACTS];
double g_dFOICommunityTotal, g_dFOIIsolationTotal, g_dTimeToNonCloseInfectionAndSpamMin;
double g_dFOIIsolation[NUM_CENSUS_TRACTS], g_dFOINonCloseAndSpam[NUM_CENSUS_TRACTS], g_dFOINonCloseAndSpamTotal;
double g_dTimeToNonCloseInfectionAndSpam[NUM_CENSUS_TRACTS];
int g_iHeadCount[NUM_DISEASE_STATES][2][2][2][NUM_CENSUS_TRACTS]; // g_iHeadCount[disease_status][quarantine_status][compliance_status][isolation_status][census_tract_info]
int g_iHeadCountTotal[NUM_DISEASE_STATES][2][2][2];
CMySet<int, unsigned int> g_cSusceptibleList[NUM_CENSUS_TRACTS], g_cSpamList[NUM_CENSUS_TRACTS];
//FOR BUILDING THE NETWORK
int temp;
double tempor;
int chosen1, chosen2;
int g_iNumClassrooms[4] = {0, 0, 0, 0}; // fermi - added the Pre-kindergarten Peer-Group
int g_iOldGroups = 0;
int g_iBabyGroups = 0;//Fermi
//tuba
string str= "resultstuba.txt";
ofstream sfile(str.c_str());
//tuba
bool g_bStopTesting;
int g_iEventCounter, g_iPrintCounter, g_iThresholdCounter, g_iNumTraced, g_iNumFOIUpdates;
ofstream g_ofTimeSeries[4], g_ofStat[2];
const int gc_iNumTimeSeries = 4, gc_iNumStat = 2;
#ifdef CHECK_TARGETS
vector<double> g_cTimesInfection;
#endif
 
 
#ifdef DURATION_DETAILS
int g_iQuarantineDurationPDF[MAX_DURATION+1], g_iHouseholdQuarantineDurationPDF[MAX_DURATION+1], g_iIsolationDurationPDF[MAX_DURATION+1];
//int g_iQuarantineTimesPDF[MAX_QI_TIMES], g_iIsolationTimesPDF[MAX_QI_TIMES], g_iHouseholdQuarantineTimesPDF[MAX_QI_TIMES];
#endif
0
 

Author Comment

by:ltdanp22
ID: 22736938
whoops. .h as code snippet below
#include <ctime>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <queue>
#include <algorithm>
#include <string>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <windows.h>//DP2
#include <vector>//DP2
#include <time.h>//DP2
 
using namespace std; 
 
/*
#include <nag.h>//DP2
#include <stdio.h>
#include <nag_stdlib.h>
#include <nagg05.h>
*/
 
#include <stdlib.h>
 
//#include <ilcplex/ilocplex.h>
 
//ILOSTLBEGIN
//typedef IloArray<IloNumVarArray> D2Array; 
//typedef IloArray<D2Array> D3Array;
 
//#include <nag.h>
//#include <nagg05.h>
//#include <nag_stdlib.h>
/*************************************/
/* Faram's Macros to avoid using nag */
/*************************************/
 
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
 
double nag_random_continuous_uniform() //nag random continuous uniform (g05cac) returns a pseudo-random number taken from a uniform distribution between 0 and 1.
{
	double rval = (double) rand();
	rval = (rval+1.0)/((double) RAND_MAX+2.0);
	return rval;
}
 
double random_continuous_uniform_ab(const double a, const double b)//DP2
{
	srand((unsigned)time(0)); 
    double rval; 
    double lowest=a, highest=b; 
    double range=(highest-lowest)+1; 
    rval = lowest+int(range*rand()/(RAND_MAX + 1.0)); 
	return rval;
} 
 
double getRandom(double lower, double upper, double granularity) {//DP2
    int width = 1 + ((upper - lower) / granularity);
    return lower + ((rand() % width) * granularity);
}
 
double nag_random_exp(const double a) 
{
	if (fabs (a) < 1E-6)
		return 0.0;
	else
		return	(-1.0 * a * log (nag_random_continuous_uniform()));
}
 
int nag_random_discrete_uniform (const int a, const int b) 
{
	double f = nag_random_continuous_uniform();
	f = f * (b-a+1);
	int rval = a + f;
	return rval;
}
 
float RoundToNearestQuarter (float num)//DP2
{
	int n = num * 4;
	return (float)n/4;
}
 
double factorial(int i)
{
  if (i > 150)
  {
	fprintf (stderr, "Warning: large factorials, required %d!\n", i);
  }
  double f = 1.0;
  while (i != 0) 
  {
    f = i * f;
    i--;
  }
  return f;
}
 
void nag_ref_vec_poisson(const double a, double **r, void *NAGERR_DEFAULT)
{
	double sum = 0.0;
	*r = (double *) malloc (sizeof (double) * 100);
	(*r[0]) = 0.0;
	for (int i = 1; i < 100; i++)
	{
		(*r)[i] = ((double)(pow(a,i))*((double)exp(-a)))/((double) factorial(i));
		sum += (*r)[i];
	}
	(*r)[99] = 0.0;
	if (sum < 1.0-1E-3)
	{
		fprintf (stderr, "Warning: improve nag_ref_vec_poisson, sum < 1-E-3\n");
	}
}
 
int nag_return_discrete(double *r)
{
	double x = nag_random_continuous_uniform();
	double sum = 0.0;
 
	for (int i = 0; i < 100; i++)
	{		
		if ((sum+r[i] >= x) && (sum < x))
		{
			return i;
		}
		sum += r[i];
	}
 
	return 99;
}
 
#define NAG_FREE(r) (free(r))
 
#define nag_random_init_repeatable(s) (srand(s))
 
/******************************/
 
#ifdef CHECK_TARGETS
#define SYMPTOMS_DESTINED
#endif
 
#define LARGE_NUMBER 1e10
#define LARGE_INTEGER 12345678
#define IS_EQUAL_MARGIN 0.0001
#define SMALLEST_DOUBLE 0.0000001
 
#define HOUSEHOLD 0
#define PEERGROUP 1
#define COMMUNITY 2
 
// Fermi - added variable for number of age groups - increased to 8 age groups 
# define NUM_AGE_GROUPS 8
 
// Disease Stages
#define NUM_DISEASE_STATES 8
#define SUSCEPTIBLE 0
#define EXPOSED 1
#define PRESYMPTOMATIC 2
#define ASYMPTOMATIC 3
#define SYMPTOMATIC 4
#define RECOVERED 5
#define HOSPITALIZED 6
#define DEAD 7
 
//measels control vaccination schedule
#define MCV1_9 0
#define MCV1_12 1
#define MCV2_2 2
#define MCV2_3 3
#define MCV2_4 4
#define MCV2_5 5
#define MCV2_6 6
#define MCV2_7 7
 
// EventList m_iEvents
 
#define NO_EVENT 0
#define PROGRESSION 1
#define MOVE_EVENT_LIST 2
#define ISOLATION_RELEASE 3
#define REPORT 4
#define QUARANTINE_RELEASE 5
#define SPAM_END 6
#define CLEAR_CTLIST_RECORD 7
#define TRACED 8
#define ISOLATION 9
#define DRUG_ACTIVATE 10
#define TEST_RETURN 11
#define RETEST 12
//#define BIRTH 13
#define DEATH 14 //tuba
#define VACCINATION 15
#define VACCINATION2 16
//#define AGING 17
//#define SUMMER_BEGIN 18
//#define SUMMER_END 19
 
#define NAG
#define DEBUG
#define DISPLAY
//#define PRINT_STATS
//#define READ_PARAMETERS
//#define PRINT_TIME_SERIES
#define IMPORT 
//#define SINGLE_SEED
#define CHECK_TARGETS
#define CONTACT_TRACING
#define DURATION_DETAILS
#define LOW_SPAM
#define TESTING
#define SYMPTOMS_DESTINED
//#define NEW_PEER_GROUP
//#define SET_INITIAL_CONDITIONS_2
#define EQUILIBRIUM2
//#define SEASONALITY
//#define NEW_HOUSEHOLD
 
#ifdef DURATION_DETAILS
#define MAX_DURATION 100
#define MAX_QI_TIMES 10
#endif
 
enum Policy {NONE, Q, QA, QI, QIA, QIAC, QIAT, QIATC};
string g_sPolicyString[] = {"NONE", "Q", "QA", "QI", "QIA", "QIAC", "QIAT", "QIATC"};
const int gc_iPrintInterval = 1;
 
#ifdef CHECK_TARGETS
const double gc_dTimeMax1 = 3650+1e-10;  // in days; why add all the 365.0000000001
#else
const double gc_dTimeMax1 = 365+1e-10;  // in days; 
#endif
 
double gc_dTimeMax = gc_dTimeMax1;
 
int g_iParameterSetIndexStart = 1, g_iParameterSetIndexEnd = 1, g_iParameterSetIndex = 1;
 
const int gc_iNumPolicies = 1;
const Policy gc_iPolicySet[] = {NONE}; //, QA, QI, QIA, QIAC, QIAT, QIATC};
Policy g_iPolicy;
const int gc_iNumRealizationsPerNetwork = 1, gc_iNumRealizations = 1, gc_iNumEventsBetweenDisplay = 1000000;
const int gc_iNumAttackRateThresholds = 4;
const double gc_dAttackRateThreshold[] = {0.05, 0.1, 0.15, 0.2};
double g_dTime, g_dOldTime, g_dAttackRateThresholdHittingTime[4];
bool g_bQuarantineActive = false, g_bIsolationActive = false, g_bTestingActive = false, g_bTracingActive = false, g_bDrugActive = false;
int g_iSeed = 10000000;
int OutOfStatePop = 0;
//vaccination parameters DP
int g_vScheduleV1;
int g_vScheduleV2;
double g_vMCV1;
double g_vMCV2;//DP4 deleted former def of MCV2 as fcn of MCV1
double g_vTimeToV1;
double g_vTimeToV2;
double g_vProbProtectedV1 = 0.95;//at 9 mos. = 0.85 and at 12-15 mos. = 0.85 acc. CDC
double g_vProbProtectedV2 = 0.99//at 4-6 yrs acc. CDC
;//at acc. 4-6 years CDC
 
//delete once equilibrium is done
const double g_ProbRecovered[NUM_AGE_GROUPS] = {0.99, 0.6, 0.6, 0.6, 0.7, 0.8, 0.9, 0.98};//DP Made this an array below; LATER make it user inputtable
const double g_ProbExposed[NUM_AGE_GROUPS] = {0.0, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.0};
 
/*//delete these g_vProbCoveredAgeGrp1 = X% after equilibrium2 is running
double g_vProbCoveredAgeGrp1 = 0.1;
double g_vProbCoveredAgeGrp2 = 0.1;
double g_vProbCoveredAgeGrp3 = 0.1;
double g_vProbCoveredAgeGrp4 = 0.1;
double g_vProbCoveredAgeGrp5 = 0.1;
double g_vProbCoveredAgeGrp6 = 0.1;
*///DP3 Equilibrium States
/*Delete when Equil2 is running const double PropDiseaseState[NUM_AGE_GROUPS][NUM_DISEASE_STATES] =
//each row is an age group, each column a disease state; note Recovered states always 1 b/c overwritten by other states
	{
		{ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
		{ 0.3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}
	};
*/
int interval=0;
int peergroupsizecontrol1, peergroupsizecontrol2;
int iHouseholdCounterTotal = 0;
 
// ************************* Parameters *************************************************
 
 
 
// Contact Network Parameters
const int number_counties = 160;
double Infected_ppl[number_counties];
//CENSUS
const int NUM_CENSUS_TRACTS = 1616;
//const int NUM_CENSUS_TRACTS = 400;
const int metroAtlanta[] = {17, 21, 27, 30, 32, 43, 47, 55, 59, 66, 70, 74, 106, 109, 121};
 
 
const int gc_iHKPopulationSize = 6800000;
int gc_iPopulationSizeTotal;
int gc_iPopulationSizeRunningTotal;
//Birth and death parameters DP CHANGED
const double g_dMeanBirthInterval = 365 / (10.54 / 1000 * gc_iPopulationSizeTotal);//Later (gc_iPopulationSizeRunningTotal-NumDead)
//10.54 births/1,000 population per year
const int gc_iMinClassSize = 25, gc_iMaxClassSize = 35, gc_iMaxNumPeers = 1000, gc_iMaxNumClassrooms = gc_iPopulationSizeTotal/gc_iMinClassSize;
 
const double gc_dAgeMeanNaturalDeathInterval[] = {3.33, 67.3192, 33.8452, 66.22812, 62.13556, 5.53493, 0.369088, 0.075203}; //tuba
 
int gc_iChildrenTotal;
int gc_iAdultsTotal;
double gc_dMeanClassSize1 = (gc_iMinClassSize+gc_iMaxClassSize)/2.0;
double gc_dMeanNumCoworkers1 = 20;
 
//CENSUS
int number_CT[number_counties]={0};//number counties = 160, this declares and array with 160 elements that will hold number of CTs in each county
double scale[number_counties]={0.0};
int subtotal[NUM_CENSUS_TRACTS];
int subtotal_county[number_counties];
//int county_age_population[5][number_counties]={0};
//int county_population[number_counties]={0};
int combinedcountyindex[NUM_CENSUS_TRACTS];
int combinedCTID[NUM_CENSUS_TRACTS];
int combined_population[NUM_CENSUS_TRACTS];
double combined_age_ratios[NUM_CENSUS_TRACTS][NUM_AGE_GROUPS];
double combined_census_location[NUM_CENSUS_TRACTS][2];
int gc_iPopulationSize[NUM_CENSUS_TRACTS];
int gc_iAgePopulation[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];//this and next, next line redundant? What's diff.
double gc_dPropAgeGroup[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];
int iAgePopulation[NUM_AGE_GROUPS][NUM_CENSUS_TRACTS];
int iAgeGroupSubtotal[NUM_AGE_GROUPS];
double gc_dMeanClassSize[]={0,0,14,14, 20,30}; // Fermi - Added Pre-kindergarten;  No class for 0-9months & 9m-2 yr old kids 
//double gc_dMeanClassSize[]={14,79,128};
static int workflow[NUM_CENSUS_TRACTS][NUM_CENSUS_TRACTS-1];
static double proportion[NUM_CENSUS_TRACTS][NUM_CENSUS_TRACTS-1];
double ratio[NUM_CENSUS_TRACTS-1];
int sum[NUM_CENSUS_TRACTS];
int gc_iAdultsPopulation[NUM_CENSUS_TRACTS];
int iChildrenPopulation[NUM_CENSUS_TRACTS], iAdultsPopulation[NUM_CENSUS_TRACTS];
 
double householdsizestat[NUM_CENSUS_TRACTS-1][7];
double householdfamilystatus[NUM_CENSUS_TRACTS-1][6];
double hhchildrenstatus[NUM_CENSUS_TRACTS-1][6];
int iHouseholdCounter[NUM_CENSUS_TRACTS];
int subtotalhouse[NUM_CENSUS_TRACTS];
int peergroups[NUM_CENSUS_TRACTS];
int iPopPerAgeGroupCounter[NUM_AGE_GROUPS];
int subtotal_peers[NUM_CENSUS_TRACTS];
//ISOLATION SEPARATED
int g_iCountyNumIsolated[NUM_CENSUS_TRACTS];
 
int hhsizecheck[8]={0};
 
 
// Fermi - increase all these for all the age groups 
double g_dInfHazardPeerGroup[]={0.074, 0.074, 0.074,0.074, 0.074, 0.074, 0.037, 0.037};// Fermi
double dAgeSusceptibility[] = {1.15, 1.15, 1.15,1.15, 1.15, 1.15, 1.0, 1.0}; //Fermi
const double gc_dAgeProbSymptoms[] = {1.0, 1.0, 1.0,1.0, 1.0, 1.0, 1.0, 1.0};//CHANGED DP AGE Added more here for more age groups - Fermi
const double gc_dAgeProbHospitalization[] = {0.18,0.18,0.18,0.18,0.06, 0.06, 0.06, 0.12}; // Fermi
const double gc_dAgeProbDeath[] = {0.344,0.344,0.344,0.344, 0.172, 0.172, 0.172, 0.344}; // Fermi
 
double g_dAgeBeta[] = {0.525, 0.525, 0.525,0.525, 0.525, 0.525, 0.525, 0.525}; // Fermi
double g_dAgeInfHazardSym[] = {1.5, 1.5, 1.5,1.5, 1.5, 1.5, 1.0, 1.0}; // Fermi
double g_dAgeInfHazardPresym[] = {0.6544, 0.6544, 0.6544,0.6544, 0.6544, 0.6544, 0.6544, 0.6544}; // Fermi
double g_dAgeInfHazardAsym[] = {0.2237, 0.2237, 0.2237,0.2237, 0.2237, 0.2237, 0.2237, 0.2237}; //Fermi
 
/*
double g_dInfHazardPeerGroup[]={0.037, 0.037, 0.037, 0.037, 0.037};
double dAgeSusceptibility[] = {1.0, 1.0, 1.0, 1.0, 1.0};
const double gc_dAgeProbSymptoms[] = {0.67, 0.67, 0.67, 0.67, 0.67};
const double gc_dAgeProbHospitalization[] = {0.06, 0.06, 0.06, 0.06, 0.06};
const double gc_dAgeProbDeath[] = {0.172, 0.172, 0.172, 0.172, 0.172};
double g_dAgeBeta[] = {0.525, 0.525, 0.525, 0.525, 0.525};
double g_dAgeInfHazardSym[] = {1.0, 1.0, 1.0, 1.0, 1.0};
double g_dAgeInfHazardPresym[] = {0.6544, 0.6544, 0.6544, 0.6544, 0.6544};
double g_dAgeInfHazardAsym[] = {0.2237, 0.2237, 0.2237, 0.2237, 0.2237};
*/
const int ExtraRuns=0;
 
 
 
 
 
//THESE WILL BE CHANGED
//FOR INITIAL CONDITIONS
int initialstatus[NUM_DISEASE_STATES][number_counties];
//Optimization Definitions
#define MaxNumberFacility2 2 //means only at most 2 facility can be opened at each node
#define	truckCapacity 500
#define TforOpt 30
#define maxNumOfDaysForOpt 210
#define periodlength 7
#define optimizationstart 5
double dailyDemand[number_counties-1][maxNumOfDaysForOpt][gc_iNumRealizationsPerNetwork+ExtraRuns];
double distancecounty[number_counties-1][number_counties-1];
double capacityFacility[number_counties-1][MaxNumberFacility2];
double fixedFacilityCost[number_counties-1][MaxNumberFacility2];
double openFacilityCost[number_counties-1][MaxNumberFacility2];
double closeFacilityCost[number_counties-1][MaxNumberFacility2];
double demand[number_counties-1][TforOpt];
double supply[number_counties-1];
double y_values[TforOpt][number_counties-1][MaxNumberFacility2];
double xx_values[TforOpt][number_counties-1][number_counties-1];
//INITIAL VALUES FOR OPTIMIZATION
double initial_inventory[number_counties-1];
int initial_y[(int)(maxNumOfDaysForOpt/periodlength)+1][number_counties-1][MaxNumberFacility2];
int familysize;
int additionalruns;
//FOR IMPROVING THE CODE
int supplynodes;
int facilitynodes;
int originalsupplycountyindex[number_counties-1];
int originalfacilitycountyindex[number_counties-1];
 
 
 
 
#ifdef SINGLE_SEED
const int gc_iInitialNumSeeds = 1;
#else
const int gc_iInitialNumSeeds = 0;
#endif
 
//Seasonality Declarations & Parameters DPS
void SummerDates(double);
double UserFOIFactor;
int g_dFirstSummer;
int FOIFactor = 1;
 
// Disease Progression Parameters CHANGED DP
const double gc_dMeanExpDuration = 7.94; /* also see line 373 which defines exposedduration as fcn of meanpresymduration */ 
const double gc_dStdDevExpDuration = 1.32,  gc_dMeanHospDuration = 14, gc_dMeanPresymDuration = 4.0;
const double gc_dProbSymptoms = 1.00, gc_dProbDeath = 0.14, gc_dProbHospitalization = 0.06, gc_dSymAsymDurationRatio = 5.0/3;//DP need to find if ProbDeath is for a one age group and scaled for other age groups
 
// Disease Transmission Parameters
// Base Case
double g_dTheta = 0.3, g_dOmega = 0.5*g_dTheta, g_dGamma = 0.7, g_dDelta = 0.5;
double g_dProbSymActiveChildren = 0, g_dProbSymActiveAdults = 0.5;
double g_dBeta = 0.875, g_dR0 = 15, g_dInfHazardCommunityTotal = 0.0;
double g_dInfHazardPeerGroupAdults = 0.037, g_dInfHazardPeerGroupChildren = g_dInfHazardPeerGroupAdults, gc_dInfHazardHousehold = 1.0;
double g_dInfHazardPresym = 0.6544, g_dInfHazardAsym = 0.2237, g_dInfHazardSym = 1.0;
double g_dMeanSymDuration = 4.0, g_dMeanAsymDuration = g_dMeanSymDuration/gc_dSymAsymDurationRatio;
 
double g_dRelativeR0Isolation = 1, g_dBetaIsolation = g_dRelativeR0Isolation*g_dR0/(g_dMeanSymDuration+gc_dProbHospitalization*gc_dMeanHospDuration);
 
// Intervention Parameters
const short gc_iMaxRiskIndex = 3;
const double gc_dTestSensitivity = 0.9, gc_dTestSpecificity = 1.0;
double g_dProbComplianceDrugs = 0.5, g_dProbComplianceNoDrugs = g_dProbComplianceDrugs, g_dProbIsolation = 0.5;
double g_dProbCompliance = g_dProbComplianceNoDrugs, g_dProbReport = g_dProbCompliance;
const double gc_dSusHazardDrug = 0.3, gc_dInfHazardDrug = 0.69, gc_dMeanNumContactNamed = 5;
double g_dSusHazardHouseholdQuarantine = pow(2.0, 0.5), g_dInfHazardHouseholdQuarantine = g_dSusHazardHouseholdQuarantine;
const double gc_dSusHazardPeerGroupQuarantine = 0.25, gc_dInfHazardPeerGroupQuarantine = 0.25;
const double gc_dIsolationClock = 3, gc_dQuarantineClock = 7, gc_dMaxCTListDuration = 5;
const int gc_iMaxNumCTServers = 10000000, gc_iMaxNumTestServers = static_cast<int>(1e6*4000.0/gc_iHKPopulationSize*gc_iPopulationSizeTotal);
const double gc_dMeanTraceDuration = 1, gc_dMeanTestDuration = 1.5, gc_dMeanRetestDuration = 4;
double g_dMeanIsolationDelay = 1, g_dMeanDrugDelay = 1;
 
// Stress Parameters
#ifdef IMPORT
const double gc_dUnimodalImportPeak = 270, gc_dFlatImportRate = 100.0, gc_dSpamRate = 5000.0/gc_iHKPopulationSize;
#else
const double gc_dUnimodalImportPeak = 0, gc_dFlatImportRate = 0, gc_dSpamRate = 0;
#endif
const double gc_dMeanSpamDuration = 3;
 
const double 
gc_dSmallestInfectivity = MAX(1e-7, g_dBeta*g_dInfHazardPeerGroupAdults*g_dInfHazardAsym*gc_dInfHazardPeerGroupQuarantine*gc_dInfHazardDrug/10.0),//MAX(tiny# OR (0.875*0.037*0.2237*0.25*0.69)/10)=0.000124929459)
gc_dSmallestSusceptibility = MAX(1e-7, gc_dSusHazardPeerGroupQuarantine*gc_dSusHazardDrug/10.0), //MAX(tiny# OR (.25*.3)/10=0.0075
gc_dSmallestFOI = MAX(1e-7, gc_dSmallestInfectivity*gc_dSmallestSusceptibility);//MAX(tiny# OR (0.0075*0.000124929459)
 
//#ifdef CHECK_TARGETS
int g_iSelectedSeed, g_iNumInfecteesBySeed[3][3];
double g_dTg;
//#endif
 
inline int Round(const double x){return static_cast<int>(floor(x+0.5));}
inline double Probability() {return nag_random_continuous_uniform();} //UNIFORM DRAW used a ton with if then to make decisions based on draws from distributions
inline double ExponentialDeviate(const double a){ return nag_random_exp(a);}//EXPONENTIAL DRAW
 
inline int PoissonDeviate(const double a)
{
	int dDeviate;
	double *r;
	nag_ref_vec_poisson(a, &r, NULL);
	dDeviate = nag_return_discrete(r);
	NAG_FREE(r);
	return dDeviate;
}
 
inline double ExposedDuration()
{
	return 4.0+pow(-1.25*log(nag_random_continuous_uniform()), 1.0/2.2012)-gc_dMeanPresymDuration;//CHANGED DP
	/* nag_random_continuous_uniform returns a pseudo-random number taken from a uniform distribution between 0 and 1
		therefore exposedDuration = 0.5 plus some pos number between 0 and infinity to the power of approx 0.45 minus meanPresymDur */
	/* purpose of the 0.5 (same as original meanPreSymDuration for flu) out front seems to be to keep ExposedDuration Positive so changed to 4.0 */
	/* nag_random_... redefined around line 32 presumably because psuedo random isn't good enough */
}
inline double PresymptomaticDuration() {return ExponentialDeviate(gc_dMeanPresymDuration);}//CHANGED DP Missing Exponential Deviate
inline double AsymptomaticDuration() {return ExponentialDeviate(g_dMeanAsymDuration);}
//exponentialDeviate simply draws a number for a exp'l distrib'n with mean given by the param.
inline double SymptomaticDuration() {return ExponentialDeviate(g_dMeanSymDuration);}
 
inline double HospitalizationDuration() {return ExponentialDeviate(gc_dMeanHospDuration);}
inline int DiscreteUniformDeviate(const int a, const int b){ return nag_random_discrete_uniform(a, b);}
inline double ContinuousUniformDeviate(const double a, const double b){ return random_continuous_uniform_ab(a, b);}//DP2; does not work
inline int DiscreteUniformZeroDeviate(int a){ return nag_random_discrete_uniform(0, a-1);}
inline double SpamDuration() {return ExponentialDeviate(gc_dMeanSpamDuration);}
inline double TraceDuration() {return ExponentialDeviate(gc_dMeanTraceDuration);}
inline double TestDuration(){ return gc_dMeanTestDuration;}
inline double IsolationDelay() {return g_dMeanIsolationDelay;}
inline double DrugDelay() {return g_dMeanDrugDelay;}
 
inline bool IsEqual(const double x, const double y){ 
	if (fabs(x) < SMALLEST_DOUBLE && fabs(y) < SMALLEST_DOUBLE)
		return true;
	else if (fabs(x) < SMALLEST_DOUBLE)
	{
		if (fabs(y) > SMALLEST_DOUBLE)
			return false;
		return true;
	}
	else if (fabs(y) < SMALLEST_DOUBLE)
	{
		if (fabs(x) > SMALLEST_DOUBLE)
			return false;
		return true;
	}
	else if (fabs(1-x/y) > IS_EQUAL_MARGIN)
		return false;
	else
		return true;
}
 
 
 
//a type denotes a data structure and the meanings of operations that make sense for that data structure
template<class ElementType, class CounterType>//template header tells implementation we are defining a "template fcn" below this header and that the fcn will take a "type parameter"
//type parameters are like fcn parameters: they define names that can be used within the scope of the fcn; however, type parameters refer to types, not to variables; wherever ElementType and CounterType appear in the fcn, the implementation will assume that ElementType and CounterType name "types"
class CMySet
{
private:
	CounterType m_iCurrentSize, m_iMaxSize;
	ElementType* m_cMember;
public:
	CMySet()//"default constructor"
	{ 
		m_iCurrentSize = 0;
		m_iMaxSize = 2;
		m_cMember = new ElementType[m_iMaxSize];
	}
	
	CMySet(const CounterType iInitialSize)//"constructor" w/ arguments
	{ 
		m_iCurrentSize = 0;
		m_iMaxSize = (CounterType) MAX(2, iInitialSize);
		m_cMember = new ElementType[m_iMaxSize];
	}
 
	CMySet(const CMySet& other)//DP2 08-13-08
	{ 
        m_iCurrentSize = other.m_iCurrentSize;
        m_iMaxSize     = other.m_iMaxSize;
        m_cMember      = new ElementType[m_iMaxSize];
        std::copy(other.m_cMember, other.m_cMember+m_iMaxSize-1, m_cMember);
    }
 
	~CMySet(){ delete [] m_cMember;}
 
	void Initialize()
	{
		m_iCurrentSize = 0;
		m_iMaxSize = 2;
		m_cMember = new ElementType[m_iMaxSize];
	}
 
	CMySet<ElementType, CounterType>& operator=(CMySet<ElementType, CounterType>& rhs)
	{
		//(*this).Clear();
		(*this).Resize(rhs.Size());
		for (CounterType iCounter = 0; iCounter < rhs.Size(); ++iCounter)
			(*this).Push(rhs[iCounter]);
		return *this;
	}
 
	ElementType& operator[](const CounterType iIndex) const
	{
		return m_cMember[iIndex];
	}
 
	int Find(const ElementType cTarget)//use to create removefromlistfcn
	{
		for (CounterType iCounter = 0; iCounter < m_iCurrentSize; ++iCounter)
		{
			if (m_cMember[iCounter] == cTarget){//compares two pointers to the IDs in the vector and if there's a match returns the !index!
				cout << "Individual to be removed found. cTarget = " << cTarget << "; iCounter = " << iCounter << endl;
				return iCounter;
			}
		}
		return -1;
	}
 
	bool Empty()
	{
		if (m_iCurrentSize == 0)
			return true;
		return false;
	}
 
	int GetMaxSize(){ return m_iMaxSize;}
	void Pop(){ m_iCurrentSize--;}
	ElementType Top(){ return m_cMember[m_iCurrentSize-1];}
	int Size(){	return m_iCurrentSize; }
	void Clear(){ m_iCurrentSize = 0;}
 
	int Push(const ElementType cTarget)//cTarget here is the individual id 
	{
		// input: object to be inserted
		// output: position of insertion
		if (m_iCurrentSize == m_iMaxSize){//allocate more memory if at maxSize
			ElementType *pElement;
			m_iMaxSize = (CounterType) MAX(m_iMaxSize+1, m_iMaxSize*1.1);
			pElement = new ElementType[m_iMaxSize];
			for (CounterType iCounter = 0; iCounter < m_iCurrentSize; ++iCounter)
				pElement[iCounter] = m_cMember[iCounter];
			delete [] m_cMember;
			m_cMember = pElement;
		}
		//cout << "cTarget: " << cTarget << endl;
		cout << "Size: " << m_iCurrentSize << endl;
		m_cMember[m_iCurrentSize++] = cTarget;//otherwisemake
		return m_iCurrentSize-1;  
	}
 
	ElementType Erase(const CounterType iIndex)
	{
		// input: position of removal
		// output: object that replaces the object removed
		if (iIndex < 0 || iIndex > m_iCurrentSize-1)
		{
			cout << "Error in CMySet::Erase" << endl;
			exit(0);
		}
		m_cMember[iIndex] = m_cMember[--m_iCurrentSize];//This is super elegant; no need to move things around. Just take the last element and use it to replace the one you want to get rid of; no need to erase the last element beausee it'll be ignored b/c won't search past the current m_icurrentsize
	}
 
	void Resize(const CounterType iSize)
	{
		m_iCurrentSize = 0;
		m_iMaxSize = (CounterType) MAX(2, iSize);
		delete [] m_cMember;
		m_cMember = new ElementType[m_iMaxSize];
	}
};
 
class CFOIEngineElement
{
private:
	double m_dFOI;
	CMySet<int, unsigned int> *m_pInfectorGroup;
public:
	CFOIEngineElement(): m_dFOI(0), m_pInfectorGroup(NULL){}
	CFOIEngineElement(double x, CMySet<int, unsigned int> *y): m_dFOI(x), m_pInfectorGroup(y){}
	CFOIEngineElement(CFOIEngineElement &e): m_dFOI(e.m_dFOI), m_pInfectorGroup(e.m_pInfectorGroup) {}  // copy constructor
	~CFOIEngineElement(){};
	double GetFOI() { return m_dFOI;}
	CMySet<int, unsigned int> *GetPtrInfectorGroup() { return m_pInfectorGroup;}
	void SetFOI(const double x) { m_dFOI = x;}
	void SetPtrInfectorGroup(CMySet<int, unsigned int> *x) { m_pInfectorGroup = x;}
};
 
class CFOIPerturbedListElement
{
private:
	int m_iID;
	double m_dOldFOI;
public:
	CFOIPerturbedListElement(): m_iID(-1), m_dOldFOI(0) {}
	CFOIPerturbedListElement(int x, double y): m_iID(x), m_dOldFOI(y) {}
	~CFOIPerturbedListElement(){};
	int GetID(){ return m_iID;}
	double GetOldFOI(){ return m_dOldFOI;}
};
 
 
#ifdef HISTORY
// History m_iEvents
enum HistoryEvent {StoE, PtoA, AtoR, EtoP, PtoI, ItoR, ItoH, HtoD, HtoR, Report, QuaLead, QuaFollow, QuaExtend, QuaRelease, 
IsoVol, IsoForced, IsoRelease, IsoExtend, NoEvent}; 
#endif
 
inline void Pause() { 
	cout << "Press ENTER to continue" << endl;
	getchar();
}
 
// Each entry in the EventList is an EventListRecord object
#ifdef HISTORY
class CHistoryRecord
{
private: 
	HistoryEvent m_iEvent;
	double m_dTime;
	short m_iDiseaseStatus;
	bool m_bIsolationStatus, m_bQuarantineStatus, m_bComplianceStatus;
public:
	CHistoryRecord(): m_dTime(LARGE_NUMBER), m_iEvent(NoEvent), m_iDiseaseStatus(SUSCEPTIBLE), m_bIsolationStatus(false),
		m_bQuarantineStatus(false), m_bComplianceStatus(false){};
	CHistoryRecord(const double dtime, const HistoryEvent iEvent, const short iDiseaseStatus, const bool bIsolationStatus, 
		const bool bQuarantineStatus, const bool bComplianceStatus): m_dTime(dTime), m_iEvent(iEvent), m_iDiseaseStatus(iDiseaseStatus), 
		m_bIsolationStatus(bIsolationStatus),m_bQuarantineStatus(bQuarantineStatus), m_bComplianceStatus(bComplianceStatus){};
	CHistoryRecord(const HistoryRecord& e): m_dTime(e.m_dTime), m_iEvent(e.m_iEvent), m_iDiseaseStatus(e.m_iDiseaseStatus), 
		m_bIsolationStatus(e.m_bIsolationStatus), m_bQuarantineStatus(e.m_bQuarantineStatus), m_bComplianceStatus(e.m_bComplianceStatus){}; 
	~CHistoryRecord(){};
 
	friend bool operator<(const CHistoryRecord& x, const CHistoryRecord& y)
	{
		if (x.m_dTime < y.m_dTime)
			return true;
		else if(x.m_dTime > y.m_dTime)
			return false;   
		else 
		{
			if (x.m_iEvent < y.m_iEvent)
				return true;
			return false;
		}
	}
 
	friend ostream& operator<<(ostream& os, const CHistoryRecord& e)
	{
		string sEventName;
		switch (e.iEvent)
		{
		case StoE: sEventName ="StoE";
			break;
		case PtoA: sEventName ="PtoA";
			break;
		case EtoP: sEventName ="EtoP";
			break;
		case PtoI: sEventName ="PtoI";
			break;
		case ItoR: sEventName ="ItoR";
			break;
		case ItoH: sEventName ="ItoH";
			break;
		case HtoD: sEventName ="HtoD";
			break;
		case HtoR: sEventName ="HtoR";
			break;
		case AtoR: sEventName ="AtoR";
			break;
		case IsoVol: sEventName = "IsoVol";
			break;
		case IsoForced: sEventName = "IsoForced";
			break;
		case QuaLead: sEventName = "QuaLead";
			break;
		case QuaFollow: sEventName = "QuaFollow";
			break;
		case IsoExtend: sEventName = "IsoExtend";
			break;
		case QuaExtend: sEventName = "QuaExtend";
			break;
		case QuaRelease: sEventName = "QuaRelease";
			break;
		case IsoRelease: sEventName = "IsoRelease";
			break;
		case Report: sEventName = "Report";
			break;
		default: 
			{ 
				cout << endl << "Error: Unknown m_iEvent." << endl;
				exit(0);
			}
		}
		return os << setw(15) << e.m_dTime << setw(15) << sEventName << setw(5) << e.m_iDiseaseStatus << setw(5) << 
			e.m_bIsolationStatus << setw(5) << e.m_bQuarantineStatus << setw(5) << e.m_bComplianceStatus << endl;       
	}
};
#endif
 
class CEventListRecord 
{
private:
	int m_iID;
	short m_iEvent;
	double m_dTime;
public:
	CEventListRecord(): m_dTime(LARGE_NUMBER), m_iID(-1), m_iEvent(NO_EVENT) {}//"default (no arguments) constructor (no return type and same name as class)" ensures that EventListRecord object's data members are properly initialized
	//instantiate a non-event, very far in future, with nonsense iID (maybe to allocate memory for events)
	//The single semicolon initializes a member when a method is called. It's usually used to initialize constants in the constructor
	CEventListRecord(double dTime, int iID, short iEvent): m_dTime(dTime), m_iID(iID), m_iEvent(iEvent) {} //constructor called if time, individual, and event type are passed
	CEventListRecord(const CEventListRecord& e): m_dTime(e.m_dTime), m_iID(e.m_iID), m_iEvent(e.m_iEvent) {}//constructor called if eventListRecord is passed: pass attributes of existing eventListRecord into new eventListRecord object; used to update an event based on current event parameters
	~CEventListRecord(){}//when the tilde is used as the first character in a class's method name (where the rest of the name must be the same name as the class) to indicate a destructor - a special method which is called at the end of the object's life.
	void printt() { cout<<"PRINTING FROM CLASS\n"; }
	void Initialize()//CEventListRecord.Initialize called when a new event needs to be created!!!; except never found in .cpp!
	{
		m_dTime = LARGE_NUMBER;//LARGE-NUMBER = 1e10 def'd above
		m_iID = -1;
		m_iEvent = NO_EVENT;
	}
	short GetEvent(){return m_iEvent;}
	double GetTime() const{return m_dTime;}
	int GetID() const {return m_iID;}
 
	friend bool operator==(const CEventListRecord& x, const CEventListRecord& y)
	//checks if EventRecords x and y have the same individual, time, and event type
	// a class can allow non-member fcns to access private data by making them friends
 
	{
		if (IsEqual(x.m_dTime, y.m_dTime) == true && x.m_iID == y.m_iID && x.m_iEvent == y.m_iEvent)
			return true;
		return false;
	}
 
	friend bool operator<(const CEventListRecord& x, const CEventListRecord& y) // This is for priority queue;
	/* This is for comparing priority of events in main fcn; implementation will pass two arguments
	operator<() overloads (give special meanings to operators, when they are used with user-defined class) the < operator;
	says when operator < has operand CEventListRecord, run this code instead of simply comparing the left and right operand and returning true or false
	*/
 
	{
		if(x.m_dTime > y.m_dTime)//compare time of events
			return true;
		else if (x.m_dTime < y.m_dTime)
			return false;
		else
		{
			if (x.m_iID < y.m_iID)//if same time, then compare individual involved and type of event; if event has all three attributes the same, return false
				return true;
			else if (x.m_iID > y.m_iID)
				return false;
			else
			{
				if (x.m_iEvent < y.m_iEvent)
					return true;
				else if (x.m_iEvent > y.m_iEvent)
					return false;
				else
					return false;
			}
		}
	}
 
	friend ostream& operator<<(ostream& os, const CEventListRecord& e)
	{
		string sEventName;
		switch (e.m_iEvent)
		{
		case PROGRESSION: sEventName ="Progression";
			break;
		case NO_EVENT: sEventName = "No Event";
			break;
		case REPORT: sEventName = "Report";
			break;
		case QUARANTINE_RELEASE: sEventName = "Quarantine Release";
			break;
		case ISOLATION_RELEASE: sEventName = "Isolation Release";
			break;
		case MOVE_EVENT_LIST: sEventName = "Move EventList";
			break;
		default: 
			{
				cout << endl << "Error in printing EventList events: Unknown m_iEvent." << endl;
				exit(0);
			}
		}
		return os << sEventName << " for Individual " << e.m_iID << " at time " << e.m_dTime << endl;        
	}    
};
 
#ifdef CONTACT_TRACING
class CCTRecord
{
private:
	int m_iID;  
	float m_dCTRecordTime;
public:
	CCTRecord(const int x, const float y):  m_iID(x), m_dCTRecordTime(y) {}
	CCTRecord(const CCTRecord& c): m_iID(c.m_iID), m_dCTRecordTime(c.m_dCTRecordTime) {} // copy constructor    
	~CCTRecord(){}; // destructor
	int GetID() const { return m_iID;} 
	float GetCTRecordTime() const {return m_dCTRecordTime;}
	friend bool operator ==(const CCTRecord& x, const CCTRecord& y)
	{
		if (x.m_iID == y.m_iID && x.m_dCTRecordTime == y.m_dCTRecordTime)
			return true;
		return false;
	}
};
#endif
 
 
 
class CIndividual
{
private:
	int m_iID, m_iHouseholdID, m_iPeerGroupID, m_iCountyID;
	double m_iAge;//DP2
	int m_iAgeGroup;//DP2
	short m_iDiseaseStatus;
	float m_dTimeRecord;
	bool m_bAdultStatus, m_bSpamStatus, m_bComplianceStatus, m_bQuarantineStatus, m_bIsolationStatus,
		m_bImmuneStatus, m_bLeadStatus, m_bPeerGroupActive, m_bDrugStatus;
#ifdef SYMPTOMS_DESTINED
	bool m_bWillBeSymptomatic;
#endif
#ifdef TESTING
	bool m_bTestListStatus, m_bTestActive, m_bTestResult;
#endif
#ifdef CONTACT_TRACING 
	bool m_bCTListStatus, m_bCTActive, m_bCTInterviewed;
	short m_iCTMultiplicity;
	CMySet<short, unsigned short> m_cContactIndexList;
#endif
#ifdef DURATION_DETAILS
	short m_iQuarantineTimes, m_iIsolationTimes, m_iTotalQuarantineDuration, m_iTotalIsolationDuration;  // total number of times an individual was quarantined over the course of the epidemic
	float m_dQuarantineEntryTime, m_dIsolationEntryTime;
#endif
#ifdef HISTORY
	vector<cHistoryRecord> m_cHistory;
#endif
 
public:
 
 
	CIndividual& operator=(CIndividual& y)
	/*	&y is a reference: means the class CIndiv is the type for any of the variables that are referenced by what follows 
		operator= overloads the = operator (give special meanings to operators, when they are used with user-defined class CIndividual)
		The ampersand operator between the data type and the variable name can assume one of three positions as follows: 
			int& nbr;
			int & nbr;
			int &nbr;
		As long as the & symbol is between a valid data type and a variable name, the compiler knows that the variable name (in this case Nbr) is a reference. 
	*/
	{
		m_iID = y.m_iID;
		m_iAge = y.m_iAge;//DP2 Add reference LATER
		m_iAgeGroup = y.m_iAgeGroup;
		m_iHouseholdID = y.m_iHouseholdID;
		m_iPeerGroupID = y.m_iPeerGroupID;
		m_iCountyID = y.m_iCountyID;
		m_iDiseaseStatus = y.m_iDiseaseStatus;
		m_dTimeRecord = y.m_dTimeRecord;
		m_bAdultStatus = y.m_bAdultStatus;
		m_bDrugStatus =  y.m_bDrugStatus;
 
		m_bSpamStatus = y.m_bSpamStatus;
		m_bComplianceStatus = y.m_bComplianceStatus;
		m_bQuarantineStatus = y.m_bQuarantineStatus;
		m_bIsolationStatus = y.m_bIsolationStatus;
		m_bImmuneStatus = y.m_bImmuneStatus;
		m_bLeadStatus = y.m_bLeadStatus;
		m_bPeerGroupActive = y.m_bPeerGroupActive;
#ifdef SYMPTOMS_DESTINED
		m_bWillBeSymptomatic = y.m_bWillBeSymptomatic;
#endif
 
#ifdef TESTING
		m_bTestListStatus = y.m_bTestListStatus;
		m_bTestActive = y.m_bTestActive;
		m_bTestResult = y.m_bTestResult;
#endif
 
#ifdef CONTACT_TRACING 
		m_bCTListStatus = y.m_bCTListStatus;
		m_bCTActive = y.m_bCTActive;
		m_bCTInterviewed = y.m_bCTInterviewed;
		m_iCTMultiplicity = y.m_iCTMultiplicity;
#endif
 
#ifdef DURATION_DETAILS
		m_iQuarantineTimes = y.m_iQuarantineTimes;  // total number of times an individual was quarantined over the course of the epidemic
		m_iIsolationTimes = y.m_iIsolationTimes;
		m_dQuarantineEntryTime = y.m_dQuarantineEntryTime;
		m_dIsolationEntryTime = y.m_dIsolationEntryTime;
#endif
		return *this;
	}
 
	void Print()
	{
		cout << "m_iID: " << m_iID << endl;
		cout <<	"m_iAge " << m_iAge << endl;//DP
		cout << "m_iAgeGroup" << m_iAgeGroup << endl;
		cout << "m_iHouseholdID: " << m_iHouseholdID << endl;
		cout << "m_iPeerGroupID: " << m_iPeerGroupID << endl;
		cout << "m_iCountyID: " << m_iCountyID << endl;
		cout << "m_iDiseaseStatus: " << m_iDiseaseStatus << endl;
		cout << "m_dTimeRecord: " << m_dTimeRecord << endl;
		cout << "m_bAdultStatus: " << m_bAdultStatus << endl;	
		cout << "m_bSpamStatus: " << m_bSpamStatus << endl;	
		cout << "m_bComplianceStatus: " << m_bComplianceStatus << endl;
		cout << "m_bQuarantineStatus: " << m_bQuarantineStatus << endl;
		cout << "m_bIsolationStatus: " << m_bIsolationStatus << endl;
		cout << "m_bImmuneStatus: " << m_bImmuneStatus << endl;	
		cout << "m_bLeadStatus: " << m_bLeadStatus << endl;	
		cout << "x.m_bPeerGroupActive: " << m_bPeerGroupActive << endl;
		return;
	}
	friend bool operator ==(const CIndividual& x, const CIndividual& y)
	{
		if (x.m_iID != y.m_iID)
			cout << "m_iID: " << x.m_iID << " " << y.m_iID << endl;
		if (x.m_iAge != y.m_iAge)
			cout << "m_iAge: " << x.m_iAge << " " << y.m_iAge << endl;//DP2
		if (x.m_iAgeGroup != y.m_iAgeGroup)
			cout << "m_iAgeGroup: " << x.m_iAgeGroup << " " << y.m_iAgeGroup << endl;
		if (x.m_iHouseholdID != y.m_iHouseholdID)
			cout << "m_iHouseholdID: " << x.m_iHouseholdID << " " << y.m_iHouseholdID << endl;
		if (x.m_iPeerGroupID != y.m_iPeerGroupID)
			cout << "m_iPeerGroupID: " << x.m_iPeerGroupID << " " << y.m_iPeerGroupID << endl;
		if (x.m_iCountyID != y.m_iCountyID)
			cout << "m_iCountyID: " << x.m_iCountyID << " " << y.m_iPeerGroupID << endl;
		if (x.m_iDiseaseStatus != y.m_iDiseaseStatus)
			cout << "m_iDiseaseStatus: " << x.m_iDiseaseStatus << " " << y.m_iDiseaseStatus << endl;
		if (x.m_dTimeRecord != y.m_dTimeRecord)
			cout << "m_dTimeRecord: " << x.m_dTimeRecord << " " << y.m_dTimeRecord << endl;
		if (x.m_bAdultStatus != y.m_bAdultStatus)
			cout << "m_bAdultStatus: " << x.m_bAdultStatus << " " << y.m_bAdultStatus << endl;
		if (x.m_bSpamStatus != y.m_bSpamStatus)
			cout << "m_bSpamStatus: " << x.m_bSpamStatus << " " << y.m_bSpamStatus << endl;
		if (x.m_bComplianceStatus != y.m_bComplianceStatus)
			cout << "m_bComplianceStatus: " << x.m_bComplianceStatus << " " << y.m_bComplianceStatus << endl;
		if (x.m_bQuarantineStatus != y.m_bQuarantineStatus)
			cout << "m_bQuarantineStatus: " << x.m_bQuarantineStatus << " " << y.m_bQuarantineStatus << endl;
		if (x.m_bIsolationStatus != y.m_bIsolationStatus)
			cout << "m_bIsolationStatus: " << x.m_bIsolationStatus << " " << y.m_bIsolationStatus << endl;
		if (x.m_bImmuneStatus != y.m_bImmuneStatus)
			cout << "m_bImmuneStatus: " << x.m_bImmuneStatus << " " << y.m_bImmuneStatus << endl;
		if (x.m_bLeadStatus != y.m_bLeadStatus)
			cout << "m_bLeadStatus: " << x.m_bLeadStatus << " " << y.m_bLeadStatus << endl;
		if (x.m_bPeerGroupActive != y.m_bPeerGroupActive)
			cout << "x.m_bPeerGroupActive: " << x.m_bPeerGroupActive << " " << y.m_bPeerGroupActive << endl;
		if (x.m_iID != y.m_iID || x.m_iAgeGroup != y.m_iAgeGroup || x.m_iHouseholdID != y.m_iHouseholdID || x.m_iPeerGroupID != y.m_iPeerGroupID || x.m_iCountyID != y.m_iCountyID ||
			x.m_iDiseaseStatus != y.m_iDiseaseStatus || x.m_dTimeRecord != y.m_dTimeRecord || x.m_bAdultStatus != y.m_bAdultStatus ||
			x.m_bSpamStatus != y.m_bSpamStatus || x.m_bComplianceStatus != y.m_bComplianceStatus || x.m_bQuarantineStatus != y.m_bQuarantineStatus ||
			x.m_bIsolationStatus != y.m_bIsolationStatus || x.m_bImmuneStatus != y.m_bImmuneStatus || x.m_bLeadStatus != y.m_bLeadStatus ||  
			x.m_bPeerGroupActive != y.m_bPeerGroupActive)
			return false;
#ifdef SYMPTOMS_DESTINED
		if (x.m_bWillBeSymptomatic != y.m_bWillBeSymptomatic)
			return false;
#endif
 
#ifdef TESTING
		if (x.m_bTestListStatus != y.m_bTestListStatus || x.m_bTestActive != y.m_bTestActive || x.m_bTestResult != y.m_bTestResult)
			return false;
#endif
 
#ifdef CONTACT_TRACING 
		if (x.m_bCTListStatus != y.m_bCTListStatus || x.m_bCTActive != y.m_bCTActive || x.m_bCTInterviewed != y.m_bCTInterviewed || 
			x.m_iCTMultiplicity != y.m_iCTMultiplicity)
			return false;
#endif
		return true;
	}
 
	void Initialize(const int x)//called in line 5427 of main function when allocating memory for all individuals in pop
	{    
		m_iHouseholdID = -1;
		m_iPeerGroupID = -1;
		m_iCountyID = -1;
		m_iAge = -1;//DP2
		m_iAgeGroup = -1;
		Reset(x);
	}   
 
	void Reset(const int x)//called in line 6392 at top of each realization/policy
	{
		m_iID = x;
		m_dTimeRecord = LARGE_NUMBER;
		m_iDiseaseStatus = SUSCEPTIBLE;
		m_bQuarantineStatus = false;
		m_bComplianceStatus = false;
		m_bLeadStatus = false;
		m_bSpamStatus = false;
		m_bIsolationStatus = false;
		m_bImmuneStatus = false;
		m_bPeerGroupActive = true;
		m_bDrugStatus = false;
 
#ifdef SYMPTOMS_DESTINED
		m_bWillBeSymptomatic = false;
#endif
 
#ifdef TESTING
		//m_bTestListStatus = false;
		m_bTestActive = false;
		m_bTestResult = false;
#endif
 
#ifdef CONTACT_TRACING
		m_cContactIndexList.Clear();
		m_bCTActive = false;
		m_bCTListStatus = false;
		m_iCTMultiplicity = 0;
		m_bCTInterviewed = false;
#endif
 
#ifdef DURATION_DETAILS
		m_iQuarantineTimes = 0;
		m_iIsolationTimes = 0;
		m_dQuarantineEntryTime = LARGE_NUMBER;
		m_dIsolationEntryTime = LARGE_NUMBER;
		m_iTotalQuarantineDuration = 0;
		m_iTotalIsolationDuration = 0;
#endif
#ifdef HISTORY
		m_cHistory.clear();
#endif
	}
 
#ifdef SYMPTOMS_DESTINED
	bool GetWillBeSymptomatic(){ return m_bWillBeSymptomatic;}
#endif
	bool GetHouseholdActiveStatus()
	{
		if (m_iDiseaseStatus == DEAD || m_bIsolationStatus == true)
			return false;
		return true;
	}
 
	int GetID(){ return m_iID;}
	void SetTimeRecord(const float x){ m_dTimeRecord = x;}
	float GetTimeRecord(){ return m_dTimeRecord;}
	bool GetAdultStatus(){ return m_bAdultStatus;}
	bool GetQuarantineStatus(){ return m_bQuarantineStatus;}
	bool GetComplianceStatus(){ return m_bComplianceStatus;}
	bool GetIsolationStatus(){ return m_bIsolationStatus;}
	bool GetImmuneStatus(){ return m_bImmuneStatus;}
	short GetDiseaseStatus(){ return m_iDiseaseStatus;} 
	bool GetSymptomsStatus()
	{
		if (m_iDiseaseStatus == SYMPTOMATIC || m_iDiseaseStatus == HOSPITALIZED || m_bSpamStatus == true)
			return true;
		return false;
	}
	bool GetFluStatus()
	{
		if (m_iDiseaseStatus == PRESYMPTOMATIC || m_iDiseaseStatus == ASYMPTOMATIC  || 
			m_iDiseaseStatus == SYMPTOMATIC || m_iDiseaseStatus == HOSPITALIZED)
			return true;
		return false;
	}
//	void SetPeerGroupActive(const bool x){m_bPeerGroupActive = x;}
	bool GetSpamStatus(){ return m_bSpamStatus;}
	void SetSpamStatus(const bool x){ m_bSpamStatus = x;}
	void SetPeerGroupActive(const bool x);
	void SetLeadStatus(const bool x){ m_bLeadStatus = x;}
#ifdef TESTING
	void TakeTest();
	void Retest();
	void CheckTestResult();
	bool GetTestActive(){ return m_bTestActive;}
	void SetTestActive(const bool x){ m_bTestActive = x;}
	bool GetTestResult(){ return m_bTestResult;}
	void SetTestResult(const bool x){ m_bTestResult = x;}
#endif
 
double GetInfectivity(const int iGroupType)
{
 
#ifdef CHECK_TARGETS
		if (m_iID != g_iSelectedSeed)
			return 0;
#endif
		if (m_iDiseaseStatus == SUSCEPTIBLE || m_bIsolationStatus == true)
			return 0;
		if (iGroupType == PEERGROUP && m_bPeerGroupActive == false)
			return 0;
 
		double dInfectivity = g_dAgeBeta[m_iAgeGroup];
		switch (m_iDiseaseStatus)
		{
		case PRESYMPTOMATIC: 
			dInfectivity *= g_dAgeInfHazardPresym[m_iAgeGroup];
			break;
		case ASYMPTOMATIC:
			dInfectivity *= g_dAgeInfHazardAsym[m_iAgeGroup];
			break;
		case SYMPTOMATIC:
			dInfectivity *= g_dAgeInfHazardSym[m_iAgeGroup];
			break;
		case HOSPITALIZED:
			dInfectivity *= g_dAgeInfHazardSym[m_iAgeGroup];
			break;
		default:
			return 0;
		}
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
		{
			// 999if (g_bDrugActive == true)
			if (m_bDrugStatus == true)
				dInfectivity *= gc_dInfHazardDrug;
			if (iGroupType == HOUSEHOLD)
				dInfectivity *= g_dInfHazardHouseholdQuarantine;
			else if (iGroupType == PEERGROUP)
				dInfectivity *= gc_dInfHazardPeerGroupQuarantine;
		}
		return dInfectivity;
	}
 
	double GetSusceptibility(const int iGroupType)
	{
		if (m_iDiseaseStatus != SUSCEPTIBLE || m_bIsolationStatus == true)//error check: person must be susceptible (and not be isolated)
			return 0;
		if (iGroupType == PEERGROUP && m_bPeerGroupActive == false)//error check
			return 0;
//		double dSusceptibility = 1.0;
		double dSusceptibility = dAgeSusceptibility[m_iAgeGroup];//GetSusc just returns constant from array
		if (m_bQuarantineStatus == true && m_bComplianceStatus == true)
		{
			// 999if (g_bDrugActive == true)
			if (m_bDrugStatus == true)
				dSusceptibility *= gc_dSusHazardDrug;
			if (iGroupType == HOUSEHOLD)
				dSusceptibility *= g_dSusHazardHouseholdQuarantine;//mult HH by a factor if quarantined
			else if (iGroupType == PEERGROUP)
				dSusceptibility *= gc_dSusHazardPeerGroupQuarantine;//mult PG by a factor if quarantined
		}
		return dSusceptibility;
	}
 
//this is the key set of functions that are called from BuildNetwork
	int GetHouseholdID(){ return m_iHouseholdID;}
	int GetPeerGroupID(){ return m_iPeerGroupID;}
	int GetCountyID(){ return m_iCountyID;}//mis-named; actually gets ct id
	int GetAgeGroup(){ return m_iAgeGroup;}//fcn that return age group attribute of this person (m_iAgeGroup???)
	void SetAdultStatus(const bool x){ m_bAdultStatus = x;}
	void SetAge(double iAge){ m_iAge = iAge;}//DP2 iAge is the number that's  passed when you call this fcn
	double GetAge(){ return m_iAge;}//DP2
	void SetAgeGroup(const int iAgeGroup){ m_iAgeGroup = iAgeGroup;}//fcn that sets agegroup to iAgeGroup; where iAgeGroup is the constant that's passed when you call this fcn
	void SetHouseholdID(const int iGroupID){ m_iHouseholdID = iGroupID;}
	void SetPeerGroupID(const int iGroupID){ m_iPeerGroupID = iGroupID;}
	void SetCountyID(const int iGroupID){ m_iCountyID = iGroupID;}
	void SetDiseaseState(const int iNewDiseaseStatus);
	void SusceptibleToExposed();
	void ExposedToPresymptomatic();
	void PresymptomaticToAsymptomatic();
	void PresymptomaticToSymptomatic();
	void AsymptomaticToRecovered();
	void SymptomaticToHospitalized();
	void SymptomaticToRecovered();
	void HospitalizedToRecovered();
	void HospitalizedToDead();
	void DiseaseProgression();
	void Isolation();
	void IsolationRelease();
	void Report();
	int GetHouseholdMember(const int iIndex);
	int GetPeerGroupMember(const int iIndex);
	void CheckQuarantineRelease();
	void QuarantineRelease();
	void Quarantine(bool x);
	void ActivateDrug();
	void UpdateFOI(double dOldInfectivity[], double dOldSusceptibility[]);
	bool IsQuarantinable()
	{
		if (m_bQuarantineStatus == false && m_bIsolationStatus == false && m_bImmuneStatus == false)
			return true;
		return false;
	}
 
// FOR INITIALIZATION PURPOSES
	void SusceptibleToExposed2();
	void SusceptibleToPresymptomatic2();
	void SusceptibleToAsymptomatic2();
	void SusceptibleToSymptomatic2();
	void SusceptibleToRecovered2();
	void SusceptibleToHospitalized2();
	void SusceptibleToDead2();
	void RecoveredToSusceptible();
 
#ifdef CONTACT_TRACING
	void ChangeCTMultiplicity(const int iDelta){ m_iCTMultiplicity += iDelta;}
	void AddedToCTList(const bool x);
	void RemovedFromCTList(const bool x);
	void ActivateTracing();
	void PushCTList();
	void SetCTActive(const bool x){ m_bCTActive = x;}
	bool GetCTActive(){ return m_bCTActive;}
	void SetDrugStatus(const bool x){ m_bDrugStatus = x;}
	bool GetDrugStatus(){ return m_bDrugStatus;}
	void TraceContacts();
	void Traced();
	bool FindFamilyMember(const int x);
	bool GetCTListStatus(){ return m_bCTListStatus;}
	void SetCTListStatus(const bool x){ m_bCTListStatus = x;}
	void ClearCTListRecord();
	bool GetHouseholdCTActive();
	int GetPeerGroupIndex()
	{
		for (int iCounter = 0; iCounter < GetPeerGroupSize(); ++iCounter)
		{
			if (GetPeerGroupMember(iCounter) == m_iID)
				return iCounter;
		}
		return -1;
	}
	void AddToContactIndexList(const int x)
	{ 
		if (m_cContactIndexList.Find(x) == -1)
			m_cContactIndexList.Push(x);
	}
	int GetContactListSize(){ return m_cContactIndexList.Size();}
#endif
	int GetHouseholdSize();
	int GetPeerGroupSize();
 
#ifdef DURATION_DETAILS
	void SetQuarantineTimes(const int x){ m_iQuarantineTimes = x;} 
	void SetIsolationTimes(const int x){ m_iIsolationTimes = x;} 
	void SetQuarantineEntryTime(const float x){ m_dQuarantineEntryTime = x;}
	void SetIsolationEntryTime(const float x){ m_dIsolationEntryTime = x;}
	short GetQuarantineTimes(){ return m_iQuarantineTimes;} 
	short GetIsolationTimes(){ return m_iIsolationTimes;} 
	float GetQuarantineEntryTime(){ return m_dQuarantineEntryTime;}
	float GetIsolationEntryTime(){ return m_dIsolationEntryTime;}
	short GetTotalQuarantineDuration(){ return m_iTotalQuarantineDuration;}
	short GetTotalIsolationDuration(){ return m_iTotalIsolationDuration;}
#endif
};
 
class CSocialGroup
{
private:
	short m_iGroupType;
	int m_iGroupID, m_iPosFOIEngine, m_iPosInfectorGroup;
	bool m_bFOIPerturbedStatus;
	CMySet<int, unsigned short> m_cMemberList;
	double m_dInfectivity, m_dSusceptibility;
public:
	CSocialGroup()
	{
		m_iGroupID = -1;
		m_iGroupType = -1;
		m_iPosFOIEngine = -1;
		m_iPosInfectorGroup = -1;
		m_bFOIPerturbedStatus = false;
		m_dInfectivity = 0;
		m_dSusceptibility = 0;
	}
	CSocialGroup(const int iGroupID)
	{
		m_iGroupID = iGroupID;
		m_iGroupType = -1;
		m_iPosFOIEngine = -1;
		m_iPosInfectorGroup = -1;
		m_bFOIPerturbedStatus = false;
		m_dInfectivity = 0;
		m_dSusceptibility = 0;
	}
 
	void SetGroupID(const int iGroupID){ m_iGroupID = iGroupID;}
	int GetGroupID(){ return m_iGroupID;}
	void SetGroupType(const short iGroupType){ m_iGroupType = iGroupType; }
	short GetGroupType(){ return m_iGroupType;}
 
	CMySet<int, unsigned short>& GetMemberList()
	{ 
		return m_cMemberList;
	}
 
 
	void Reset(const int ID)
	{
		m_iGroupID = ID;
		m_iPosFOIEngine = -1;
		m_iPosInfectorGroup = -1;
		m_bFOIPerturbedStatus = false;
		m_dInfectivity = 0;
		m_dSusceptibility = 0;
	}
 
	void PrintData()
	{
		cout << "GroupID = " << m_iGroupID << endl;
		cout << "MemeberListSize = " << m_cMemberList.Size() << endl;
		cout << "Infectivity = " << m_dInfectivity << ", Susceptibility = " << m_dSusceptibility << ", InfHazardGroup = " << GetInfHazardGroup() <<
			", FOIDenominator = " << GetFOIDenominator() << endl;
		cout << "FOI = " << ComputeFOI() << endl;
	}
 
	void SetPosFOIEngine(const int x){ m_iPosFOIEngine = x;}
	int GetPosFOIEngine(){ return m_iPosFOIEngine;}
	void SetPosInfectorGroup(const int x){ m_iPosInfectorGroup = x;}
	int GetPosInfectorGroup(){ return m_iPosInfectorGroup;}
 
	void ClearMemberList(){ m_cMemberList.Clear(); }
	void AddToMemberList(const int iIndividual){
		m_cMemberList.Push(iIndividual);
	}
	void RemoveFromMemberList(const int iIndividual){//DP3//This code is taking forever!!!!
		cout << "RemoveFromMemList called!" << endl;
		int iCounter = m_cMemberList.Find(iIndividual);
		cout << "Size: " << m_cMemberList.Size();
		cout << "iCounter " << iCounter << " erased." << endl;
		m_cMemberList.Erase(iCounter);
		
	}
	/*DELETE AFTER OCTOBER 1st DP3
	void RemoveFromMemberList(const int iIndividual){
		for (int iCounter = 0 ; iCounter < m_cMemberList.Size() ; iCounter++) {
			if( m_cMemberList[iCounter] == iIndividual) {
				m_cMemberList.Erase(m_cMemberList.begin()+iCounter, m_cMemberList.begin()+(iCounter+1));
			}
		}
	}
	
	void RemoveFromMemberList(const int iIndividualID){
		vector<int>::iterator new_end = remove(m_cMemberList.begin(), m_cMemberList.end(), iIndividualID);
	}
	*/
	void SetFOIPerturbedStatus(const bool x){ m_bFOIPerturbedStatus = x;}
	bool GetFOIPerturbedStatus(){ return m_bFOIPerturbedStatus;}
	double GetInfectivity(){ return m_dInfectivity;}
	double GetSusceptibility(){ return m_dSusceptibility;}
	double GetFOI(){ return m_dInfectivity*m_dSusceptibility/GetFOIDenominator()*GetInfHazardGroup();}
	double ComputeFOI(){ return ComputeInfectivity()*ComputeSusceptibility()/GetFOIDenominator()*GetInfHazardGroup();}
 
	virtual double GetInfHazardGroup(){ return 1.0;}
	virtual double GetFOIDenominator(){ return 1.0;}
 
	int SelectInfectee(const double dFOICutOff);//fcn declaration for SelectInfectee
 
	// Just fcn declarations
	double ComputeInfectivity();
	double ComputeSusceptibility();
	double ChangeInfectivity(const double dDelta);
	double ChangeSusceptibility(const double dDelta);
};
 
class CHousehold: public CSocialGroup
{
private:
	short m_iActiveHouseholdSize;
	float m_dQuarantineTime, m_dDrugTime;
#ifdef CONTACT_TRACING
	bool m_bHouseholdSeen;
#endif
#ifdef TESTING
	bool m_bTestActive;
#endif
#ifdef DURATION_DETAILS
	short m_iQuarantineTimes, m_iTotalQuarantineDuration;  // total number of times a household was quarantined over the course of the epidemic
	float m_dQuarantineEntryTime;
#endif
public:
	CHousehold()
	{
		SetGroupType(HOUSEHOLD);
		m_iActiveHouseholdSize = 0;
		m_dQuarantineTime = LARGE_NUMBER;
		m_dDrugTime = LARGE_NUMBER;
#ifdef CONTACT_TRACING
		m_bHouseholdSeen = false;
#endif
#ifdef TESTING
		m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
		m_iQuarantineTimes = 0;  // total number of times a household was quarantined over the course of the epidemic
		m_dQuarantineEntryTime = LARGE_NUMBER;
		m_iTotalQuarantineDuration = 0;
#endif
	}
	CHousehold(int iGroupID)
	{
		SetGroupID(iGroupID);
		SetGroupType(HOUSEHOLD);
		m_iActiveHouseholdSize = GetMemberList().Size();
		m_dQuarantineTime = LARGE_NUMBER;
		m_dDrugTime = LARGE_NUMBER;
#ifdef CONTACT_TRACING
		m_bHouseholdSeen = false;
#endif
#ifdef TESTING
		m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
		m_iQuarantineTimes = 0;  // total number of times a household was quarantined over the course of the epidemic
		m_dQuarantineEntryTime = LARGE_NUMBER;
		m_iTotalQuarantineDuration = 0;
#endif
	}
	~CHousehold(){}
 
	void HouseholdReset(const int ID)
	{
		Reset(ID);
		m_dQuarantineTime = LARGE_NUMBER;
		m_dDrugTime = LARGE_NUMBER;
		m_iActiveHouseholdSize = GetMemberList().Size();
#ifdef CONTACT_TRACING
		m_bHouseholdSeen = false;
#endif
#ifdef TESTING
		m_bTestActive = false;
#endif
#ifdef DURATION_DETAILS
		m_iQuarantineTimes = 0;
		m_dQuarantineEntryTime = LARGE_NUMBER;
		m_iTotalQuarantineDuration = 0;
#endif
	}
	int GetHouseholdSize();
	int GetPeerGroupSize();
	int GetNumAdults();
	void SetQuarantineTime(const float x){ m_dQuarantineTime = x;}
	float GetQuarantineTime(){ return m_dQuarantineTime;}
	void SetDrugTime(const float x){ m_dDrugTime = x;}
	float GetDrugTime(){ return m_dDrugTime;}
	bool GetHouseholdQuarantineStatus();
	bool GetHouseholdDrugStatus();
	int GetHouseholdQuarantineSize();
	double GetInfHazardGroup(){ return gc_dInfHazardHousehold; }
	double GetFOIDenominator(){ return MAX(1, static_cast<double>(m_iActiveHouseholdSize));}
	void ResetActiveHouseholdSize(){ m_iActiveHouseholdSize = GetMemberList().Size();}
	bool IsQuarantineReleasable();
	int ComputeActiveHouseholdSize();
	int GetActiveHouseholdSize(){ return m_iActiveHouseholdSize;}
	int ChangeActiveHouseholdSize(const int iDelta);
 
#ifdef CONTACT_TRACING
	void SetHouseholdSeen(const bool x){ m_bHouseholdSeen = x;}
	bool GetHouseholdSeen(){ return m_bHouseholdSeen;}
#endif
#ifdef TESTING
	bool GetTestActive(){ return m_bTestActive;}
	void SetTestActive(const bool x){ m_bTestActive = x;}
#endif
#ifdef DURATION_DETAILS
	void SetQuarantineTimes(const int x){ m_iQuarantineTimes = x;}  // total number of times a household was quarantined over the course of the epidemic
	void SetQuarantineEntryTime(const float x){ m_dQuarantineEntryTime = x;}
	void IncreaseQuarantineTimes(){ ++m_iQuarantineTimes;}
	short GetQuarantineTimes(){ return m_iQuarantineTimes;}  
	float GetQuarantineEntryTime(){ return m_dQuarantineEntryTime;}
	short GetTotalQuarantineDuration(){ return m_iTotalQuarantineDuration;}  
	void ChangeTotalQuarantineDuration(const int x){ m_iTotalQuarantineDuration += x; }
#endif
 
};
/*
In order to derive a class from another, we use a colon (:) in the declaration of the derived class using the following format: 
class derived_class_name: public base_class_name
{ ... };
Where derived_class_name is the name of the derived class and base_class_name is the name of the class on which it is based. 
*/
class CPeerGroup: public CSocialGroup
{
private:
 
	int m_iPeerGroupID, m_iCTOrCountyID, m_iAgeGroup;
	bool m_bAdultStatus;//Var. to differentiate btw CT and county level PGs; not currently used
 
public:
	CPeerGroup()
	{
		SetGroupType(PEERGROUP);
		SetPeerGroupID(-1);
		SetAgeGroup(-1);
		SetCTorCountyID(-1);
	}
 
	CPeerGroup(const int iGroupID)
	{
		SetGroupID(iGroupID);
		SetGroupType(PEERGROUP);
	}
	~CPeerGroup(){}
 
	int GetPeerGroupSize();
	double GetInfHazardGroup();
	double GetFOIDenominator(){ return 1.0;}
 
	// Assignment operator must take a const CPeerGroup
	// Needed for push_back a CPeerGroup to a std::vector
	CPeerGroup& operator=(const CPeerGroup& y)//DP2
	{
		m_iPeerGroupID = y.m_iPeerGroupID;
		m_iAgeGroup = y.m_iAgeGroup;
		m_bAdultStatus = y.m_bAdultStatus;//Not currently used
		
		return *this;
	}
 
	// DP2 block: std::find uses operater== and cannot operate without it
	bool operator==(const CPeerGroup& y)
	{
		return GetPeerGroupID() == y.GetPeerGroupID() && GetCTorCountyID() == y.GetCTorCountyID() && GetAgeGroup() == y.GetAgeGroup();
	}
 
	// These three "Get" methods must indicate they do not modify the instance
	// (hence are typed const) to satisfy (const CPeerGroup& y) argument to operator==
	int GetPeerGroupID()const { return m_iPeerGroupID;}//DP2
	int GetCTorCountyID() const { return m_iCTOrCountyID;}//DP2; mis-named; actually gets ct id
	int GetAgeGroup() const { return m_iAgeGroup;}//DP2; fcn that return age group attribute of this person (m_iAgeGroup???)
	void SetAgeGroup(const int iAgeGroup){ m_iAgeGroup = iAgeGroup;}//fcn that sets agegroup to iAgeGroup; where iAgeGroup is the constant that's passed when you call this fcn
	void SetPeerGroupID(const int iGroupID){ m_iPeerGroupID = iGroupID;}
	void SetCTorCountyID(const int iCTorCountyID){ m_iCTOrCountyID = iCTorCountyID;}//DP2
};
 
 
std::vector<CPeerGroup>& get_vector();
 
priority_queue<CEventListRecord> **g_pEventList;
//priority_queue<CEventListRecord> g_pEventList;
//**g_pEventList is the size but it's defined here and not initialized with any value.
CIndividual *g_cIndividual =NULL; //DP BIRTHS pointers! standard syntax for declaring a pointer: type *x 
CHousehold *g_cHousehold = NULL;
CPeerGroup *g_cPeerGroup = NULL;
 
 
int g_iNumGroups[] = {0, 0}, g_iMaxNumGroups[] = {0, 0};
int g_iCurrentEventList = 0;  // There's more than one EventList!!!
const int gc_iNumEventLists = static_cast<int>(100*gc_dTimeMax);//This var is CONSTANT (36,500)!!! so 100 eventLists per day. Am I exceeding this? Such an arbitrary number? So you can't just add events willy nilly without running an event. static cast for any normal conversion between types (need b/c timeMax not an int)
vector<CMySet<int, unsigned int>*> g_cFreePtrInfectorGroup;//what is the asterisk after the CMySet<> doing?
const int gc_iNumEngineSlots = static_cast<int>(10*pow(static_cast<double>(gc_iPopulationSizeTotal), 0.5));
double g_dTotalFOI[2], *g_dFOI[2];
CMySet<CFOIPerturbedListElement, unsigned int> *g_cFOIPerturbedList[2];
CMySet<CFOIEngineElement, unsigned int> *g_cFOIEngine[2];
CMySet<int, unsigned int> *g_cEmptyFOIEngineSlot[2];
//CMySet<int, unsigned int> g_cSusceptibleList, g_cSpamList;
 
 
#ifdef CONTACT_TRACING
deque<CCTRecord> g_cCTList;
#endif
time_t g_tClockStart, g_tClockStart2;
 
int g_iInfectionIncidence, g_iMaxInfectionIncidence;
int g_iNumQuarantined, g_iOldNumQuarantined, g_iMaxNumQuarantined, g_iQuarantineIncidence, g_iMaxQuarantineIncidence;
int g_iNumHouseholdsQuarantined, g_iMaxNumHouseholdsQuarantined,  g_iTotalNumHouseholdsQuarantined;
int g_iTotalNumHouseholdsQuarantineReleased, g_iDailyNumHouseholdsQuarantineReleased;
int g_iTotalNumQuarantined, g_iTotalNumQuarantineReleased, g_iDailyNumQuarantineReleased, g_iDisruptiveness, g_iMaxDisruptiveness;
int g_iNumIsolated, g_iOldNumIsolated, g_iMaxNumIsolated, g_iIsolationIncidence, g_iMaxIsolationIncidence;
int g_iTotalNumIsolated, g_iTotalNumIsolationReleased, g_iDailyNumIsolationReleased, g_iDailyLeakage, g_iTotalLeakage; 
double g_dTotalQuarantineDuration, g_dTotalIsolationDuration;
double g_dTotalDrugUsedQuarantineNonSymp, g_dTotalDrugUsedQuarantineSymp, g_dTotalDrugUsedQuarantineNonComp, g_dTotalDrugUsedIsolation;
double g_dDailyDrugUsedQuarantineNonSymp, g_dDailyDrugUsedQuarantineSymp, g_dDailyDrugUsedQuarantineNonComp, g_dDailyDrugUsedIsolation;
int g_iTotalNumImport, g_iTotalNumSpam, g_iMaxNumHospitalized;
int g_iNumActiveCTServers, g_iNumActiveTestServers, g_iNumCTRecordRemoved;
double g_dTotalCloseFOI, g_dOldTotalCloseFOI;
double g_dTimeToCloseInfection, g_dTimeToEventOnList;
double g_dTimeToCloseInfection1, g_dTimeToCloseInfection2;
int selected_group;
double g_dTimeResumeTesting;
 
//CENSUS
double g_dImportRate[NUM_CENSUS_TRACTS];
int SelectedCounty;
double g_dFOIImport[NUM_CENSUS_TRACTS], g_dFOICommunity[NUM_CENSUS_TRACTS], g_dInfHazardCommunity[NUM_CENSUS_TRACTS];
double g_dFOICommunityTotal, g_dFOIIsolationTotal, g_dTimeToNonCloseInfectionAndSpamMin;
double g_dFOIIsolation[NUM_CENSUS_TRACTS], g_dFOINonCloseAndSpam[NUM_CENSUS_TRACTS], g_dFOINonCloseAndSpamTotal;
double g_dTimeToNonCloseInfectionAndSpam[NUM_CENSUS_TRACTS];
 
int g_iHeadCount[NUM_DISEASE_STATES][2][2][2][NUM_CENSUS_TRACTS]; // g_iHeadCount[disease_status][quarantine_status][compliance_status][isolation_status][census_tract_info]
int g_iHeadCountTotal[NUM_DISEASE_STATES][2][2][2];
CMySet<int, unsigned int> g_cSusceptibleList[NUM_CENSUS_TRACTS], g_cSpamList[NUM_CENSUS_TRACTS];
 
//FOR BUILDING THE NETWORK
int temp;
double tempor;
int chosen1, chosen2;
int g_iNumClassrooms[4] = {0, 0, 0, 0}; // fermi - added the Pre-kindergarten Peer-Group
int g_iOldGroups = 0;
int g_iBabyGroups = 0;//Fermi
 
//tuba
string str= "resultstuba.txt"; 
ofstream sfile(str.c_str()); 
//tuba
 
bool g_bStopTesting;
int g_iEventCounter, g_iPrintCounter, g_iThresholdCounter, g_iNumTraced, g_iNumFOIUpdates;
ofstream g_ofTimeSeries[4], g_ofStat[2];
const int gc_iNumTimeSeries = 4,  gc_iNumStat = 2;
 
#ifdef CHECK_TARGETS
vector<double> g_cTimesInfection;
#endif
 
 
 
#ifdef DURATION_DETAILS
int g_iQuarantineDurationPDF[MAX_DURATION+1], g_iHouseholdQuarantineDurationPDF[MAX_DURATION+1], g_iIsolationDurationPDF[MAX_DURATION+1];
//int g_iQuarantineTimesPDF[MAX_QI_TIMES], g_iIsolationTimesPDF[MAX_QI_TIMES], g_iHouseholdQuarantineTimesPDF[MAX_QI_TIMES];
#endif

Open in new window

0
 
LVL 17

Accepted Solution

by:
sweetfa2 earned 500 total points
ID: 22736968
It looks like it may be based around it, but I am no CPLEX expert.

The quickest way to find out what is effected is to remove the reference in the makefile for your project.  Given that you are using Visual Studio there is a reference to the library somewhere in your project.  I am not sure of the quickest way to find it in VS, but that will then highlight what bits of code are using the library.  Then you can determine how much of it you really need.  Perhaps if you do a search of the directory for the path to the file you are missing it will show what files it is set in and you can then remove it from there.
0
 

Author Comment

by:ltdanp22
ID: 22737002
Is this the reference you're refering to?
#include <ilcplex/ilocplex.h>
I am not able to use Find All References on this line.
Daniel
0
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22737036
No, that is only the include file.  You can remove that and that will tell you what parts of the source file are using the library.

You also need to remove the reference to the concert.lib file as well, but that won;t be in the C or C++ files.  That will be in a makefile, which in VS will also be configured as an external resource or something similiar.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question