/*
TwoParameter.cpp

*/

#include "TwoParameter.h"


//Constructor
TwoParameter::TwoParameter(): daysContagious(7), likelihoodOfTransmission(.1) {}

//Destructor
TwoParameter::~TwoParameter(){}

//Menu
void TwoParameter::DisplayMenu(){
	cout << endl << "\t 2 Parameter Transmission Model" << endl;
	
	//Prompt user for the number of days an infected person remains contagious
	cout << "Please enter the number of days a location is contagious: ";
	cin >>  daysContagious;
	cout << endl;
	//input validation for daysContagious
	while(daysContagious < 0){
		cout << "Invaild Number of Contagious Days." << endl;
		cout << "Please enter the number of days a location is contagious: ";
		cin >>  daysContagious;
		cout << endl;
	}
	
	//Prompt user for liklihood (probability) of infection transmission
	cout << "Please enter the likelihood of transmission(0 to 1): ";
	cin >> likelihoodOfTransmission;
	cout << endl;
	//input validation for likelihood of transmission
	while(likelihoodOfTransmission < 0 || likelihoodOfTransmission > 1){
		cout << "Invaild likelihood of transmission." << endl;
		cout << "Please enter the likelihood of transmission: ";
		cin >> likelihoodOfTransmission;
		cout << endl;
	}
	
	//High-risk factor input prompt
	GetHighRiskInput();
}

//Run
void TwoParameter::Run(City * targetCity){
	int row = targetCity->GetRows();
	int columns = targetCity->GetColumns();
	int numberInfected = targetCity->NumberInfected();
	double vaccineIneffectiveness = targetCity->GetVaccineIneffectiveness();
	int r,c;
	double hrFactor;
	double chance;
	
	targetCity->SetDaysContagious(daysContagious);
	
	for(r = 0; r < row; r++){
		for(c = 0; c < columns; c++){
			
			//set local variable, depending on whether the location is high risk
			if (targetCity->IsHighRisk(r,c)) {
				hrFactor = highRiskFactor;
			}
			else {
				hrFactor = 1.0;
			}
			
			chance = ( (double)rand() / ((double)(RAND_MAX)+(double)(1))) * hrFactor;
			
			//if unaffected, probability based on likelihood * percent of total population infected
			if(targetCity->IsUnaffected(r,c) && 
			   chance <= ( ((double)numberInfected / (double)(row*columns) ) * likelihoodOfTransmission) ){
				   targetCity->InfectLocation(r,c);
			}
			
			//if location is vaccinated, factor in the probability that the vaccine fails
			else if(targetCity->IsVaccinated(r,c) &&
				chance <= ( ((double)numberInfected / (double)(row*columns) ) * likelihoodOfTransmission * vaccineIneffectiveness) ){
					targetCity->InfectLocation(r,c);
			}
		}
	}
}
