import java.util.ArrayList; import java.util.Random; import java.awt.*; import java.awt.event.*; import java.applet.*; public class Node { int numEdges; int daysInfected; int daysRecovered; boolean infected; boolean vaccinated; boolean susceptible; boolean recovered; double vacProb; int vaccinatedNeigh; double myInfSev; double threshold; double infSeverThreshold; double susSseverThreshold; double kappaH; double kappaC; double preference; double npieff; double vaceff; int totVaccinations; //int totnonEffVaccinations; boolean notEfficacious; double sigma; double transmissionRate = 0.045; double transmissionRateFluc = 0.2; int infNeighSeas; double cumuInfSeas; double memory; int timesinfthisseas; int timesvacthisseas; boolean chooseNotToVac; boolean infChooseDis; double EI /*= -0.0055*/; double EV /*= -0.0015*/; double ED; double EH; double ES; int delay = 0; boolean underDelay = false; Random ranGen = new Random(); ArrayList contacts = new ArrayList(); public Node(double a,double b,double c,double d,double e,double f,double g,double h,double i,double j,double k,double l,double m){ threshold = a; infSeverThreshold = b; susSseverThreshold = b; kappaH = c; kappaC = d; sigma = e; memory = f; ED = g; EH = h; ES = i; EV = j; EI=k; npieff = l; vaceff = m; preference = 0.0; numEdges = 0; daysInfected = 0; daysRecovered = 0; susceptible = true; infected = false; vaccinated = false; recovered = false; //vaccinatedNeigh = 0; myInfSev = 0; totVaccinations = 0; //totnonEffVaccinations = 0; notEfficacious = false; infNeighSeas=0; cumuInfSeas=0.0; timesinfthisseas = 0; timesvacthisseas = 0; chooseNotToVac = false; infChooseDis = false; } public void addContact(int a){ contacts.add(a); } public int getContact(int a){ return contacts.get(a); } public int numContacts(){ return contacts.size(); } public void distanceContact(int a){ if(a == 0){ int b = -10001; for(int i = 0 ; i < contacts.size(); i++){ if(contacts.get(i) == a){contacts.set(i,b);} } } else{ int b = a * -1; for(int i = 0 ; i < contacts.size(); i++){ if(contacts.get(i) == a){contacts.set(i,b);} } } } public void removeDist(){ for(int i = 0 ; i < contacts.size(); i++){ if(contacts.get(i) < 0){ if(contacts.get(i) == -10001){contacts.set(i,0);} else{ int a = contacts.get(i); contacts.set(i,a*-1); } } } } public void addtimesinfthisseas(){ timesinfthisseas++; //System.out.print(timesinfthisseas); } public void addtimesvacthisseas(){ timesvacthisseas++; //System.out.print(timesinfthisseas); } public void resettimesinfthisseas(){ timesinfthisseas = 0; } public void resettimesvacthisseas(){ timesvacthisseas = 0; } public int gettimesvacthisseas(){ return timesvacthisseas; } public int gettimesinfthisseas(){ return timesinfthisseas; } public int getEdges(){ return numEdges; } public void addEdge(){ numEdges++; } public boolean isInfected(){ return infected; } public boolean isSusceptible(){ return susceptible; } public boolean isRecovered(){ return recovered; } public boolean isVaccinated(){ return vaccinated; } public void becomeInfected(){ infected = true; susceptible = false; timesinfthisseas++; } public void recover(){ infected = false; vaccinated = false; susceptible = false; recovered = true; infChooseDis = false; } public void becomeVaccinated2(){ delay = 0; underDelay = true; } public boolean isUnderDelay(){ return underDelay; } public void incDelay(){ delay++; if(delay >= 14){ this.becomeVaccinated(); } } public void becomeVaccinated(){ underDelay = false; double r = Math.random(); if(r < vaceff){ vaccinated = true; susceptible = false; } } public void becomeSusceptible(){ susceptible = true; infected = false; vaccinated = false; recovered = false; daysInfected = 0; daysRecovered = 0; notEfficacious = false; } public boolean getEfficacy(){ return notEfficacious; } public int getDaysInfected(){ return daysInfected; } public void addDayInfected(){ daysInfected++; } public void decreasePref(){ this.preference = this.preference * memory; } public void incInfNeighSeas(){ infNeighSeas++; } public int getInfNeighSeas(){ return infNeighSeas; } public void setCumuInfSeas(){ cumuInfSeas = sigma*(1.0-Math.exp(-kappaH*((double)infNeighSeas+(double)timesinfthisseas))) + (1.0-sigma)*cumuInfSeas; infNeighSeas = 0; chooseNotToVac = false; preference = preference * memory; //System.out.println(cumuInfSeas); } public void decayCumuInfSeas(){ cumuInfSeas = cumuInfSeas * memory; //System.out.println(cumuInfSeas); } public boolean getInfDisDec(){ return infChooseDis; //System.out.print(timesinfthisseas); } public void potentialRecover(){ double r = Math.random(); double poissonCDF = 0.0; double lambda = 5.0; double tempSum = 0.0; for(int i = 0 ; i <= this.getDaysInfected() ; i++){ tempSum += (Math.pow(lambda,(double)i) / (double)NetVac.factorial(i) ); } poissonCDF = Math.exp(-lambda)*tempSum; if(r < poissonCDF){ this.recover(); } else{this.addDayInfected();} } public void potentialSusc(){ double r = Math.random(); if(r < 0.002739726){this.becomeSusceptible();} else {daysRecovered++;} } public void potentialInfect(int infNeigh, int time){ double r = Math.random(); double beta = transmissionRate*(1+transmissionRateFluc*Math.cos(((2.0*Math.PI*(double)time/365.0) /*- 0.5*/) )); double pInf = 1.0 - Math.pow((1.0-beta),(double)infNeigh); pInf = pInf; if(r < pInf){ this.becomeInfected(); } } public double getPref(){ return preference; } public void potentialVaccinate(int numS, int numV){ double r = Math.random(); double w1 = sigma*(1.0-Math.exp(-kappaH*(double)infNeighSeas)) + (1.0-sigma)*(cumuInfSeas); double w5 = 1.0 - Math.exp(-kappaC * ((double)numS + ((1.0-vaceff)*(double)numV))); double v1=0; double v2=0; if(!chooseNotToVac){ //preference = preference * memory; r = Math.random(); if(r < w1){v2 = EI + w5*EH;} else{v2 = 0.0;} r = Math.random(); if(r < (1.0-vaceff) v1 = v2 + EV; } else{v1 = EV + ES ;} preference = preference + (v1-v2); //System.out.println(preference); if(this.preference <= -threshold){chooseNotToVac = true;} if(this.preference >= threshold){ if(this.isSusceptible()){timesvacthisseas++; this.becomeVaccinated2();} if(this.isVaccinated() || this.isRecovered()){timesvacthisseas++;} } } } public boolean potentialInfSever(int numS, int numV){ double r = 0.0; double pref = 0.0; double w5 = 1.0 - Math.exp(-kappaC * ((double)numS + ((1.0-vaceff)*(double)numV))); double w7 = (1.0-npieff); double v1= 0.0; double v2 = 0.0; int checkCount = 0; while(pref < infSeverThreshold && pref > -infSeverThreshold){ r = Math.random(); if(r < w5){v2 = EH;} else{v2 = 0;} r = Math.random(); if(r < w7){v1 = ED*this.numContacts()+ v2;} else{v1 = ED*this.numContacts()+ ES;} pref += (v1-v2); checkCount++; if(checkCount > 1000){return false;} } if(pref >= infSeverThreshold){infChooseDis = true; return true;} else{return false;} } public boolean potentialSuscSever(int numI, int numS, int numV, boolean vaccinated){ double r = 0.0; double[] distProbs = {0.3449956347189606, 1.0, 1.0, 1.0}; r = Math.random(); double pref = 0.0; double w9; double w7 = (1.0-npieff); double v1= 0.0; double v2 = 0.0; int checkCount = 0; if(vaccinated){w9 = (1.0-vaceff)*(1.0 - Math.exp(-kappaC * ((double)numI)));} else{w9 = 1.0 - Math.exp(-kappaC * ((double)numI));} while(pref < susSseverThreshold && pref > -susSseverThreshold){ r = Math.random(); if(r < w9){v2 = EI;} else{v2 = 0;} r = Math.random(); if(r < w7){v1 = ED*(double)numI + v2;} else{v1 = ED*(double)numI;} pref += (v1-v2); checkCount++; if(checkCount > 1000){return false;} } if(pref >= susSseverThreshold){return true;} else{return false;} } }