Skip to content

Commit ca54a43

Browse files
committed
Merge branch 'main' of github.com:SciCompMod/memilio-tutorials
2 parents 10baebf + 44ff6cc commit ca54a43

20 files changed

Lines changed: 416 additions & 315 deletions

.clang-format

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
SortIncludes: false
4+
ColumnLimit: 120
5+
AlignTrailingComments: false
6+
AccessModifierOffset: -4
7+
AlignConsecutiveAssignments: true
8+
ReflowComments: true
9+
BraceWrapping:
10+
AfterClass: true
11+
AfterFunction: true
12+
BeforeElse: true
13+
BeforeCatch: true
14+
AfterNamespace: true
15+
AfterEnum: true
16+
BreakBeforeBraces: "Custom"
17+
PointerAlignment: Left
18+
AllowShortFunctionsOnASingleLine: false
19+
NamespaceIndentation: None
20+
BreakConstructorInitializersBeforeComma: true
21+
AlwaysBreakTemplateDeclarations: Yes
22+
AllowShortLambdasOnASingleLine: Empty

cpp-tutorials/abm/parameter_setter.cpp

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,63 @@ const auto age_group_35_to_59 = mio::AgeGroup(3);
1010
const auto age_group_60_to_79 = mio::AgeGroup(4);
1111
const auto age_group_80_plus = mio::AgeGroup(5);
1212

13-
std::pair<double, double> get_my_and_sigma(std::pair<double, double> mean_and_std)
13+
std::pair<double, double> get_mu_and_sigma(std::pair<double, double> mean_and_std)
1414
{
1515
auto mean = mean_and_std.first;
1616
auto stddev = mean_and_std.second;
17-
double my = log(mean * mean / sqrt(mean * mean + stddev * stddev));
17+
double mu = log(mean * mean / sqrt(mean * mean + stddev * stddev));
1818
double sigma = sqrt(log(1 + stddev * stddev / (mean * mean)));
19-
return {my, sigma};
19+
return {mu, sigma};
2020
}
2121

