Go back to Home
<project-file type=“source”/>
<content> #include “networkstructure.h” #include “parameters.h” #include “ode.h” #include “genrand2.h”
#include <iostream> #include <fstream>
int main(int argc, const char *argv[]) {
Parameters params;
StringArgument ArgNet(“network”, “network data file name (output of the netgen program)”, Argument::REQUIRED);
StringArgument ArgI0("initial-infections", "the initial infections data file name (a list of node IDs)", Argument::NOT_REQUIRED); LongArgument ArgSeed("seed", "the seed to initialize the random number generator", Argument::NOT_REQUIRED); StringArgument ArgLog("log", "log file name", Argument::REQUIRED); FloatArgument ArgBetaHousehold("household-contact-rate", "the transmission rate", Argument::REQUIRED); FloatArgument ArgBetaExternal("external-contact-rate", "the transmission rate", Argument::REQUIRED); FloatArgument ArgBeta("contact-rate", "the transmission rate", Argument::REQUIRED); DistributionArgument ArgTinf("infectious-period", "the infectious period", Argument::REQUIRED); DistributionArgument ArgTlat("latent-period", "the latent period", Argument::REQUIRED); FloatArgument ArgQuit("quit-time", "the simulation end time", Argument::REQUIRED); BoolArgument ArgSIR("has-immunity", "SIR/SIS model", Argument::REQUIRED); IntArgument ArgRuns("runs", "the number of simulation runs", Argument::NOT_REQUIRED, 1); BoolArgument ArgDumpNet("dump-network", "whether to dump the contact network in the log file", Argument::NOT_REQUIRED, false); BoolArgument ArgCases("count-cases", "if true, count the number of new cases in each time unit, otherwise, count the number of infected individual in each time unit", Argument::NOT_REQUIRED, false);
params.addArgument(ArgNet); params.addArgument(ArgI0); params.addArgument(ArgSeed); params.addArgument(ArgLog); params.addArgument(ArgBetaHousehold); params.addArgument(ArgBetaExternal); params.addArgument(ArgTinf); if (!params.parse(argc, argv)) { params.usage(argv[0]); return 1; } NetworkStructure net(ArgNet.value());
// set initial infections std::vector<int> I0; int n = net.nodes(); if (ArgI0.set()) { FILE *fI0 = fopen(ArgI0.value(), "r"); if (fI0 == NULL) { std::cerr<<"Error: initial infections data file not readable!"<<std::endl; return 1; } int a; while (fscanf(fI0, "%d", &a) > 0) I0.push_back(a); fclose(fI0); } else I0.push_back(genrand2i() % n + 1); std::ofstream log(ArgLog.value());
net.infect(I0); if (ArgDumpNet.value()) net.dumpNet(log); net.dumpHouseholdCompartments(log); net.dumpEffectiveDegrees(log);
ODEParameters p = { ArgBetaHousehold.value(), ArgBetaExternal.value(), 1 / ArgTinf.value()->mean(), net.MaxHouseholdSize, net.MaxExternalDegree}; ODEResults * results = ode_simulation(p, 0, net); n = results->points(); log<<"ODE:"<<std::endl; for (int i = 0; i < n; i++) log<<results->t(i)<<" : I : "<<results->It(i)<<" : "<<results->IH(i)<<std::endl;
log.close(); return 0;
} </content> <use name=“parameters.h”/> <use name=“ode.h”/> <use name=“networkstructure.h”/> <use name=“genrand2.h”/>