5555int main (int argc, char * argv[])
5656{
5757 // Usage: tutorial_abm_household [n_households] [infected_frac] [sim_days]
58- // n_households : number of each household type (default: 125)
58+ // n_households : number of each household type (default: 125)
5959 // infected_frac : fraction initially infected (default: 0.2)
6060 // sim_days : simulation duration in days (default: 30)
61- int arg_n_households = (argc > 1 ) ? std::atoi (argv[1 ]) : 125 ;
61+ int arg_n_households = (argc > 1 ) ? std::atoi (argv[1 ]) : 125 ;
6262 double arg_infected_frac = (argc > 2 ) ? std::atof (argv[2 ]) : 0.2 ;
63- int arg_sim_days = (argc > 3 ) ? std::atoi (argv[3 ]) : 30 ;
63+ int arg_sim_days = (argc > 3 ) ? std::atoi (argv[3 ]) : 30 ;
6464
6565 // Suppress verbose log output; only warnings and errors are shown.
6666 mio::set_log_level (mio::LogLevel::warn);
@@ -70,7 +70,7 @@ int main(int argc, char* argv[])
7070 // one group when created. The number and meaning of groups must be
7171 // consistent throughout the entire setup.
7272 size_t num_age_groups = 6 ;
73- const auto age_group_0_to_4 = mio::AgeGroup (0 ); // toddlers / kindergarten
73+ const auto age_group_0_to_4 = mio::AgeGroup (0 ); // toddlers / kindergarden
7474 const auto age_group_5_to_14 = mio::AgeGroup (1 ); // school children
7575 const auto age_group_15_to_34 = mio::AgeGroup (2 ); // young adults
7676 const auto age_group_35_to_59 = mio::AgeGroup (3 ); // middle-aged adults
@@ -92,9 +92,7 @@ int main(int argc, char* argv[])
9292 model.parameters .get <mio::abm::AgeGroupGotoSchool>() = false ;
9393 model.parameters .get <mio::abm::AgeGroupGotoSchool>()[age_group_5_to_14] = true ;
9494
95- model.parameters .get <mio::abm::AgeGroupGotoWork>().set_multiple (
96- {age_group_15_to_34, age_group_35_to_59}, true );
97-
95+ model.parameters .get <mio::abm::AgeGroupGotoWork>().set_multiple ({age_group_15_to_34, age_group_35_to_59}, true );
9896
9997 // *** Define HouseholdMember types. ***
10098 // A HouseholdMember is not a person itself; it is a *template* that
@@ -103,7 +101,7 @@ int main(int argc, char* argv[])
103101
104102 // child: equally likely to be 0-4 or 5-14 years old (weights 1 and 1).
105103 auto child = mio::abm::HouseholdMember (num_age_groups);
106- child.set_age_weight (age_group_0_to_4, 1 );
104+ child.set_age_weight (age_group_0_to_4, 1 );
107105 child.set_age_weight (age_group_5_to_14, 1 );
108106
109107 // parent: equally likely to be 15-34 or 35-59 years old.
@@ -134,7 +132,7 @@ int main(int argc, char* argv[])
134132
135133 // --- Type A: two-person household (1 parent + 1 child) -------------------
136134 auto twoPersonHousehold = mio::abm::Household ();
137- twoPersonHousehold.add_members (child, 1 );
135+ twoPersonHousehold.add_members (child, 1 );
138136 twoPersonHousehold.add_members (parent, 1 );
139137
140138 auto twoPersonGroup = mio::abm::HouseholdGroup ();
@@ -143,7 +141,7 @@ int main(int argc, char* argv[])
143141
144142 // --- Type B: three-person household (2 parents + 1 child) ----------------
145143 auto threePersonHousehold = mio::abm::Household ();
146- threePersonHousehold.add_members (child, 1 );
144+ threePersonHousehold.add_members (child, 1 );
147145 threePersonHousehold.add_members (parent, 2 );
148146
149147 auto threePersonGroup = mio::abm::HouseholdGroup ();
@@ -169,12 +167,11 @@ int main(int argc, char* argv[])
169167 // visit: a hospital, an ICU, a social event venue, a shop, a school, and
170168 // a workplace. The returned LocationId is used to assign persons later.
171169
172-
173170 // One hospital and one ICU shared by all persons.
174171 auto hospital = model.add_location (mio::abm::LocationType::Hospital);
175- auto icu = model.add_location (mio::abm::LocationType::ICU);
172+ auto icu = model.add_location (mio::abm::LocationType::ICU);
176173
177- // One social event venue (e.g. a community centre ).
174+ // One social event venue (e.g., a community center ).
178175 auto event = model.add_location (mio::abm::LocationType::SocialEvent);
179176
180177 // One supermarket. Groceries shops allow up to 20 simultaneous contacts.
@@ -186,43 +183,38 @@ int main(int argc, char* argv[])
186183 // One workplace for all working adults.
187184 auto work = model.add_location (mio::abm::LocationType::Work);
188185
189-
190186 // *** Assign initial infection states. ***
191187 // Each person draws a random infection state from the distribution below.
192188 // Persons who are not Susceptible receive a full Infection object so their
193189 // viral-load course and state transitions are properly initialised.
194190 //
195- // Index | InfectionState | Probability
196- // ------|-------------------------|------------
197- // 0 | Susceptible | 0.80
198- // 1 | Exposed | 0.10
199- // 2 | InfectedNoSymptoms | 0.01
200- // 3 | InfectedSymptoms | 0.01
201- // 4 | InfectedSevere | 0.01
202- // 5 | InfectedCritical | 0.01
203- // 6 | Recovered | 0.00
204- // 7 | Dead | 0.06
191+ // Index | InfectionState | Probability
192+ // ------|-------------------------------- |------------
193+ // 0 | Susceptible | 1.0 - arg_infected_frac
194+ // 1 | Exposed | 0.25 * arg_infected_frac
195+ // 2 | InfectedNoSymptoms (I_NS) | 0.5 * arg_infected_frac
196+ // 3 | InfectedSymptoms (I_Sy) | 0.25 * arg_infected_frac
197+ // 4 | InfectedSevere (I_Sev) | 0.0
198+ // 5 | InfectedCritical (I_Crit) | 0.0
199+ // 6 | Recovered | 0.0
200+ // 7 | Dead | 0.0
205201 auto start_date = mio::abm::TimePoint (0 ); // t = 0 s from the simulation epoch
206202
207203 // Build infection distribution from the infected fraction.
208204 // The non-susceptible portion is split: 25% Exposed, 50% I_NS, 25% I_Sy.
209205 const double f = arg_infected_frac;
210- std::vector<ScalarType> infection_distribution{
211- 1.0 - f, f * 0.25 , f * 0.50 , f * 0.25 , 0.0 , 0.0 , 0.0 , 0.0 };
206+ std::vector<ScalarType> infection_distribution{1.0 - f, f * 0.25 , f * 0.50 , f * 0.25 , 0.0 , 0.0 , 0.0 , 0.0 };
212207
213208 for (auto & person : model.get_persons ()) {
214209 // Draw an infection state from the distribution above.
215210 mio::abm::InfectionState infection_state = mio::abm::InfectionState (
216- mio::DiscreteDistribution<size_t >::get_instance ()(
217- mio::thread_local_rng (), infection_distribution));
218-
211+ mio::DiscreteDistribution<size_t >::get_instance ()(mio::thread_local_rng (), infection_distribution));
212+
219213 auto rng = mio::abm::PersonalRandomNumberGenerator (person);
220214 if (infection_state != mio::abm::InfectionState::Susceptible) {
221215 // Infect an agent with the drawn state
222- person.add_new_infection (
223- mio::abm::Infection (rng, mio::abm::VirusVariant::Wildtype,
224- person.get_age (), model.parameters ,
225- start_date, infection_state));
216+ person.add_new_infection (mio::abm::Infection (rng, mio::abm::VirusVariant::Wildtype, person.get_age (),
217+ model.parameters , start_date, infection_state));
226218 }
227219 }
228220
@@ -244,8 +236,7 @@ int main(int argc, char* argv[])
244236 if (person.get_age () == age_group_5_to_14) {
245237 model.assign_location (id, school);
246238 }
247- if (person.get_age () == age_group_15_to_34 ||
248- person.get_age () == age_group_35_to_59) {
239+ if (person.get_age () == age_group_15_to_34 || person.get_age () == age_group_35_to_59) {
249240 model.assign_location (id, work);
250241 }
251242 }
@@ -266,9 +257,7 @@ int main(int argc, char* argv[])
266257 // *** Write results to file. ***
267258 std::ofstream outfile (" abm_household.txt" );
268259 std::get<0 >(historyTimeSeries.get_log ())
269- .print_table (outfile,
270- {" S" , " E" , " I_NS" , " I_Sy" , " I_Sev" , " I_Crit" , " R" , " D" },
271- 7 , 4 );
260+ .print_table (outfile, {" S" , " E" , " I_NS" , " I_Sy" , " I_Sev" , " I_Crit" , " R" , " D" }, 7 , 4 );
272261 std::cout << " Results written to abm_household.txt\n " ;
273262
274263 return 0 ;
0 commit comments