-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.js
39 lines (30 loc) · 1.47 KB
/
simulation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Population = require("./population.js");
const pandemicPeriod = 100;
module.exports = ({ disease, populationConfiguration, interventions, name }) => {
const population = new Population({
...Object.assign({}, populationConfiguration),
disease,
testAvailability: interventions.testAvailability
});
console.log(`------ ${name} -----`)
for (let days = 0; days < pandemicPeriod; days++) {
const stats = population.run();
if(stats.infected / population.people.length > interventions.quarantineStart) {
population.normalInteractionSize = interventions.sickenedInteractionSize;
}
if(stats.infected / population.people.length < interventions.quarantineEnd) {
population.normalInteractionSize = populationConfiguration.normalInteractionSize;
}
if(interventions.quarantineStartByFatality && (stats.dead / population.people.length) > interventions.quarantineStartByFatality) {
population.normalInteractionSize = interventions.sickenedInteractionSize;
}
if(interventions.quarantineStopByEconomicPain && stats.economicPain > interventions.quarantineStopByEconomicPain) {
population.normalInteractionSize = populationConfiguration.normalInteractionSize;
}
console.log(`${stats.infected}, ${stats.dead}, ${stats.interactionSize}, ${stats.recovered}, ${stats.patientsTurnedAway}, ${stats.economicPain}`);
if(stats.infected === 0) {
// save ourselves some time if the outbreak is over
break;
}
}
};