Skip to content

Commit 3b8cf9d

Browse files
jubickerHenrZu
andauthored
721 Munich graph sim (#791)
Co-authored-by: Henrik Zunker <69154294+HenrZu@users.noreply.github.com>
1 parent 9e697c0 commit 3b8cf9d

15 files changed

+634
-204
lines changed

cpp/memilio/io/epi_data.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@
2525
namespace mio
2626
{
2727

28-
const std::array<const char*, 6> ConfirmedCasesDataEntry::age_group_names = {"A00-A04", "A05-A14", "A15-A34",
29-
"A35-A59", "A60-A79", "A80+"};
28+
std::vector<const char*> ConfirmedCasesDataEntry::age_group_names = {"A00-A04", "A05-A14", "A15-A34",
29+
"A35-A59", "A60-A79", "A80+"};
3030

31-
const std::array<const char*, 11> PopulationDataEntry::age_group_names = {
31+
std::vector<const char*> PopulationDataEntry::age_group_names = {
3232
"<3 years", "3-5 years", "6-14 years", "15-17 years", "18-24 years", "25-29 years",
3333
"30-39 years", "40-49 years", "50-64 years", "65-74 years", ">74 years"};
3434

35-
const std::array<const char*, 6> VaccinationDataEntry::age_group_names = {"0-4", "5-14", "15-34",
36-
"35-59", "60-79", "80-99"};
35+
std::vector<const char*> VaccinationDataEntry::age_group_names = {"0-4", "5-14", "15-34", "35-59", "60-79", "80-99"};
3736

38-
IOResult<std::vector<int>> get_node_ids(const std::string& path, bool is_node_for_county)
37+
IOResult<std::vector<int>> get_node_ids(const std::string& path, bool is_node_for_county, bool rki_age_groups)
3938
{
40-
BOOST_OUTCOME_TRY(population_data, read_population_data(path));
39+
BOOST_OUTCOME_TRY(population_data, read_population_data(path, rki_age_groups));
4140
std::vector<int> id;
4241
id.reserve(population_data.size());
4342
for (auto&& entry : population_data) {

cpp/memilio/io/epi_data.h

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class StringDate : public Date
7474
class ConfirmedCasesDataEntry
7575
{
7676
public:
77-
static const std::array<const char*, 6> age_group_names;
77+
static std::vector<const char*> age_group_names;
7878

7979
double num_confirmed;
8080
double num_recovered;
@@ -223,7 +223,7 @@ IOResult<std::vector<T>> unpack_all(const std::vector<IOResult<T>>& v)
223223
class PopulationDataEntry
224224
{
225225
public:
226-
static const std::array<const char*, 11> age_group_names;
226+
static std::vector<const char*> age_group_names;
227227

228228
CustomIndexArray<double, AgeGroup> population;
229229
boost::optional<regions::StateId> state_id;
@@ -260,8 +260,8 @@ inline void get_rki_age_interpolation_coefficients(const std::vector<double>& ag
260260
std::vector<bool>& carry_over)
261261
{
262262
std::array<double, 6> param_ranges = {5., 10., 20., 25., 20., 20.};
263-
static_assert(param_ranges.size() == ConfirmedCasesDataEntry::age_group_names.size(),
264-
"Number of RKI age groups does not match number of age ranges.");
263+
assert(param_ranges.size() == ConfirmedCasesDataEntry::age_group_names.size() &&
264+
"Number of RKI age groups does not match number of age ranges.");
265265

266266
//counter for parameter age groups
267267
size_t counter = 0;
@@ -342,12 +342,19 @@ interpolate_to_rki_age_groups(const std::vector<PopulationDataEntry>& population
342342
* Deserialize population data from a JSON value.
343343
* Age groups are interpolated to RKI age groups.
344344
* @param jsvalue JSON value that contains the population data.
345+
* @param rki_age_groups Specifies whether population data should be interpolated to rki age groups.
345346
* @return list of population data.
346347
*/
347-
inline IOResult<std::vector<PopulationDataEntry>> deserialize_population_data(const Json::Value& jsvalue)
348+
inline IOResult<std::vector<PopulationDataEntry>> deserialize_population_data(const Json::Value& jsvalue,
349+
bool rki_age_groups = true)
348350
{
349351
BOOST_OUTCOME_TRY(population_data, deserialize_json(jsvalue, Tag<std::vector<PopulationDataEntry>>{}));
350-
return success(details::interpolate_to_rki_age_groups(population_data));
352+
if (rki_age_groups) {
353+
return success(details::interpolate_to_rki_age_groups(population_data));
354+
}
355+
else {
356+
return success(population_data);
357+
}
351358
}
352359

353360
/**
@@ -356,27 +363,46 @@ inline IOResult<std::vector<PopulationDataEntry>> deserialize_population_data(co
356363
* @param filename JSON file that contains the population data.
357364
* @return list of population data.
358365
*/
359-
inline IOResult<std::vector<PopulationDataEntry>> read_population_data(const std::string& filename)
366+
inline IOResult<std::vector<PopulationDataEntry>> read_population_data(const std::string& filename,
367+
bool rki_age_group = true)
360368
{
361369
BOOST_OUTCOME_TRY(jsvalue, read_json(filename));
362-
return deserialize_population_data(jsvalue);
370+
return deserialize_population_data(jsvalue, rki_age_group);
363371
}
364372

373+
/**
374+
* @brief Sets the age groups' names for the ConfirmedCasesDataEntry%s.
375+
* @param[in] names age group names
376+
*/
377+
IOResult<void> set_confirmed_cases_age_group_names(std::vector<const char*> names);
378+
379+
/**
380+
* @brief Sets the age groups' names for the PopulationDataEntry%s.
381+
* @param[in] names age group names
382+
*/
383+
IOResult<void> set_population_data_age_group_names(std::vector<const char*> names);
384+
385+
/**
386+
* @brief Sets the age groups' names for the VaccinationDataEntry%s.
387+
* @param[in] names age group names
388+
*/
389+
IOResult<void> set_vaccination_data_age_group_names(std::vector<const char*> names);
390+
365391
/**
366392
* @brief returns a vector with the ids of all nodes.
367393
* @param[in] path directory to population data
368394
* @param[in] is_node_for_county boolean specifying whether the nodes should be counties or districts
369395
* @return list of node ids.
370396
*/
371-
IOResult<std::vector<int>> get_node_ids(const std::string& path, bool is_node_for_county);
397+
IOResult<std::vector<int>> get_node_ids(const std::string& path, bool is_node_for_county, bool rki_age_groups = true);
372398

373399
/**
374400
* Represents an entry in a vaccination data file.
375401
*/
376402
class VaccinationDataEntry
377403
{
378404
public:
379-
static const std::array<const char*, 6> age_group_names;
405+
static std::vector<const char*> age_group_names;
380406

381407
double num_vaccinations_completed;
382408
Date date;

cpp/memilio/mobility/graph.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,18 @@ class Graph
258258
* @param[in] tnt_capacity_factor Factor for test and trace capacity.
259259
* @param[in] num_days Number of days to be simulated; required to load data for vaccinations during the simulation.
260260
* @param[in] export_time_series If true, reads data for each day of simulation and writes it in the same directory as the input files.
261+
* @param[in] rki_age_groups Specifies whether rki-age_groups should be used.
261262
*/
262263
template <class TestAndTrace, class ContactPattern, class Model, class MigrationParams, class Parameters,
263264
class ReadFunction, class NodeIdFunction>
264-
IOResult<void>
265-
set_nodes(const Parameters& params, Date start_date, Date end_date, const fs::path& data_dir,
266-
const std::string& population_data_path, bool is_node_for_county, Graph<Model, MigrationParams>& params_graph,
267-
ReadFunction&& read_func, NodeIdFunction&& node_func, const std::vector<double>& scaling_factor_inf,
268-
double scaling_factor_icu, double tnt_capacity_factor, int num_days = 0, bool export_time_series = false)
265+
IOResult<void> set_nodes(const Parameters& params, Date start_date, Date end_date, const fs::path& data_dir,
266+
const std::string& population_data_path, bool is_node_for_county,
267+
Graph<Model, MigrationParams>& params_graph, ReadFunction&& read_func,
268+
NodeIdFunction&& node_func, const std::vector<double>& scaling_factor_inf,
269+
double scaling_factor_icu, double tnt_capacity_factor, int num_days = 0,
270+
bool export_time_series = false, bool rki_age_groups = true)
269271
{
270-
BOOST_OUTCOME_TRY(node_ids, node_func(population_data_path, is_node_for_county));
272+
BOOST_OUTCOME_TRY(node_ids, node_func(population_data_path, is_node_for_county, rki_age_groups));
271273
std::vector<Model> nodes(node_ids.size(), Model(int(size_t(params.get_num_groups()))));
272274
for (auto& node : nodes) {
273275
node.parameters = params;

0 commit comments

Comments
 (0)