2222
void set_world_parameters(mio::abm::Parameters& params)
2323
{
24-
auto incubation_period_my_sigma = get_my_and_sigma({4.5, 1.5});
25-
params.get<mio::abm::TimeExposedToNoSymptoms>() = mio::ParameterDistributionLogNormal(incubation_period_my_sigma.first, incubation_period_my_sigma.second);
24+
auto incubation_period_mu_sigma = get_mu_and_sigma({4.5, 1.5});
25+
params.get<mio::abm::TimeExposedToNoSymptoms>() =
26+
mio::ParameterDistributionLogNormal(incubation_period_mu_sigma.first, incubation_period_mu_sigma.second);
2627

27-
auto InfectedNoSymptoms_to_symptoms_my_sigma = get_my_and_sigma({1.1, 0.9});
28-
params.get<mio::abm::TimeInfectedNoSymptomsToSymptoms>() = mio::ParameterDistributionLogNormal(InfectedNoSymptoms_to_symptoms_my_sigma.first,
29-
InfectedNoSymptoms_to_symptoms_my_sigma.second);
28+
auto InfectedNoSymptoms_to_symptoms_mu_sigma = get_mu_and_sigma({1.1, 0.9});
29+
params.get<mio::abm::TimeInfectedNoSymptomsToSymptoms>() = mio::ParameterDistributionLogNormal(
30+
InfectedNoSymptoms_to_symptoms_mu_sigma.first, InfectedNoSymptoms_to_symptoms_mu_sigma.second);
3031

31-
auto TimeInfectedNoSymptomsToRecovered_my_sigma = get_my_and_sigma({8.0, 2.0});
32-
params.get<mio::abm::TimeInfectedNoSymptomsToRecovered>() = mio::ParameterDistributionLogNormal(TimeInfectedNoSymptomsToRecovered_my_sigma.first,
33-
TimeInfectedNoSymptomsToRecovered_my_sigma.second);
32+
auto TimeInfectedNoSymptomsToRecovered_mu_sigma = get_mu_and_sigma({8.0, 2.0});
33+
params.get<mio::abm::TimeInfectedNoSymptomsToRecovered>() = mio::ParameterDistributionLogNormal(
34+
TimeInfectedNoSymptomsToRecovered_mu_sigma.first, TimeInfectedNoSymptomsToRecovered_mu_sigma.second);
3435

35-
auto TimeInfectedSymptomsToSevere_my_sigma = get_my_and_sigma({6.6, 4.9});
36-
params.get<mio::abm::TimeInfectedSymptomsToSevere>() = mio::ParameterDistributionLogNormal(TimeInfectedSymptomsToSevere_my_sigma.first,
37-
TimeInfectedSymptomsToSevere_my_sigma.second);
36+
auto TimeInfectedSymptomsToSevere_mu_sigma = get_mu_and_sigma({6.6, 4.9});
37+
params.get<mio::abm::TimeInfectedSymptomsToSevere>() = mio::ParameterDistributionLogNormal(
38+
TimeInfectedSymptomsToSevere_mu_sigma.first, TimeInfectedSymptomsToSevere_mu_sigma.second);
3839

39-
auto TimeInfectedSymptomsToRecovered_my_sigma = get_my_and_sigma({8.0, 2.0});
40-
params.get<mio::abm::TimeInfectedSymptomsToRecovered>() = mio::ParameterDistributionLogNormal(TimeInfectedSymptomsToRecovered_my_sigma.first,
41-
TimeInfectedSymptomsToRecovered_my_sigma.second);
40+
auto TimeInfectedSymptomsToRecovered_mu_sigma = get_mu_and_sigma({8.0, 2.0});
41+
params.get<mio::abm::TimeInfectedSymptomsToRecovered>() = mio::ParameterDistributionLogNormal(
42+
TimeInfectedSymptomsToRecovered_mu_sigma.first, TimeInfectedSymptomsToRecovered_mu_sigma.second);
4243

43-
auto TimeInfectedSevereToCritical_my_sigma = get_my_and_sigma({1.5, 2.0});
44-
params.get<mio::abm::TimeInfectedSevereToCritical>() = mio::ParameterDistributionLogNormal(TimeInfectedSevereToCritical_my_sigma.first,
45-
TimeInfectedSevereToCritical_my_sigma.second);
44+
auto TimeInfectedSevereToCritical_mu_sigma = get_mu_and_sigma({1.5, 2.0});
45+
params.get<mio::abm::TimeInfectedSevereToCritical>() = mio::ParameterDistributionLogNormal(
46+
TimeInfectedSevereToCritical_mu_sigma.first, TimeInfectedSevereToCritical_mu_sigma.second);
4647

47-
auto TimeInfectedSevereToRecovered_my_sigma = get_my_and_sigma({18.1, 6.3});
48-
params.get<mio::abm::TimeInfectedSevereToRecovered>() = mio::ParameterDistributionLogNormal(TimeInfectedSevereToRecovered_my_sigma.first,
49-
TimeInfectedSevereToRecovered_my_sigma.second);
48+
auto TimeInfectedSevereToRecovered_mu_sigma = get_mu_and_sigma({18.1, 6.3});
49+
params.get<mio::abm::TimeInfectedSevereToRecovered>() = mio::ParameterDistributionLogNormal(
50+
TimeInfectedSevereToRecovered_mu_sigma.first, TimeInfectedSevereToRecovered_mu_sigma.second);
5051

51-
auto TimeInfectedCriticalToDead_my_sigma = get_my_and_sigma({10.7, 4.8});
52-
params.get<mio::abm::TimeInfectedCriticalToDead>() = mio::ParameterDistributionLogNormal(TimeInfectedCriticalToDead_my_sigma.first,
53-
TimeInfectedCriticalToDead_my_sigma.second);
52+
auto TimeInfectedCriticalToDead_mu_sigma = get_mu_and_sigma({10.7, 4.8});
53+
params.get<mio::abm::TimeInfectedCriticalToDead>() = mio::ParameterDistributionLogNormal(
54+
TimeInfectedCriticalToDead_mu_sigma.first, TimeInfectedCriticalToDead_mu_sigma.second);
5455

55-
auto TimeInfectedCriticalToRecovered_my_sigma = get_my_and_sigma({18.1, 6.3});
56-
params.get<mio::abm::TimeInfectedCriticalToRecovered>() = mio::ParameterDistributionLogNormal(TimeInfectedCriticalToRecovered_my_sigma.first,
57-
TimeInfectedCriticalToRecovered_my_sigma.second);
56+
auto TimeInfectedCriticalToRecovered_mu_sigma = get_mu_and_sigma({18.1, 6.3});
57+
params.get<mio::abm::TimeInfectedCriticalToRecovered>() = mio::ParameterDistributionLogNormal(
58+
TimeInfectedCriticalToRecovered_mu_sigma.first, TimeInfectedCriticalToRecovered_mu_sigma.second);
5859

5960
// Set percentage parameters
60-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_0_to_4}] = 0.50;
61-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_5_to_14}] = 0.55;
62-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_15_to_34}] = 0.60;
63-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_35_to_59}] = 0.70;
64-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_60_to_79}] = 0.83;
65-
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_80_plus}] = 0.90;
61+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_0_to_4}] = 0.50;
62+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_5_to_14}] = 0.55;
63+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_15_to_34}] =
64+
0.60;
65+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_35_to_59}] =
66+
0.70;
67+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_60_to_79}] =
68+
0.83;
69+
params.get<mio::abm::SymptomsPerInfectedNoSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_80_plus}] = 0.90;
6670

