Beanshell Scripting Appendix
Main Menu Previous Topic Next Topic
File SPDynamicsInterim.bsh
This Beanshell script was used to generate Figure 4 in Slide 2 of Topic 3 of this
tutorial.
/*
* This script contains functions needed to run experiments to obtain the effect of the
* switch day in the Federal Interim policy in the disease transmission model from
* "Emergency response to a smallpox attack: The case for mass vaccination" by Kaplan, Craft,
* and Wein (submitted to the PNAS office directly).
*/
// deaths[i] : the number of deaths when the government switches from Trace to Mass Vaccination
// on day i of the epidemic
// numPoints : number of data points
int numPoints = 51;
deaths = new double[numPoints];
/*
* This collects data for the experiment. To obtain numbers of casualties at day 200 as the
* day of the switch from TV to MV varies from 1 to 51, run
* bsh% SPDynamicsInterim( 200 );
* The experiment should take about 1.7 hours on a 1.0 GHz Windows machine
*
* numDays Number of days for the experiment to run. In the paper, the base case results
* for the interim policy are reported for 165 days. As the day of the switch from
* TV to MV goes up, the number of days to obtain asymptotic behavior in the number
* of casualties goes up as well. For numPoints = 51, running each experiment for
* 200 days is sufficient to get to that asymptotic behavior.
*/
void SPDynamicsInterim( int numDays )
{
double timeStep = 0.008;
double beta = 1E-7;
double initInfected = 1000;
double totalPopulation = 1E7;
double r3 = 1.0 / 3.0;
initSusceptible = totalPopulation - initInfected;
for (int i=0; i
}
initSoc = SocietyFactory.createSmallpoxDynamicsSociety( false, timeStep );
//// set the values of beta and initial number of people infected
// set initial infected and susceptible populations
initSoc.getTimeModel().alterKnowledge( initSusceptible, 0, 0 );
initSoc.getTimeModel().alterKnowledge( initInfected, 0, 2 );
// set beta
edu.umich.si.infoelite.minischeme.Interpreter.evaluate(
new MinischemeExpression( "(set beta " + beta + ")" ),
initSoc.environment, initSoc.primitives );
for (int i=1; i<=numPoints; i++ ) {
// don't run initSoc, make a clone to run so that you can reuse initSoc
// in the future
soc = (Society) initSoc.clone();
// now run the society for the appropriate number of steps of TraceVaccination
int numSteps;
numSteps = (int) ( (double)i / timeStep );
soc.run( numSteps );
// switch the society from Trace to Mass Vaccination
SocietyFactory.switchSmallpoxDynamicsToMV( soc );
// run the society for the appropriate number of steps of Mass Vaccination
// in other words, the number of steps needed to reach numDays
numSteps = (int)( (double)numDays / timeStep ) - numSteps;
soc.run( numSteps );
// collect and record data - the current population of the dead state - agent 16
deaths[i-1] = soc.getAgent(16).getKnowledge(0);
// print out the result
print( "i-1 " + (i-1) + " : deaths " + deaths[i-1] );
}
print("Smallpox Dynamics Experiment complete!");
}
void writeSDResultsToFile() {
str = "";
for (int i=0; i
}
writeStringToFile( str );
}
Previous Slide Next Slide