-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
We may benefit from abstracting some common interventions/events that could be added across models. One I have been working on is the quarantine+isolation process. The following code snippet could be used in the future (it is not finalized and needs testing!):
// Generating a quarantine process as a global action.
template<typename TSeq>
inline epiworld::GlobalFun<TSeq> entity_quarantine_event_factory(
std::vector< size_t > states_to_quarantine,
size_t state_triggers_quarantine,
size_t quarantine_days,
double avg_days_undetected,
double quarantine_willingness,
size_t next_state,
size_t next_queue
) {
// Keeps track of when the agent was quarantined
std::shared_ptr< std::vector< int > > day_flagged_ptr(
new std::vector< int >(0)
);
std::shared_ptr< std::vector< bool > > willingness_ptr(
new std::vector< bool >(0)
);
// Other variables needed to keep track
std::shared_ptr< size_t > quarantine_days_ptr(
new size_t(quarantine_days)
);
// Status of the entity
std::shared_ptr< std::vector< bool > > status_ptr(
new std::vector< bool >(0)
);
epiworld::GlobalFun<TSeq> quarantine_fun = [
states_to_quarantine,
state_triggers_quarantine,
day_flagged_ptr,
quarantine_days_ptr,
status_ptr,
quarantine_willingness,
avg_days_undetected,
next_state,
next_queue
](
epiworld::Model<TSeq> * m
) -> void
{
// Checking if need to be resetted
auto today = m->today();
if (today == 0)
{
// Resizing the vectors
day_flagged_ptr->resize(m->size());
std::fill(day_flagged_ptr->begin(), day_flagged_ptr->end(), -1);
// Whether agents will quarantine or not
willingness_ptr->resize(m->size());
for (auto & w: *willingness_ptr)
w = m->runif() > quarantine_willingness;
// Resizing the status vector
status_ptr->resize(m->get_n_entities());
std::fill(status_ptr->begin(), status_ptr->end(), false);
}
// Checking if a quarantine is needed or not
for (auto & a : m->get_agents())
{
if (a.get_state() == state_triggers_quarantine)
{
// Will be discovered?
if (m->runif() < 1.0/avg_days_undetected)
{
day_flagged_ptr->at(a.get_id()) = today;
status_ptr->at(a.get_entity(0u).get_id()) = true;
break;
}
}
}
return;
};
}Reactions are currently unavailable