33 template <ContactLogMode::Id LL>
38 unsigned short int,
const double,
const double)
50 class LOG_POLICY<ContactLogMode::Id::Transmissions>
54 unsigned short int,
const double,
const double)
58 static void Trans(
const std::shared_ptr<spdlog::logger>& logger,
const Person* p1,
const Person* p2,
68 class LOG_POLICY<ContactLogMode::Id::All>
71 static void Contact(
const std::shared_ptr<spdlog::logger>& logger,
const Person* p1,
const Person* p2,
72 ContactType::Id type,
unsigned short int sim_day,
const double c_rate,
const double t_rate)
75 logger->info(
"[CONT] {} {} {} {} {} {} {} {} {} {} {} {}", p1->
GetId(), p1->
GetAge(),
76 p2->
GetAge(),
static_cast<unsigned int>(type == ContactType::Id::Household),
77 static_cast<unsigned int>(type == ContactType::Id::K12School),
78 static_cast<unsigned int>(type == ContactType::Id::College),
79 static_cast<unsigned int>(type == ContactType::Id::Workplace),
80 static_cast<unsigned int>(type == ContactType::Id::PrimaryCommunity),
81 static_cast<unsigned int>(type == ContactType::Id::SecondaryCommunity), sim_day,
86 static void Trans(
const std::shared_ptr<spdlog::logger>& logger,
const Person* p1,
const Person* p2,
96 class LOG_POLICY<ContactLogMode::Id::Susceptibles>
99 static void Contact(
const std::shared_ptr<spdlog::logger>& logger,
const Person* p1,
const Person* p2,
103 logger->info(
"[CONT] {} {}", p1->
GetId(), p2->
GetId());
122 const double reference_num_contacts{profile[
EffectiveAge(static_cast<unsigned int>(p->
GetAge()))]};
123 const double potential_num_contacts{
static_cast<double>(pool_size - 1)};
125 double individual_contact_rate = reference_num_contacts / potential_num_contacts;
126 if (individual_contact_rate >= 1) {
127 individual_contact_rate = 0.999;
130 individual_contact_rate = individual_contact_rate / 2;
132 individual_contact_rate += (individual_contact_rate * individual_contact_rate);
134 return individual_contact_rate;
145 template <ContactLogMode::Id LL,
bool TIC,
bool TO>
148 unsigned short int simDay, shared_ptr<spdlog::logger> cLogger)
150 using LP = LOG_POLICY<LL>;
155 const auto pSize = pMembers.size();
159 for (
size_t i_person1 = 0; i_person1 < pSize; i_person1++) {
161 const auto p1 = pMembers[i_person1];
165 const double c_rate = GetContactRate(profile, p1, pSize);
167 for (
size_t i_person2 = 0; i_person2 < pSize; i_person2++) {
169 if (i_person1 == i_person2) {
173 const auto p2 = pMembers[i_person2];
180 LP::Contact(cLogger, p1, p2, pType, simDay, c_rate, tProbability);
182 LP::Contact(cLogger, p2, p1, pType, simDay, c_rate, tProbability);
189 if (h1.IsInfectious() && h2.IsSusceptible()) {
190 LP::Trans(cLogger, p1, p2, pType, simDay);
194 }
else if (h2.IsInfectious() && h1.IsSusceptible()) {
195 LP::Trans(cLogger, p2, p1, pType, simDay);
210 template <ContactLogMode::Id LL,
bool TIC>
213 unsigned short int simDay, shared_ptr<spdlog::logger> cLogger)
215 using LP = LOG_POLICY<LL>;
218 bool infectious_cases;
220 tie(infectious_cases, num_cases) = pool.
SortMembers();
222 if (!infectious_cases) {
230 const auto c_size = c_members.size();
234 for (
size_t i_infected = 0; i_infected < num_cases; i_infected++) {
236 const auto p1 = c_members[i_infected];
241 if (h1.IsInfectious()) {
242 const double c_rate_p1 = GetContactRate(profile, p1, c_size);
244 for (
size_t i_contact = num_cases; i_contact < c_immune; i_contact++) {
246 const auto p2 = c_members[i_contact];
250 const double c_rate_p2 = GetContactRate(profile, p2, c_size);
254 if (h1.IsInfectious() && h2.IsSusceptible()) {
259 LP::Trans(cLogger, p1, p2, c_type, simDay);
std::vector< Person * > m_members
Pointers to contactpool members (raw pointers intentional).
Health & GetHealth()
Return person's health status.
Id
Enumerates the ContactPool types.
bool IsSurveyParticipant() const
Does this person participates in the social contact study?
Header file for the Person class.
A group of Persons that potentially have contacts with one another.
Header for the core ContactPool class.
string ToString(Id l)
Converts a LogMode value to corresponding name.
bool HasContactAndTransmission(double contact_rate, double transmission_probability)
Check if two individuals have contact and transmission.
bool HasTransmission(double transmission_probability)
Check whether transmission occurs.
unsigned int GetId() const
Get the id.
Processes the contacts between persons and determines whether transmission occurs.
float GetAge() const
Get the age.
ContactType::Id m_pool_type
The type of the ContactPool (for logging and testing purposes).
unsigned int m_index_immune
Index of the first immune member in the ContactPool.
Header for the Infector class.
bool IsInPool(const ContactType::Id &poolType) const
Check if a person is present today in a given contact pool.
std::tuple< bool, unsigned int > SortMembers()
Sort w.r.t. health status: order: exposed/infected/recovered, susceptible, immune.
unsigned int EffectiveAge(unsigned int age)
Effective age (topping of at maximum).
Actual contacts and transmission in contactpool (primary template).
Transmission probabilities from disease data.
double GetProbability() const
Return transmission probability.
Contact rates as a function of age.
Header file for the Calendar class.
Store and handle person data.
Namespace for the simulator and related classes.
bool IsSusceptible() const
Is this person susceptible?
void StartInfection()
Start the infection.
bool HasContact(double contact_rate)
Check if two individuals have contact.
Namespace to manage types of ContactPool.