Line data Source code
1 : /* 2 : * Copyright (C) 2020-2024 MEmilio 3 : * 4 : * Authors: Daniel Abele, Sascha Korf, Khoa Nguyen 5 : * 6 : * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> 7 : * 8 : * Licensed under the Apache License, Version 2.0 (the "License"); 9 : * you may not use this file except in compliance with the License. 10 : * You may obtain a copy of the License at 11 : * 12 : * http://www.apache.org/licenses/LICENSE-2.0 13 : * 14 : * Unless required by applicable law or agreed to in writing, software 15 : * distributed under the License is distributed on an "AS IS" BASIS, 16 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 : * See the License for the specific language governing permissions and 18 : * limitations under the License. 19 : */ 20 : 21 : #ifndef MIO_ABM_HOUSEHOLD_H 22 : #define MIO_ABM_HOUSEHOLD_H 23 : 24 : #include "abm/model.h" 25 : #include "memilio/epidemiology/age_group.h" 26 : #include "memilio/utils/custom_index_array.h" 27 : #include <numeric> 28 : #include <vector> 29 : 30 : namespace mio 31 : { 32 : namespace abm 33 : { 34 : 35 : /** 36 : * @file 37 : * A HouseholdMember has a vector with weighted age distribution from which the age can be calculated. 38 : * A Household holds a vector with HouseholdMembers. 39 : * A HouseholdGroup holds a vector with a tuple of a Household and the amount of times the Household is in the group. 40 : * E.g. if 10 households hold a member of "child and parent" and that Household would be parentAndChildHousehold the 41 : * vector would contain <parentAndChildHousehold, 10>. parentAndChildHousehold would consist of a vector with the 42 : * HouseholdMembers parent and child and parent has, for example the age distribution {0,0,10,1,0,0} with respect to the 43 : * AgeGroup class. The child would have, for example, {1,1,0,0,0}, meaning that the AgeGroups 0-4 and 5-14 are the only 44 : * possible ages and are both equally likely. 45 : */ 46 : 47 : /** 48 : * @brief A HouseholdMember represented by a weighted age distribution. 49 : * For every AgeGroup there is a weight which is used to calculate the age of the Person living in this Household. 50 : */ 51 : class HouseholdMember 52 : { 53 : public: 54 : /** 55 : * @brief Constructs a new HouseholdMember. 56 : * @param[in] agegroups the age groups in the model. 57 : */ 58 324 : HouseholdMember(size_t num_agegroups) 59 324 : : m_age_weights({AgeGroup(num_agegroups)}, 0) 60 : { 61 324 : } 62 : 63 : /** 64 : * @brief Sets the weight of an AgeGroup. 65 : * The weights correspond to the probability that a Person has the corresponding age. 66 : * @param[in] age_group The AgeGroup. 67 : * @param[in] weight The weight of the AgeGroup. 68 : */ 69 36 : void set_age_weight(mio::AgeGroup age_group, int weight) 70 : { 71 36 : assert(age_group < m_age_weights.size<mio::AgeGroup>()); 72 36 : m_age_weights[age_group] = weight; 73 36 : } 74 : 75 : /** 76 : * @brief Returns the CustomIndexArray with the weights of each AgeGroup. 77 : */ 78 936 : const CustomIndexArray<int, mio::AgeGroup>& get_age_weights() const 79 : { 80 936 : return m_age_weights; 81 : } 82 : 83 : private: 84 : CustomIndexArray<int, mio::AgeGroup> m_age_weights; ///< Weights of every AgeGroup. 85 : }; 86 : 87 : /** 88 : * @brief A Household represented by a vector with HouseholdMember%s. 89 : * The Household may contain multiple members of the same type. 90 : */ 91 : class Household 92 : { 93 : public: 94 : /** 95 : * @brief Constructs a new Household. 96 : */ 97 45 : Household() 98 45 : : m_household_member_list() 99 : { 100 45 : m_number_of_members = 0; 101 45 : m_space_per_member = 0; 102 45 : } 103 : 104 : /** 105 : * @brief Returns the number of members, i.e.\ Person%s in the Household. 106 : */ 107 288 : int get_total_number_of_members() const 108 : { 109 288 : return m_number_of_members; 110 : } 111 : 112 : /** 113 : * @brief Set the space per member for the computation of the LocationCapacity of the Household. 114 : * @param[in] space_per_member Space per member in cubic meters. 115 : */ 116 0 : void set_space_per_member(int space_per_member) 117 : { 118 0 : m_space_per_member = space_per_member; 119 0 : } 120 : 121 : /** 122 : * @brief Get the space per member of the Household, measured in cubic meters. 123 : */ 124 144 : int get_space_per_member() const 125 : { 126 144 : return m_space_per_member; 127 : } 128 : 129 : /** 130 : * @brief Get the HouseholdMember%s of the Household. 131 : */ 132 144 : const std::vector<std::tuple<HouseholdMember, int>>& get_members() const 133 : { 134 144 : return m_household_member_list; 135 : } 136 : 137 : /** 138 : * @brief Adds a number of the same HouseholdMember%s to a Household. 139 : * @param[in] household_member A HouseholdMember. 140 : * @param[in] number_of_members The amount of members to be added. 141 : */ 142 : void add_members(HouseholdMember household_member, int number_of_members); 143 : 144 : private: 145 : int m_number_of_members; ///< Total number of Person%s in the Household. 146 : int m_space_per_member; ///< Space per Person in cubic meters (constant maximal capacity over time). 147 : std::vector<std::tuple<HouseholdMember, int>> m_household_member_list; /**< HouseholdMember%s of the Household and 148 : the respective number of Person%s.*/ 149 : }; 150 : 151 : /** 152 : * @brief A HouseholdGroup represented by different Household%s. 153 : * The group may contain multiple Household%s of the same type. 154 : */ 155 : class HouseholdGroup 156 : { 157 : public: 158 : /** 159 : * @brief Constructs a new HouseholdGroup. 160 : */ 161 9 : HouseholdGroup() 162 9 : : m_household_list() 163 : { 164 9 : m_number_of_households = 0; 165 9 : } 166 : 167 : /** 168 : * @brief Returns the number of Household%s in the HouseholdGroup. 169 : */ 170 : int get_total_number_of_households() const 171 : { 172 : return m_number_of_households; 173 : } 174 : 175 : /** 176 : * @brief Returns the Household%s of the HouseholdGroup. 177 : * @return A vector of tuples that contains the Houshold and the amount of times that Household is in the group. 178 : */ 179 9 : const std::vector<std::tuple<Household, int>>& get_households() const 180 : { 181 9 : return m_household_list; 182 : } 183 : 184 : /** 185 : * @brief Adds a number of Household%s of the same kind, e.g.\ same members, to a HouseholdGroup. 186 : * @param[in] household A Household. 187 : * @param[in] number_of_households The amount of times that Household is in the group. 188 : */ 189 : void add_households(Household household, int number_of_households); 190 : 191 : private: 192 : int m_number_of_households; ///< Number of Household%s in this group. 193 : std::vector<std::tuple<Household, int>> m_household_list; /**< A list of types of Household%s and the amount of 194 : times it is in the group.*/ 195 : }; 196 : 197 : /** 198 : * @brief Adds a specific Household to the Model. 199 : * Adds Person%s to the Model according to the age distribution of the HouseholdMember%s of the Household. 200 : * @param[in,out] model The Model to which the Household has to be added. 201 : * @param[in] household The Household to add to Model. 202 : */ 203 : void add_household_to_model(Model& model, const Household& household); 204 : 205 : /** 206 : * @brief Adds Household%s from a HouseholdGroup to the Model. 207 : * @param[in,out] model The Model to which the group has to be added. 208 : * @param[in] household_group The HouseholdGroup to add. 209 : */ 210 : void add_household_group_to_model(Model& model, const HouseholdGroup& household_group); 211 : 212 : } // namespace abm 213 : } // namespace mio 214 : 215 : #endif //MIO_ABM_HOUSEHOLD_H