6771
params.get<mio::abm::SeverePerInfectedSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_0_to_4}] = 0.02;
6872
params.get<mio::abm::SeverePerInfectedSymptoms>()[{mio::abm::VirusVariant::Wildtype, age_group_5_to_14}] = 0.03;
@@ -87,7 +91,7 @@ void set_world_parameters(mio::abm::Parameters& params)
8791

8892
// Set infection parameters
8993
params.get<mio::abm::InfectionRateFromViralShed>()[{mio::abm::VirusVariant::Wildtype}] = 5.0;
90-
params.get<mio::abm::AerosolTransmissionRates>() = 0.0;
94+
params.get<mio::abm::AerosolTransmissionRates>() = 0.0;
9195
}
9296

9397
void set_local_parameters(mio::abm::Model& world)
@@ -292,7 +296,7 @@ void set_local_parameters(mio::abm::Model& world)
292296
case mio::abm::LocationType::Home:
293297
loc.get_infection_parameters().get<mio::abm::ContactRates>() = contacts_home;
294298
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= 1.4; //17 hours //intensity
295-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= 15.0*0.0; // Intensity
299+
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= 15.0; // Intensity
296300
break;
297301
case mio::abm::LocationType::School:
298302
loc.get_infection_parameters().get<mio::abm::ContactRates>() = contacts_school;
@@ -320,30 +324,3 @@ void set_local_parameters(mio::abm::Model& world)
320324
}
321325
}
322326
}
323-
324-
void set_local_parameters_event(mio::abm::Model& world, double contact_rate_multiplier)
325-
{
326-
set_local_parameters(world);
327-
for (auto& loc : world.get_locations()) {
328-
switch (loc.get_type()) {
329-
case mio::abm::LocationType::Home:
330-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier; //15 hours
331-
break;
332-
case mio::abm::LocationType::School:
333-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier; //2 hours
334-
break;
335-
case mio::abm::LocationType::Work:
336-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier; // 3 hours
337-
break;
338-
case mio::abm::LocationType::SocialEvent:
339-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier; // 3 hours
340-
break;
341-
case mio::abm::LocationType::BasicsShop:
342-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier; // 2 hours
343-
break;
344-
default:
345-
loc.get_infection_parameters().get<mio::abm::ContactRates>().array() *= contact_rate_multiplier;
346-
break;
347-
}
348-
}
349-
}

cpp-tutorials/abm/parameter_setter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
#include "abm/model.h"
33

4-
54
void set_world_parameters(mio::abm::Parameters& params);
65
void set_local_parameters(mio::abm::Model& world);
76
std::pair<double, double> get_my_and_sigma(std::pair<double, double> mean_and_std);

0 commit comments

Comments
 (0)