33 #include <boost/property_tree/ptree.hpp> 38 using namespace ContactType;
49 const auto fileName = m_config.get<
string>(
"run.population_file");
50 m_stride_logger->info(
"Building default population from file {}.", fileName);
52 const auto use_install_dirs = m_config.get<
bool>(
"run.use_install_dirs");
53 const auto filePath = (use_install_dirs) ?
FileSys::GetDataDir() /= fileName : filesys::path(fileName);
54 if (!is_regular_file(filePath)) {
55 throw runtime_error(
string(__func__) +
"> Population file " + filePath.string() +
" not present.");
59 popFile.open(filePath.string());
60 if (!popFile.is_open()) {
61 throw runtime_error(
string(__func__) +
"> Error opening population file " + filePath.string());
65 getline(popFile, line);
66 unsigned int person_id = 0U;
68 while (getline(popFile, line)) {
69 const auto values =
Split(line,
",");
70 const auto age = FromString<unsigned int>(values[0]);
71 const auto householdId = FromString<unsigned int>(values[1]);
72 const auto schoolId = FromString<unsigned int>(values[2]);
73 const auto workId = FromString<unsigned int>(values[3]);
74 const auto primaryCommunityId = FromString<unsigned int>(values[4]);
75 const auto secondaryCommunityId = FromString<unsigned int>(values[5]);
77 pop->CreatePerson(person_id, age, householdId, schoolId, 0, workId, primaryCommunityId,
78 secondaryCommunityId);
84 m_stride_logger->trace(
"Done building default population.");
94 boost::optional<float> seeding_rate = m_config.get_optional<
float>(
"run.seeding_rate");
96 if (*seeding_rate > 1.0) {
97 throw runtime_error(
string(__func__) +
"> Bad input data for seeding_rate.");
111 for (
const auto& p : *pop) {
113 maxIds[typ] = max(maxIds[typ], p.GetPoolId(typ));
120 for (
unsigned int i = 1; i < maxIds[typ] + 1; i++) {
121 pop->RefPoolSys().CreateContactPool(typ);
134 for (
auto& p : *pop) {
135 for (
Id typ : IdList) {
136 const auto poolId = p.GetPoolId(typ);
138 pop->RefPoolSys().RefPools(typ)[poolId].AddMember(&p);
static filesys::path GetDataDir()
/// Return data dir (only relevant when use_install_dirs mode is active)
constexpr std::initializer_list< Id > IdList
To allow iteration over the type ids.
std::shared_ptr< Population > MakePersons(std::shared_ptr< Population > pop)
Generates pop's individuals and return pop.
std::shared_ptr< Population > Build(std::shared_ptr< Population > pop) override
Build Population and return it afterwards.
std::vector< std::string > Split(const std::string &s, const std::string &delimiters)
Split a string (in order of occurence) by splitting it on the given delimiters.
Definition of ContactPool Id Type.
Container for the contact pools of various type (household, work, ...).
Header for the ContactLogMode class.
Header file for the SurveySeeder class.
Header file for the core Population class.
Miscellaneous string utilities.
Interface for install directory queries.
Namespace for the simulator and related classes.