diff --git a/Makefile b/Makefile index 167cea8a..659eab4a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ local-update: rsync -avz ../epiworld/include/epiworld inst/include/. check: build - R CMD check epiworldR_*.tar.gz + cd .. && R CMD check epiworldR_*.tar.gz clean: Rscript --vanilla -e 'devtools::clean_dll()' diff --git a/NAMESPACE b/NAMESPACE index 59038b3d..887ea275 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -58,7 +58,7 @@ S3method(plot,epiworld_surv) S3method(print,epiworld_agent) S3method(print,epiworld_agents) S3method(print,epiworld_agents_tools) -S3method(print,epiworld_globalaction) +S3method(print,epiworld_globalevent) S3method(print,epiworld_model) S3method(print,epiworld_saver) S3method(print,epiworld_tool) @@ -90,7 +90,7 @@ export(ModelSIRLogit) export(ModelSIS) export(ModelSISD) export(ModelSURV) -export(add_global_action) +export(add_globalevent) export(add_tool) export(add_tool_agent) export(add_tool_n) @@ -131,6 +131,10 @@ export(globalaction_fun) export(globalaction_set_params) export(globalaction_tool) export(globalaction_tool_logit) +export(globalevent_fun) +export(globalevent_set_params) +export(globalevent_tool) +export(globalevent_tool_logit) export(has_tool) export(has_virus) export(initial_states) diff --git a/R/cpp11.R b/R/cpp11.R index d799599d..0b5eb2c2 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -1,31 +1,31 @@ # Generated by cpp11: do not edit by hand -globalaction_tool_logit_cpp <- function(tool, vars, coefs, name, day) { - .Call(`_epiworldR_globalaction_tool_logit_cpp`, tool, vars, coefs, name, day) +globalevent_tool_logit_cpp <- function(tool, vars, coefs, name, day) { + .Call(`_epiworldR_globalevent_tool_logit_cpp`, tool, vars, coefs, name, day) } -globalaction_tool_cpp <- function(tool, prob, name, day) { - .Call(`_epiworldR_globalaction_tool_cpp`, tool, prob, name, day) +globalevent_tool_cpp <- function(tool, prob, name, day) { + .Call(`_epiworldR_globalevent_tool_cpp`, tool, prob, name, day) } -globalaction_set_param_cpp <- function(param, value, name, day) { - .Call(`_epiworldR_globalaction_set_param_cpp`, param, value, name, day) +globalevent_set_param_cpp <- function(param, value, name, day) { + .Call(`_epiworldR_globalevent_set_param_cpp`, param, value, name, day) } print_global_action_cpp <- function(action) { .Call(`_epiworldR_print_global_action_cpp`, action) } -add_global_action_cpp <- function(model, action) { - .Call(`_epiworldR_add_global_action_cpp`, model, action) +add_globalevent_cpp <- function(model, action) { + .Call(`_epiworldR_add_globalevent_cpp`, model, action) } -rm_global_action_cpp <- function(model, name) { - .Call(`_epiworldR_rm_global_action_cpp`, model, name) +rm_globalevent_cpp <- function(model, name) { + .Call(`_epiworldR_rm_globalevent_cpp`, model, name) } -globalaction_fun_cpp <- function(fun, name, day) { - .Call(`_epiworldR_globalaction_fun_cpp`, fun, name, day) +globalevent_fun_cpp <- function(fun, name, day) { + .Call(`_epiworldR_globalevent_fun_cpp`, fun, name, day) } get_agents_cpp <- function(model) { diff --git a/R/functions-renamed.R b/R/functions-renamed.R new file mode 100644 index 00000000..2726e6a6 --- /dev/null +++ b/R/functions-renamed.R @@ -0,0 +1,7 @@ +#' Deprecated functions in epiworldR +#' @description +#' Starting version 0.0-4, epiworld changed how it refered to "actions." +#' Following more traditional ABMs, actions are now called "events." +#' @param ... Arguments to be passed to the new function. +#' @name epiworldR-deprecated +NULL \ No newline at end of file diff --git a/R/global-actions.R b/R/global-actions.R index d6ec4487..163b7fe8 100644 --- a/R/global-actions.R +++ b/R/global-actions.R @@ -31,8 +31,8 @@ #' #' #' # Adding a global action -#' vaccine_day_20 <- globalaction_tool(epitool, .2, day = 20) -#' add_global_action(model_sirconn, vaccine_day_20) +#' vaccine_day_20 <- globalevent_tool(epitool, .2, day = 20) +#' add_globalevent(model_sirconn, vaccine_day_20) #' #' # Running and printing #' run(model_sirconn, ndays = 40, seed = 1912) @@ -49,52 +49,64 @@ #' recovery_rate = 0.95 #' ) #' -#' closure_day_10 <- globalaction_set_params("Contact rate", 0, day = 10) -#' add_global_action(model_sirconn2, closure_day_10) +#' closure_day_10 <- globalevent_set_params("Contact rate", 0, day = 10) +#' add_globalevent(model_sirconn2, closure_day_10) #' #' # Running and printing #' run(model_sirconn2, ndays = 40, seed = 1912) #' model_sirconn2 #' plot_incidence(model_sirconn2) #' @returns -#' - The `globalaction_set_params` function returns an object of class -#' [epiworld_globalaction_set_param] and [epiworld_globalaction]. +#' - The `globalevent_set_params` function returns an object of class +#' [epiworld_globalevent_set_param] and [epiworld_globalevent]. #' -#' - `globalaction_tool` returns an object of class -#' [epiworld_globalaction_tool] and [epiworld_globalaction]. +#' - `globalevent_tool` returns an object of class +#' [epiworld_globalevent_tool] and [epiworld_globalevent]. #' -#' - `globalaction_tool_logit` returns an object of class -#' [epiworld_globalaction_tool_logit] and [epiworld_globalaction]. +#' - `globalevent_tool_logit` returns an object of class +#' [epiworld_globalevent_tool_logit] and [epiworld_globalevent]. #' @aliases -#' epiworld_globalaction_set_param -#' epiworld_globalaction_tool -#' epiworld_globalaction_tool_logit -#' epiworld_globalaction +#' epiworld_globalevent_set_param +#' epiworld_globalevent_tool +#' epiworld_globalevent_tool_logit +#' epiworld_globalevent #' actions #' -globalaction_tool <- function( +globalevent_tool <- function( tool, prob, name = get_name_tool(tool), day = -99 ) { structure( - globalaction_tool_cpp(tool, prob, name, day), - class = c("epiworld_globalaction_tool", "epiworld_globalaction"), + globalevent_tool_cpp(tool, prob, name, day), + class = c("epiworld_globalevent_tool", "epiworld_globalevent"), tool = tool, call = match.call() ) } +#' @export +#' @rdname epiworldR-deprecated +globalaction_tool <- function(...) { + + .Deprecated( + new = "globalevent_tool" + ) + + globalevent_tool(...) + +} + #' @export #' @rdname global-actions #' @param vars Integer vector. The position of the variables in the model. #' @param coefs Numeric vector. The coefficients of the logistic regression. -#' @details The function `globalaction_tool_logit` allows to specify a logistic +#' @details The function `globalevent_tool_logit` allows to specify a logistic #' regression model for the probability of using a tool. The model is specified #' by the vector of coefficients `coefs` and the vector of variables `vars`. #' `vars` is an integer vector indicating the position of the variables in the #' model. -globalaction_tool_logit <- function( +globalevent_tool_logit <- function( tool, vars, coefs, name = get_name_tool(tool), day = -99 ) { @@ -102,54 +114,78 @@ globalaction_tool_logit <- function( stopifnot_tool(tool) structure( - globalaction_tool_logit_cpp( + globalevent_tool_logit_cpp( tool, as.integer(vars), as.double(coefs), name, as.integer(day) ), - class = c("epiworld_globalaction_tool_logit", "epiworld_globalaction"), + class = c("epiworld_globalevent_tool_logit", "epiworld_globalevent"), tool = tool, call = match.call() ) } +#' @export +#' @rdname epiworldR-deprecated +globalaction_tool_logit <- function(...) { + + .Deprecated( + new = "globalevent_tool_logit" + ) + + globalevent_tool_logit(...) + +} + #' @export #' @param param Character scalar. The name of the parameter to be set. #' @param value Numeric scalar. The value of the parameter. #' @rdname global-actions -#' @details The function `globalaction_set_param` allows to set a parameter of +#' @details The function `globalevent_set_param` allows to set a parameter of #' the model. The parameter is specified by its name `param` and the value by #' `value`. -globalaction_set_params <- function( +globalevent_set_params <- function( param, value, name = paste0("Set ", param, " to ", value), day = -99 ) { structure( - globalaction_set_param_cpp( + globalevent_set_param_cpp( param, as.double(value), name, as.integer(day) ), - class = c("epiworld_globalaction_set_param", "epiworld_globalaction"), + class = c("epiworld_globalevent_set_param", "epiworld_globalevent"), param = param, value = as.double(value), call = match.call() ) } +#' @export +#' @rdname epiworldR-deprecated +globalaction_set_params <- function(...) { + + .Deprecated( + new = "globalevent_set_params" + ) + + globalevent_set_params(...) + +} + #' @export #' @rdname global-actions #' @param fun Function. The function to be executed. -#' @details The function `globalaction_fun` allows to specify a function to be +#' @details The function `globalevent_fun` allows to specify a function to be #' executed at a given day. The function object must receive an object of class #' [epiworld_model] as only argument. #' @examples -#' # Example using `globalaction_fun` to record the state of the +#' # Example using `globalevent_fun` to record the state of the #' # agents at each time step. #' #' # We start by creating an SIR connected model @@ -179,13 +215,13 @@ globalaction_set_params <- function( #' ) #' #' } -globalaction_fun <- function( +globalevent_fun <- function( fun, name = deparse(substitute(fun)), day = -99 ) { structure( - globalaction_fun_cpp(fun, name, as.integer(day)), - class = c("epiworld_globalaction_fun", "epiworld_globalaction"), + globalevent_fun_cpp(fun, name, as.integer(day)), + class = c("epiworld_globalevent_fun", "epiworld_globalevent"), fun = fun, call = match.call() ) @@ -193,13 +229,25 @@ globalaction_fun <- function( } #' @export -print.epiworld_globalaction <- function(x, ...) { +#' @rdname epiworldR-deprecated +globalaction_fun <- function(...) { + + .Deprecated( + new = "globalevent_fun" + ) + + globalevent_fun(...) + +} + +#' @export +print.epiworld_globalevent <- function(x, ...) { print_global_action_cpp(x) cat("Call: ", deparse(attr(x, "call")), "\n") if (length(attr(x, "tool"))) { cat("Tool: ", get_name_tool(attr(x, "tool")), "\n") - } else if (inherits(x, "epiworld_globalaction_set_param")) { + } else if (inherits(x, "epiworld_globalevent_set_param")) { cat("Parameter: ", attr(x, "param"), "\n") cat("Value: ", attr(x, "value"), "\n") } @@ -215,20 +263,20 @@ print.epiworld_globalaction <- function(x, ...) { #' @param name Character scalar. The name of the action. #' @rdname global-actions #' @seealso epiworld-model -#' @details The function `add_global_action` adds a global action to a model. +#' @details The function `add_globalevent` adds a global action to a model. #' The model checks for actions to be executed at each time step. If the added #' action matches the current time step, the action is executed. When `day` is #' negative, the action is executed at each time step. When `day` is positive, #' the action is executed at the specified time step. #' @returns -#' - The function `add_global_action` returns the model with the added +#' - The function `add_globalevent` returns the model with the added #' action. -add_global_action <- function(model, action) { +add_globalevent <- function(model, action) { if (length(attr(action, "tool"))) add_tool_n(model, attr(action, "tool"), 0) - invisible(add_global_action_cpp(model, action)) + invisible(add_globalevent_cpp(model, action)) } diff --git a/README.Rmd b/README.Rmd index 7c9a5312..2a1828ae 100644 --- a/README.Rmd +++ b/README.Rmd @@ -205,7 +205,7 @@ net <- get_transmissions(sir) # Plotting library(epiworldR) -library(netplot) +library(epiworldR) x <- igraph::graph_from_edgelist( as.matrix(net[,2:3]) + 1 ) diff --git a/README.md b/README.md index b5881e8a..c9475237 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ net <- get_transmissions(sir) # Plotting library(epiworldR) -library(netplot) +library(epiworldR) #> Loading required package: grid x <- igraph::graph_from_edgelist( as.matrix(net[,2:3]) + 1 diff --git a/inst/include/epiworld/agent-bones.hpp b/inst/include/epiworld/agent-bones.hpp index 06bc77ce..1e83c069 100644 --- a/inst/include/epiworld/agent-bones.hpp +++ b/inst/include/epiworld/agent-bones.hpp @@ -26,7 +26,7 @@ template class Queue; template -struct Action; +struct Event; template class Entity; @@ -35,25 +35,25 @@ template class Entities; template -inline void default_add_virus(Action & a, Model * m); +inline void default_add_virus(Event & a, Model * m); template -inline void default_add_tool(Action & a, Model * m); +inline void default_add_tool(Event & a, Model * m); template -inline void default_add_entity(Action & a, Model * m); +inline void default_add_entity(Event & a, Model * m); template -inline void default_rm_virus(Action & a, Model * m); +inline void default_rm_virus(Event & a, Model * m); template -inline void default_rm_tool(Action & a, Model * m); +inline void default_rm_tool(Event & a, Model * m); template -inline void default_rm_entity(Action & a, Model * m); +inline void default_rm_entity(Event & a, Model * m); template -inline void default_change_state(Action & a, Model * m); +inline void default_change_state(Event & a, Model * m); @@ -72,13 +72,13 @@ class Agent { friend class Queue; friend class Entities; friend class AgentsSample; - friend void default_add_virus(Action & a, Model * m); - friend void default_add_tool(Action & a, Model * m); - friend void default_add_entity(Action & a, Model * m); - friend void default_rm_virus(Action & a, Model * m); - friend void default_rm_tool(Action & a, Model * m); - friend void default_rm_entity(Action & a, Model * m); - friend void default_change_state(Action & a, Model * m); + friend void default_add_virus(Event & a, Model * m); + friend void default_add_tool(Event & a, Model * m); + friend void default_add_entity(Event & a, Model * m); + friend void default_rm_virus(Event & a, Model * m); + friend void default_rm_tool(Event & a, Model * m); + friend void default_rm_entity(Event & a, Model * m); + friend void default_change_state(Event & a, Model * m); private: Model * model; diff --git a/inst/include/epiworld/agent-events-meat.hpp b/inst/include/epiworld/agent-events-meat.hpp new file mode 100644 index 00000000..8da043fb --- /dev/null +++ b/inst/include/epiworld/agent-events-meat.hpp @@ -0,0 +1,296 @@ +#ifndef EPIWORLD_AGENT_EVENTS_MEAT_HPP +#define EPIWORLD_AGENT_EVENTS_MEAT_HPP + +template +inline void default_add_virus(Event & a, Model * m) +{ + + Agent * p = a.agent; + VirusPtr v = a.virus; + + // Has a agent? If so, we need to register the transmission + if (v->get_agent()) + { + + // ... only if not the same agent + if (v->get_agent()->get_id() != p->get_id()) + m->get_db().record_transmission( + v->get_agent()->get_id(), + p->get_id(), + v->get_id(), + v->get_date() + ); + + } + + p->virus = std::make_shared< Virus >(*v); + p->virus->set_date(m->today()); + p->virus->set_agent(p); + + // Change of state needs to be recorded and updated on the + // tools. + if (p->state_prev != p->state) + { + auto & db = m->get_db(); + db.update_state(p->state_prev, p->state); + + for (size_t i = 0u; i < p->n_tools; ++i) + db.update_tool(p->tools[i]->get_id(), p->state_prev, p->state); + } + + // Lastly, we increase the daily count of the virus + #ifdef EPI_DEBUG + m->get_db().today_virus.at(v->get_id()).at(p->state)++; + #else + m->get_db().today_virus[v->get_id()][p->state]++; + #endif + +} + +template +inline void default_add_tool(Event & a, Model * m) +{ + + Agent * p = a.agent; + ToolPtr t = a.tool; + + // Update tool accounting + p->n_tools++; + size_t n_tools = p->n_tools; + + if (n_tools <= p->tools.size()) + p->tools[n_tools - 1] = std::make_shared< Tool >(*t); + else + p->tools.push_back(std::make_shared< Tool >(*t)); + + n_tools--; + + p->tools[n_tools]->set_date(m->today()); + p->tools[n_tools]->set_agent(p, n_tools); + + // Change of state needs to be recorded and updated on the + // tools. + if (p->state_prev != p->state) + { + auto & db = m->get_db(); + db.update_state(p->state_prev, p->state); + + if (p->virus) + db.update_virus(p->virus->get_id(), p->state_prev, p->state); + } + + m->get_db().today_tool[t->get_id()][p->state]++; + + +} + +template +inline void default_rm_virus(Event & a, Model * model) +{ + + Agent * p = a.agent; + VirusPtr & v = a.virus; + + // Calling the virus action over the removed virus + v->post_recovery(model); + + p->virus = nullptr; + + // Change of state needs to be recorded and updated on the + // tools. + if (p->state_prev != p->state) + { + auto & db = model->get_db(); + db.update_state(p->state_prev, p->state); + + for (size_t i = 0u; i < p->n_tools; ++i) + db.update_tool(p->tools[i]->get_id(), p->state_prev, p->state); + } + + // The counters of the virus only needs to decrease + #ifdef EPI_DEBUG + model->get_db().today_virus.at(v->get_id()).at(p->state_prev)--; + #else + model->get_db().today_virus[v->get_id()][p->state_prev]--; + #endif + + + return; + +} + +template +inline void default_rm_tool(Event & a, Model * m) +{ + + Agent * p = a.agent; + ToolPtr & t = a.agent->tools[a.tool->pos_in_agent]; + + if (--p->n_tools > 0) + { + p->tools[p->n_tools]->pos_in_agent = t->pos_in_agent; + std::swap( + p->tools[t->pos_in_agent], + p->tools[p->n_tools] + ); + } + + // Change of state needs to be recorded and updated on the + // tools. + if (p->state_prev != p->state) + { + auto & db = m->get_db(); + db.update_state(p->state_prev, p->state); + + if (p->virus) + db.update_virus(p->virus->get_id(), p->state_prev, p->state); + } + + // Lastly, we increase the daily count of the tool + #ifdef EPI_DEBUG + m->get_db().today_tool.at(t->get_id()).at(p->state_prev)--; + #else + m->get_db().today_tool[t->get_id()][p->state_prev]--; + #endif + + return; + +} + +template +inline void default_change_state(Event & a, Model * m) +{ + + Agent * p = a.agent; + + if (p->state_prev != p->state) + { + auto & db = m->get_db(); + db.update_state(p->state_prev, p->state); + + if (p->virus) + db.update_virus(p->virus->get_id(), p->state_prev, p->state); + + for (size_t i = 0u; i < p->n_tools; ++i) + db.update_tool(p->tools[i]->get_id(), p->state_prev, p->state); + + } + +} + +template +inline void default_add_entity(Event & a, Model *) +{ + + Agent * p = a.agent; + Entity * e = a.entity; + + // Checking the agent and the entity are not linked + if ((p->get_n_entities() > 0) && (e->size() > 0)) + { + + if (p->get_n_entities() > e->size()) // Slower search through the agent + { + for (size_t i = 0u; i < e->size(); ++i) + if(e->operator[](i)->get_id() == p->get_id()) + throw std::logic_error("An entity cannot be reassigned to an agent."); + } + else // Slower search through the entity + { + for (size_t i = 0u; i < p->get_n_entities(); ++i) + if(p->get_entity(i).get_id() == e->get_id()) + throw std::logic_error("An entity cannot be reassigned to an agent."); + } + + // It means that agent and entity were not associated. + } + + // Adding the entity to the agent + if (++p->n_entities <= p->entities.size()) + { + + p->entities[p->n_entities - 1] = e->get_id(); + p->entities_locations[p->n_entities - 1] = e->n_agents; + + } else + { + p->entities.push_back(e->get_id()); + p->entities_locations.push_back(e->n_agents); + } + + // Adding the agent to the entity + // Adding the entity to the agent + if (++e->n_agents <= e->agents.size()) + { + + e->agents[e->n_agents - 1] = p->get_id(); + // Adjusted by '-1' since the list of entities in the agent just grew. + e->agents_location[e->n_agents - 1] = p->n_entities - 1; + + } else + { + e->agents.push_back(p->get_id()); + e->agents_location.push_back(p->n_entities - 1); + } + + // Today was the last modification + // e->date_last_add_or_remove = m->today(); + +} + +template +inline void default_rm_entity(Event & a, Model * m) +{ + + Agent * p = a.agent; + Entity * e = a.entity; + size_t idx_agent_in_entity = a.idx_agent; + size_t idx_entity_in_agent = a.idx_object; + + if (--p->n_entities > 0) + { + + // When we move the end entity to the new location, the + // moved entity needs to reflect the change, i.e., where the + // entity will now be located in the agent + size_t agent_location_in_last_entity = p->entities_locations[p->n_entities]; + Entity * last_entity = &m->get_entities()[p->entities[p->n_entities]]; ///< Last entity of the agent + + // The end entity will be located where the removed was + last_entity->agents_location[agent_location_in_last_entity] = idx_entity_in_agent; + + // We now make the swap + std::swap( + p->entities[p->n_entities], + p->entities[idx_entity_in_agent] + ); + + } + + if (--e->n_agents > 0) + { + + // When we move the end agent to the new location, the + // moved agent needs to reflect the change, i.e., where the + // agent will now be located in the entity + size_t entity_location_in_last_agent = e->agents_location[e->n_agents]; + Agent * last_agent = &m->get_agents()[e->agents[e->n_agents]]; ///< Last agent of the entity + + // The end entity will be located where the removed was + last_agent->entities_locations[entity_location_in_last_agent] = idx_agent_in_entity; + + // We now make the swap + std::swap( + e->agents[e->n_agents], + e->agents[idx_agent_in_entity] + ); + + } + + // Setting the date of the last removal + // e->date_last_add_or_remove = m->today(); + + return; + +} +#endif \ No newline at end of file diff --git a/inst/include/epiworld/agent-meat.hpp b/inst/include/epiworld/agent-meat.hpp index 29500173..a5006b5d 100644 --- a/inst/include/epiworld/agent-meat.hpp +++ b/inst/include/epiworld/agent-meat.hpp @@ -8,7 +8,7 @@ else (proposed_) = (virus_tool_);} // To large to add directly here -#include "agent-actions-meat.hpp" +#include "agent-events-meat.hpp" template inline Agent::Agent() {} @@ -159,7 +159,7 @@ inline void Agent::add_tool( CHECK_COALESCE_(state_new, tool->state_init, state); CHECK_COALESCE_(queue, tool->queue_init, Queue::NoOne); - model->actions_add( + model->events_add( this, nullptr, tool, nullptr, state_new, queue, default_add_tool, -1, -1 ); @@ -195,7 +195,7 @@ inline void Agent::set_virus( CHECK_COALESCE_(state_new, virus->state_init, state); CHECK_COALESCE_(queue, virus->queue_init, Queue::NoOne); - model->actions_add( + model->events_add( this, virus, nullptr, nullptr, state_new, queue, default_add_virus, -1, -1 ); @@ -228,7 +228,7 @@ inline void Agent::add_entity( if (model != nullptr) { - model->actions_add( + model->events_add( this, nullptr, nullptr, &entity, state_new, queue, default_add_entity, -1, -1 ); @@ -237,7 +237,7 @@ inline void Agent::add_entity( // model entity { - Action a( + Event a( this, nullptr, nullptr, &entity, state_new, queue, default_add_entity, -1, -1 ); @@ -266,7 +266,7 @@ inline void Agent::rm_tool( std::to_string(n_tools) + " tools." ); - model->actions_add( + model->events_add( this, nullptr, tools[tool_idx], nullptr, state_new, queue, default_rm_tool, -1, -1 ); @@ -284,7 +284,7 @@ inline void Agent::rm_tool( if (tool->agent != this) throw std::logic_error("Cannot remove a virus from another agent!"); - model->actions_add( + model->events_add( this, nullptr, tool, nullptr, state_new, queue, default_rm_tool, -1, -1 ); @@ -306,7 +306,7 @@ inline void Agent::rm_virus( CHECK_COALESCE_(state_new, virus->state_post, state); CHECK_COALESCE_(queue, virus->queue_post, Queue::Everyone); - model->actions_add( + model->events_add( this, virus, nullptr, nullptr, state_new, queue, default_rm_virus, -1, -1 ); @@ -335,7 +335,7 @@ inline void Agent::rm_entity( CHECK_COALESCE_(state_new, model->entities[entity_idx].state_post, state); CHECK_COALESCE_(queue, model->entities[entity_idx].queue_post, Queue::NoOne); - model->actions_add( + model->events_add( this, nullptr, nullptr, model->entities[entity_idx], state_new, queue, default_rm_entity, entities_locations[entity_idx], entity_idx ); @@ -367,7 +367,7 @@ inline void Agent::rm_entity( CHECK_COALESCE_(state_new, entity.state_post, state); CHECK_COALESCE_(queue, entity.queue_post, Queue::NoOne); - model->actions_add( + model->events_add( this, nullptr, nullptr, entities[entity_idx], state_new, queue, default_rm_entity, entities_locations[entity_idx], entity_idx ); @@ -384,7 +384,7 @@ inline void Agent::rm_agent_by_virus( CHECK_COALESCE_(state_new, virus->state_removed, state); CHECK_COALESCE_(queue, virus->queue_removed, Queue::Everyone); - model->actions_add( + model->events_add( this, virus, nullptr, nullptr, state_new, queue, default_rm_virus, -1, -1 ); @@ -587,7 +587,7 @@ inline void Agent::change_state( ) { - model->actions_add( + model->events_add( this, nullptr, nullptr, nullptr, new_state, queue, default_change_state, -1, -1 ); @@ -687,16 +687,21 @@ inline void Agent::print( if (compressed) { printf_epiworld( - "Agent: %i, state: %s (%i), Has virus: %s, NTools: %i, NNeigh: %i\n", - id, model->states_labels[state].c_str(), static_cast(state), + "Agent: %i, state: %s (%i), Has virus: %s, NTools: %ii NNeigh: %i\n", + static_cast(id), + model->states_labels[state].c_str(), + static_cast(state), virus == nullptr ? std::string("no").c_str() : std::string("yes").c_str(), - static_cast(n_tools), static_cast(neighbors.size()) + static_cast(n_tools), + static_cast(neighbors.size()) ); } else { - printf_epiworld("Information about agent id %i\n", this->id); - printf_epiworld(" State : %s (%i)\n", model->states_labels[state].c_str(), static_cast(state)); + printf_epiworld("Information about agent id %i\n", + static_cast(this->id)); + printf_epiworld(" State : %s (%i)\n", + model->states_labels[state].c_str(), static_cast(state)); printf_epiworld(" Has virus : %s\n", virus == nullptr ? std::string("no").c_str() : std::string("yes").c_str()); printf_epiworld(" Tool count : %i\n", static_cast(n_tools)); @@ -706,7 +711,10 @@ inline void Agent::print( if (nfeats > 0) { - printf_epiworld("This model includes features (%lu): [ ", nfeats); + printf_epiworld( + "This model includes features (%i): [ ", + static_cast(nfeats) + ); int max_to_show = static_cast((nfeats > 10)? 10 : nfeats); diff --git a/inst/include/epiworld/config.hpp b/inst/include/epiworld/config.hpp index 633dd0fd..852243d9 100644 --- a/inst/include/epiworld/config.hpp +++ b/inst/include/epiworld/config.hpp @@ -88,10 +88,10 @@ template using GlobalFun = std::function*)>; template -struct Action; +struct Event; template -using ActionFun = std::function&,Model*)>; +using ActionFun = std::function&,Model*)>; /** * @brief Decides how to distribute viruses at initialization @@ -112,12 +112,12 @@ template using EntityToAgentFun = std::function&,Model*)>; /** - * @brief Action data for update an agent + * @brief Event data for update an agent * * @tparam TSeq */ template -struct Action { +struct Event { Agent * agent; VirusPtr virus; ToolPtr tool; @@ -129,7 +129,7 @@ struct Action { int idx_object; public: /** - * @brief Construct a new Action object + * @brief Construct a new Event object * * All the parameters are rather optional. * @@ -144,7 +144,7 @@ struct Action { * @param idx_agent_ Location of agent in object. * @param idx_object_ Location of object in agent. */ - Action( + Event( Agent * agent_, VirusPtr virus_, ToolPtr tool_, diff --git a/inst/include/epiworld/database-bones.hpp b/inst/include/epiworld/database-bones.hpp index a57f37a1..3d64ea00 100644 --- a/inst/include/epiworld/database-bones.hpp +++ b/inst/include/epiworld/database-bones.hpp @@ -11,19 +11,19 @@ template class UserData; template -inline void default_add_virus(Action & a, Model * m); +inline void default_add_virus(Event & a, Model * m); template -inline void default_add_tool(Action & a, Model * m); +inline void default_add_tool(Event & a, Model * m); template -inline void default_rm_virus(Action & a, Model * m); +inline void default_rm_virus(Event & a, Model * m); template -inline void default_rm_tool(Action & a, Model * m); +inline void default_rm_tool(Event & a, Model * m); template -inline void default_change_state(Action & a, Model * m); +inline void default_change_state(Event & a, Model * m); /** * @brief Statistical data about the process @@ -33,11 +33,11 @@ inline void default_change_state(Action & a, Model * m); template class DataBase { friend class Model; - friend void default_add_virus(Action & a, Model * m); - friend void default_add_tool(Action & a, Model * m); - friend void default_rm_virus(Action & a, Model * m); - friend void default_rm_tool(Action & a, Model * m); - friend void default_change_state(Action & a, Model * m); + friend void default_add_virus(Event & a, Model * m); + friend void default_add_tool(Event & a, Model * m); + friend void default_rm_virus(Event & a, Model * m); + friend void default_rm_tool(Event & a, Model * m); + friend void default_change_state(Event & a, Model * m); private: Model * model; diff --git a/inst/include/epiworld/database-meat.hpp b/inst/include/epiworld/database-meat.hpp index 926c5227..95e641bb 100644 --- a/inst/include/epiworld/database-meat.hpp +++ b/inst/include/epiworld/database-meat.hpp @@ -821,9 +821,9 @@ inline void DataBase::write_data( file_virus << #ifdef EPI_DEBUG - "thread "<< "date " << "id " << "state " << "n\n"; + "thread "<< "date " << "virus_id " << "virus " << "state " << "n\n"; #else - "date " << "virus_id virus" << "state " << "n\n"; + "date " << "virus_id " << "virus " << "state " << "n\n"; #endif for (epiworld_fast_uint i = 0; i < hist_virus_id.size(); ++i) diff --git a/inst/include/epiworld/entity-bones.hpp b/inst/include/epiworld/entity-bones.hpp index b5666a42..6e2ac160 100644 --- a/inst/include/epiworld/entity-bones.hpp +++ b/inst/include/epiworld/entity-bones.hpp @@ -11,18 +11,18 @@ template class AgentsSample; template -inline void default_add_entity(Action & a, Model * m); +inline void default_add_entity(Event & a, Model * m); template -inline void default_rm_entity(Action & a, Model * m); +inline void default_rm_entity(Event & a, Model * m); template class Entity { friend class Agent; friend class AgentsSample; friend class Model; - friend void default_add_entity(Action & a, Model * m); - friend void default_rm_entity(Action & a, Model * m); + friend void default_add_entity(Event & a, Model * m); + friend void default_rm_entity(Event & a, Model * m); private: Model * model; diff --git a/inst/include/epiworld/entity-meat.hpp b/inst/include/epiworld/entity-meat.hpp index 6912ec52..4c5a30d4 100644 --- a/inst/include/epiworld/entity-meat.hpp +++ b/inst/include/epiworld/entity-meat.hpp @@ -8,7 +8,7 @@ inline void Entity::add_agent( ) { - // Need to add it to the actions, through the individual + // Need to add it to the events, through the individual p.add_entity(*this, model); } diff --git a/inst/include/epiworld/epiworld.hpp b/inst/include/epiworld/epiworld.hpp index 583878ff..d1693bde 100644 --- a/inst/include/epiworld/epiworld.hpp +++ b/inst/include/epiworld/epiworld.hpp @@ -42,8 +42,8 @@ namespace epiworld { #include "queue-bones.hpp" - #include "globalactions-bones.hpp" - #include "globalactions-meat.hpp" + #include "globalevent-bones.hpp" + #include "globalevent-meat.hpp" #include "model-bones.hpp" #include "model-meat.hpp" diff --git a/inst/include/epiworld/globalevent-bones.hpp b/inst/include/epiworld/globalevent-bones.hpp new file mode 100644 index 00000000..22d3069c --- /dev/null +++ b/inst/include/epiworld/globalevent-bones.hpp @@ -0,0 +1,53 @@ +#ifndef EPIWORLD_GLOBALEVENT_BONES_HPP +#define EPIWORLD_GLOBALEVENT_BONES_HPP + +// template +// using GlobalFun = std::function*)>; + +/** + * @brief Template for a Global Event + * @details Global events are functions that Model executes + * at the end of a day. + * + */ +template +class GlobalEvent +{ +private: + GlobalFun fun = nullptr; + std::string name = "A global action"; + int day = -99; +public: + + GlobalEvent() {}; + + /** + * @brief Construct a new Global Event object + * + * @param fun A function that takes a Model * as argument and returns void. + * @param name A descriptive name for the action. + * @param day The day when the action will be executed. If negative, it will be executed every day. + */ + GlobalEvent(GlobalFun fun, std::string name, int day = -99); + + ~GlobalEvent() {}; + + void operator()(Model * m, int day); + + void set_name(std::string name); + std::string get_name() const; + + void set_day(int day); + int get_day() const; + + void print() const; + + // Comparison operators + bool operator==(const GlobalEvent & other) const; + bool operator!=(const GlobalEvent & other) const; + +}; + + + +#endif diff --git a/inst/include/epiworld/globalevent-meat.hpp b/inst/include/epiworld/globalevent-meat.hpp new file mode 100644 index 00000000..62993bab --- /dev/null +++ b/inst/include/epiworld/globalevent-meat.hpp @@ -0,0 +1,78 @@ +#ifndef EPIWORLD_GLOBALEVENT_MEAT_HPP +#define EPIWORLD_GLOBALEVENT_MEAT_HPP + +template +inline GlobalEvent::GlobalEvent( + GlobalFun fun, + std::string name, + int day + ) +{ + this->fun = fun; + this->name = name; + this->day = day; +} + +template +inline void GlobalEvent::operator()(Model * m, int day) +{ + + if (this->fun == nullptr) + return; + + // events apply if day is negative or if day is equal to the day of the action + if (this->day < 0 || this->day == day) + this->fun(m); + + return; + +} + +template +inline void GlobalEvent::set_name(std::string name) +{ + this->name = name; +} + +template +inline std::string GlobalEvent::get_name() const +{ + return this->name; +} + +template +inline void GlobalEvent::set_day(int day) +{ + this->day = day; +} + +template +inline int GlobalEvent::get_day() const +{ + return this->day; +} + +template +inline void GlobalEvent::print() const +{ + printf_epiworld( + "Global action: %s\n" + " - Day: %i\n", + this->name.c_str(), + this->day + ); +} + +template +inline bool GlobalEvent::operator==(const GlobalEvent & other) const +{ + return (this->name == other.name) && (this->day == other.day); +} + +template +inline bool GlobalEvent::operator!=(const GlobalEvent & other) const +{ + return !(*this == other); +} + +#endif diff --git a/inst/include/epiworld/model-bones.hpp b/inst/include/epiworld/model-bones.hpp index 01efeea3..3b51e2a8 100644 --- a/inst/include/epiworld/model-bones.hpp +++ b/inst/include/epiworld/model-bones.hpp @@ -28,10 +28,10 @@ template class Queue; template -struct Action; +struct Event; template -class GlobalAction; +class GlobalEvent; template inline epiworld_double susceptibility_reduction_mixer_default( @@ -195,20 +195,20 @@ class Model { void chrono_start(); void chrono_end(); - std::vector> global_actions; + std::vector> globalevents; Queue queue; bool use_queuing = true; /** - * @brief Variables used to keep track of the actions + * @brief Variables used to keep track of the events * to be made regarding viruses. */ - std::vector< Action > actions = {}; + std::vector< Event > events = {}; epiworld_fast_uint nactions = 0u; /** - * @brief Construct a new Action object + * @brief Construct a new Event object * * @param agent_ Agent over which the action will be called * @param virus_ Virus pointer included in the action @@ -220,7 +220,7 @@ class Model { * @param idx_agent_ Location of agent in object. * @param idx_object_ Location of object in agent. */ - void actions_add( + void events_add( Agent * agent_, VirusPtr virus_, ToolPtr tool_, @@ -637,23 +637,23 @@ class Model { * at the end of every day. Otherwise, the function will be called only * at the end of the indicated date. */ - void add_global_action( + void add_globalevent( std::function*)> fun, std::string name = "A global action", int date = -99 ); - void add_global_action( - GlobalAction action + void add_globalevent( + GlobalEvent action ); - GlobalAction & get_global_action(std::string name); ///< Retrieve a global action by name - GlobalAction & get_global_action(size_t i); ///< Retrieve a global action by index + GlobalEvent & get_globalevent(std::string name); ///< Retrieve a global action by name + GlobalEvent & get_globalevent(size_t i); ///< Retrieve a global action by index - void rm_global_action(std::string name); ///< Remove a global action by name - void rm_global_action(size_t i); ///< Remove a global action by index + void rm_globalevent(std::string name); ///< Remove a global action by name + void rm_globalevent(size_t i); ///< Remove a global action by index - void run_global_actions(); + void run_globalevents(); void clear_state_set(); @@ -722,7 +722,7 @@ class Model { * * @param model_ Model over which it will be executed. */ - void actions_run(); + void events_run(); }; diff --git a/inst/include/epiworld/model-meat-print.hpp b/inst/include/epiworld/model-meat-print.hpp index 53fd3790..f17f0c00 100644 --- a/inst/include/epiworld/model-meat-print.hpp +++ b/inst/include/epiworld/model-meat-print.hpp @@ -121,9 +121,9 @@ inline const Model & Model::print(bool lite) const printf_epiworld("Rewiring : off\n\n"); } - // Printing global actions - printf_epiworld("Global actions:\n"); - for (auto & a : global_actions) + // Printing Global events + printf_epiworld("Global events:\n"); + for (auto & a : globalevents) { if (a.get_day() < 0) { @@ -133,7 +133,7 @@ inline const Model & Model::print(bool lite) const } } - if (global_actions.size() == 0u) + if (globalevents.size() == 0u) { printf_epiworld(" (none)\n"); } @@ -145,7 +145,10 @@ inline const Model & Model::print(bool lite) const if ((n_viruses_model > 10) && (i >= 10)) { - printf_epiworld(" ...and %li more viruses...\n", static_cast(n_viruses_model) - i); + printf_epiworld(" ...and %i more viruses...\n", + static_cast(n_viruses_model) - + static_cast(i) + ); break; } @@ -184,6 +187,14 @@ inline const Model & Model::print(bool lite) const } + auto nvariants = db.get_n_viruses() - n_viruses_model; + if (nvariants > 0) + { + + printf_epiworld(" ...and %i more variants...\n", static_cast(nvariants)); + + } + if (viruses.size() == 0u) { printf_epiworld(" (none)\n"); @@ -196,7 +207,10 @@ inline const Model & Model::print(bool lite) const if ((n_tools_model > 10) && (i >= 10)) { - printf_epiworld(" ...and %li more tools...\n", static_cast(n_tools_model) - i); + printf_epiworld( + " ...and %i more tools...\n", + static_cast(n_tools_model) - static_cast(i) + ); break; } diff --git a/inst/include/epiworld/model-meat.hpp b/inst/include/epiworld/model-meat.hpp index ce7e59b8..03075212 100644 --- a/inst/include/epiworld/model-meat.hpp +++ b/inst/include/epiworld/model-meat.hpp @@ -150,7 +150,7 @@ inline std::function*)> make_save_run( template -inline void Model::actions_add( +inline void Model::events_add( Agent * agent_, VirusPtr virus_, ToolPtr tool_, @@ -169,11 +169,11 @@ inline void Model::actions_add( throw std::logic_error("Actions cannot be zero!!"); #endif - if (nactions > actions.size()) + if (nactions > events.size()) { - actions.emplace_back( - Action( + events.emplace_back( + Event( agent_, virus_, tool_, entity_, new_state_, queue_, call_, idx_agent_, idx_object_ )); @@ -182,7 +182,7 @@ inline void Model::actions_add( else { - Action & A = actions.at(nactions - 1u); + Event & A = events.at(nactions - 1u); A.agent = agent_; A.virus = virus_; @@ -201,14 +201,14 @@ inline void Model::actions_add( } template -inline void Model::actions_run() +inline void Model::events_run() { // Making the call - size_t nactions_tmp = 0; - while (nactions_tmp < nactions) + size_t nevents_tmp = 0; + while (nevents_tmp < nactions) { - Action & a = actions[nactions_tmp++]; + Event & a = events[nevents_tmp++]; Agent * p = a.agent; #ifdef EPI_DEBUG @@ -403,7 +403,7 @@ inline Model::Model(const Model & model) : nstates(model.nstates), verbose(model.verbose), current_date(model.current_date), - global_actions(model.global_actions), + globalevents(model.globalevents), queue(model.queue), use_queuing(model.use_queuing), array_double_tmp(model.array_double_tmp.size()), @@ -488,7 +488,7 @@ inline Model::Model(Model && model) : nstates(model.nstates), verbose(model.verbose), current_date(std::move(model.current_date)), - global_actions(std::move(model.global_actions)), + globalevents(std::move(model.globalevents)), queue(std::move(model.queue)), use_queuing(model.use_queuing), array_double_tmp(model.array_double_tmp.size()), @@ -563,7 +563,7 @@ inline Model & Model::operator=(const Model & m) current_date = m.current_date; - global_actions = m.global_actions; + globalevents = m.globalevents; queue = m.queue; use_queuing = m.use_queuing; @@ -798,8 +798,8 @@ inline void Model::dist_virus() } - // Apply the actions - actions_run(); + // Apply the events + events_run(); } } @@ -858,8 +858,8 @@ inline void Model::dist_tools() } - // Apply the actions - actions_run(); + // Apply the events + events_run(); } @@ -915,8 +915,8 @@ inline void Model::dist_tools() // } -// // Apply the actions -// actions_run(); +// // Apply the events +// events_run(); // } @@ -1546,8 +1546,8 @@ inline Model & Model::run( // user needs. this->update_state(); - // We start with the global actions - this->run_global_actions(); + // We start with the Global events + this->run_globalevents(); // In this case we are applying degree sequence rewiring // to change the network just a bit. @@ -1789,7 +1789,7 @@ inline void Model::update_state() { } - actions_run(); + events_run(); } @@ -2412,15 +2412,15 @@ inline UserData & Model::get_user_data() } template -inline void Model::add_global_action( +inline void Model::add_globalevent( std::function*)> fun, std::string name, int date ) { - global_actions.push_back( - GlobalAction( + globalevents.push_back( + GlobalEvent( fun, name, date @@ -2430,20 +2430,20 @@ inline void Model::add_global_action( } template -inline void Model::add_global_action( - GlobalAction action +inline void Model::add_globalevent( + GlobalEvent action ) { - global_actions.push_back(action); + globalevents.push_back(action); } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_globalevent( std::string name ) { - for (auto & a : global_actions) + for (auto & a : globalevents) if (a.name == name) return a; @@ -2452,30 +2452,30 @@ GlobalAction & Model::get_global_action( } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_globalevent( size_t index ) { - if (index >= global_actions.size()) + if (index >= globalevents.size()) throw std::range_error("The index " + std::to_string(index) + " is out of range."); - return global_actions[index]; + return globalevents[index]; } // Remove implementation template -inline void Model::rm_global_action( +inline void Model::rm_globalevent( std::string name ) { - for (auto it = global_actions.begin(); it != global_actions.end(); ++it) + for (auto it = globalevents.begin(); it != globalevents.end(); ++it) { if (it->get_name() == name) { - global_actions.erase(it); + globalevents.erase(it); return; } } @@ -2486,26 +2486,26 @@ inline void Model::rm_global_action( // Same as above, but the index implementation template -inline void Model::rm_global_action( +inline void Model::rm_globalevent( size_t index ) { - if (index >= global_actions.size()) + if (index >= globalevents.size()) throw std::range_error("The index " + std::to_string(index) + " is out of range."); - global_actions.erase(global_actions.begin() + index); + globalevents.erase(globalevents.begin() + index); } template -inline void Model::run_global_actions() +inline void Model::run_globalevents() { - for (auto & action: global_actions) + for (auto & action: globalevents) { action(this, today()); - actions_run(); + events_run(); } } @@ -2788,7 +2788,7 @@ inline bool Model::operator==(const Model & other) const "Model:: current_date don't match" ) - VECT_MATCH(global_actions, other.global_actions, "global action don't match"); + VECT_MATCH(globalevents, other.globalevents, "global action don't match"); EPI_DEBUG_FAIL_AT_TRUE( queue != other.queue, diff --git a/inst/include/epiworld/models/globalevents.hpp b/inst/include/epiworld/models/globalevents.hpp new file mode 100644 index 00000000..10097bcd --- /dev/null +++ b/inst/include/epiworld/models/globalevents.hpp @@ -0,0 +1,141 @@ +#ifndef EPIWORLD_GLOBALEVENTS_HPP +#define EPIWORLD_GLOBALEVENTS_HPP + +// This function creates a global action that distributes a tool +// to agents with probability p. +/** + * @brief Global event that distributes a tool to agents with probability p. + * + * @tparam TSeq Sequence type (should match `TSeq` across the model) + * @param p Probability of distributing the tool. + * @param tool Tool function. + * @return std::function*)> + */ +template +inline std::function*)> globalevent_tool( + Tool & tool, + double p +) { + + std::function*)> fun = [p,&tool]( + Model * model + ) -> void { + + for (auto & agent : model->get_agents()) + { + + // Check if the agent has the tool + if (agent.has_tool(tool)) + continue; + + // Adding the tool + if (model->runif() < p) + agent.add_tool(tool, model); + + + } + + #ifdef EPIWORLD_DEBUG + tool.print(); + #endif + + return; + + + }; + + return fun; + +} + +// Same function as above, but p is now a function of a vector of coefficients +// and a vector of variables. +/** + * @brief Global event that distributes a tool to agents with probability + * p = 1 / (1 + exp(-\sum_i coef_i * agent(vars_i))). + * + * @tparam TSeq Sequence type (should match `TSeq` across the model) + * @param coefs Vector of coefficients. + * @param vars Vector of variables. + * @param tool_fun Tool function. + * @return std::function*)> + */ +template +inline std::function*)> globalevent_tool_logit( + Tool & tool, + std::vector< size_t > vars, + std::vector< double > coefs +) { + + std::function*)> fun = [coefs,vars,&tool]( + Model * model + ) -> void { + + for (auto & agent : model->get_agents()) + { + + // Check if the agent has the tool + if (agent.has_tool(tool)) + continue; + + // Computing the probability using a logit. Uses OpenMP reduction + // to sum the coefficients. + double p = 0.0; + #if defined(__OPENMP) || defined(_OPENMP) + #pragma omp parallel for reduction(+:p) + #endif + for (size_t i = 0u; i < coefs.size(); ++i) + p += coefs.at(i) * agent(vars[i]); + + p = 1.0 / (1.0 + std::exp(-p)); + + // Adding the tool + if (model->runif() < p) + agent.add_tool(tool, model); + + + } + + #ifdef EPIWORLD_DEBUG + tool.print(); + #endif + + return; + + + }; + + return fun; + +} + +// A global action that updates a parameter in the model. +/** + * @brief Global event that updates a parameter in the model. + * + * @tparam TSeq Sequence type (should match `TSeq` across the model) + * @param param Parameter to update. + * @param value Value to update the parameter to. + * @return std::function*)> + */ +template +inline std::function*)> globalevent_set_param( + std::string param, + double value +) { + + std::function*)> fun = [value,param]( + Model * model + ) -> void { + + model->set_param(param, value); + + return; + + + }; + + return fun; + +} +#endif \ No newline at end of file diff --git a/inst/include/epiworld/models/init-functions.hpp b/inst/include/epiworld/models/init-functions.hpp index 660d5db8..f63366df 100644 --- a/inst/include/epiworld/models/init-functions.hpp +++ b/inst/include/epiworld/models/init-functions.hpp @@ -58,8 +58,8 @@ inline std::function*)> create_init_function_sir( for (auto & agent : sample) agent->change_state(model, 2, Queue::NoOne); - // Running the actions - model->actions_run(); + // Running the events + model->events_run(); return; @@ -146,8 +146,8 @@ inline std::function*)> create_init_function_sird( for (auto & agent : sample_deceased) agent->change_state(model, 3, Queue::NoOne); - // Running the actions - model->actions_run(); + // Running the events + model->events_run(); return; @@ -226,8 +226,8 @@ inline std::function*)> create_init_function_seir( for (auto & agent : sample_exposed) agent->change_state(model, 2, Queue::NoOne); - // Running the actions - model->actions_run(); + // Running the events + model->events_run(); return; @@ -311,8 +311,8 @@ inline std::function*)> create_init_function_seird( for (auto & agent : sample_exposed) agent->change_state(model, 2, Queue::NoOne); - // Running the actions - model->actions_run(); + // Running the events + model->events_run(); // Setting the initial states for the deceased epiworld::AgentsSample sample_deceased( @@ -326,8 +326,8 @@ inline std::function*)> create_init_function_seird( for (auto & agent : sample_deceased) agent->change_state(model, 4, Queue::NoOne); - // Running the actions - model->actions_run(); + // Running the events + model->events_run(); return; diff --git a/inst/include/epiworld/models/models.hpp b/inst/include/epiworld/models/models.hpp index 6c01abe4..72cfc860 100644 --- a/inst/include/epiworld/models/models.hpp +++ b/inst/include/epiworld/models/models.hpp @@ -5,7 +5,7 @@ namespace epimodels { #include "init-functions.hpp" - #include "globalactions.hpp" + #include "globalevents.hpp" #include "sis.hpp" #include "sir.hpp" #include "seir.hpp" diff --git a/inst/include/epiworld/models/seirconnected_logit.hpp b/inst/include/epiworld/models/seirconnected_logit.hpp index 397aa95b..ba871ac3 100644 --- a/inst/include/epiworld/models/seirconnected_logit.hpp +++ b/inst/include/epiworld/models/seirconnected_logit.hpp @@ -287,7 +287,7 @@ inline ModelSEIRCONNLogit::ModelSEIRCONNLogit( model.add_virus(virus, prevalence); // Adding updating function - model.add_global_action(global_accounting, "Accounting", -1); + model.add_globalevent(global_accounting, "Accounting", -1); model.queuing_off(); // No queuing need diff --git a/inst/include/epiworld/models/surveillance.hpp b/inst/include/epiworld/models/surveillance.hpp index 81fd83b9..5afd6abb 100644 --- a/inst/include/epiworld/models/surveillance.hpp +++ b/inst/include/epiworld/models/surveillance.hpp @@ -333,7 +333,7 @@ inline ModelSURV::ModelSURV( model.add_virus_n(covid, prevalence); model.set_user_data({"nsampled", "ndetected", "ndetected_asympt", "nasymptomatic"}); - model.add_global_action(surveillance_program, "Surveilance program", -1); + model.add_globalevent(surveillance_program, "Surveilance program", -1); // Vaccine tool ----------------------------------------------------------- epiworld::Tool vax("Vaccine"); diff --git a/inst/include/epiworld/tool-bones.hpp b/inst/include/epiworld/tool-bones.hpp index 9cd56b27..8e877eab 100644 --- a/inst/include/epiworld/tool-bones.hpp +++ b/inst/include/epiworld/tool-bones.hpp @@ -23,8 +23,8 @@ template class Tool { friend class Agent; friend class Model; - friend void default_add_tool(Action & a, Model * m); - friend void default_rm_tool(Action & a, Model * m); + friend void default_add_tool(Event & a, Model * m); + friend void default_rm_tool(Event & a, Model * m); private: Agent * agent = nullptr; diff --git a/inst/include/epiworld/tool-meat.hpp b/inst/include/epiworld/tool-meat.hpp index 6d2180a7..604ca2ec 100644 --- a/inst/include/epiworld/tool-meat.hpp +++ b/inst/include/epiworld/tool-meat.hpp @@ -488,12 +488,12 @@ template inline void Tool::print() const { - printf_epiworld("Tool : %s\n", tool_name->c_str()); - printf_epiworld("Id : %s\n", (id < 0)? std::string("(empty)").c_str() : std::to_string(id).c_str()); - printf_epiworld("state_init : %i\n", static_cast(state_init)); - printf_epiworld("state_post : %i\n", static_cast(state_post)); - printf_epiworld("queue_init : %i\n", static_cast(queue_init)); - printf_epiworld("queue_post : %i\n", static_cast(queue_post)); + printf_epiworld("Tool : %s\n", tool_name->c_str()); + printf_epiworld("Id : %s\n", (id < 0)? std::string("(empty)").c_str() : std::to_string(id).c_str()); + printf_epiworld("state_init : %i\n", static_cast(state_init)); + printf_epiworld("state_post : %i\n", static_cast(state_post)); + printf_epiworld("queue_init : %i\n", static_cast(queue_init)); + printf_epiworld("queue_post : %i\n", static_cast(queue_post)); } diff --git a/inst/include/epiworld/virus-bones.hpp b/inst/include/epiworld/virus-bones.hpp index 8397e453..81a88368 100644 --- a/inst/include/epiworld/virus-bones.hpp +++ b/inst/include/epiworld/virus-bones.hpp @@ -25,8 +25,8 @@ class Virus { friend class Agent; friend class Model; friend class DataBase; - friend void default_add_virus(Action & a, Model * m); - friend void default_rm_virus(Action & a, Model * m); + friend void default_add_virus(Event & a, Model * m); + friend void default_rm_virus(Event & a, Model * m); private: Agent * agent = nullptr; diff --git a/inst/include/epiworld/virus-meat.hpp b/inst/include/epiworld/virus-meat.hpp index 1850f295..e27bc91f 100644 --- a/inst/include/epiworld/virus-meat.hpp +++ b/inst/include/epiworld/virus-meat.hpp @@ -675,14 +675,14 @@ template inline void Virus::print() const { - printf_epiworld("Virus : %s\n", virus_name->c_str()); - printf_epiworld("Id : %s\n", (id < 0)? std::string("(empty)").c_str() : std::to_string(id).c_str()); + printf_epiworld("Virus : %s\n", virus_name->c_str()); + printf_epiworld("Id : %s\n", (id < 0)? std::string("(empty)").c_str() : std::to_string(id).c_str()); printf_epiworld("state_init : %i\n", static_cast(state_init)); printf_epiworld("state_post : %i\n", static_cast(state_post)); printf_epiworld("state_removed : %i\n", static_cast(state_removed)); - printf_epiworld("queue_init : %i\n", static_cast(queue_init)); - printf_epiworld("queue_post : %i\n", static_cast(queue_post)); - printf_epiworld("queue_removed : %i\n", static_cast(queue_removed)); + printf_epiworld("queue_init : %i\n", static_cast(queue_init)); + printf_epiworld("queue_post : %i\n", static_cast(queue_post)); + printf_epiworld("queue_removed : %i\n", static_cast(queue_removed)); } diff --git a/inst/include/epiworld/viruses-bones.hpp b/inst/include/epiworld/viruses-bones.hpp index 4149e190..247df3be 100644 --- a/inst/include/epiworld/viruses-bones.hpp +++ b/inst/include/epiworld/viruses-bones.hpp @@ -94,7 +94,7 @@ inline void Viruses::print() const noexcept return; } - printf_epiworld("List of viruses (%i): ", static_cast(*n_viruses)); + printf_epiworld("List of viruses (%i): ", *n_viruses); // Printing the name of each virus separated by a comma for (size_t i = 0u; i < *n_viruses; ++i) diff --git a/man/epiworldR-deprecated.Rd b/man/epiworldR-deprecated.Rd new file mode 100644 index 00000000..15cdec94 --- /dev/null +++ b/man/epiworldR-deprecated.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/functions-renamed.R, R/global-actions.R +\name{epiworldR-deprecated} +\alias{epiworldR-deprecated} +\alias{globalaction_tool} +\alias{globalaction_tool_logit} +\alias{globalaction_set_params} +\alias{globalaction_fun} +\title{Deprecated functions in epiworldR} +\usage{ +globalaction_tool(...) + +globalaction_tool_logit(...) + +globalaction_set_params(...) + +globalaction_fun(...) +} +\arguments{ +\item{...}{Arguments to be passed to the new function.} +} +\description{ +Starting version 0.0-4, epiworld changed how it refered to "actions." +Following more traditional ABMs, actions are now called "events." +} diff --git a/man/global-actions.Rd b/man/global-actions.Rd index 4edd1068..062aedf3 100644 --- a/man/global-actions.Rd +++ b/man/global-actions.Rd @@ -2,21 +2,21 @@ % Please edit documentation in R/global-actions.R \name{global-actions} \alias{global-actions} -\alias{globalaction_tool} -\alias{epiworld_globalaction_set_param} -\alias{epiworld_globalaction_tool} -\alias{epiworld_globalaction_tool_logit} -\alias{epiworld_globalaction} +\alias{globalevent_tool} +\alias{epiworld_globalevent_set_param} +\alias{epiworld_globalevent_tool} +\alias{epiworld_globalevent_tool_logit} +\alias{epiworld_globalevent} \alias{actions} -\alias{globalaction_tool_logit} -\alias{globalaction_set_params} -\alias{globalaction_fun} -\alias{add_global_action} +\alias{globalevent_tool_logit} +\alias{globalevent_set_params} +\alias{globalevent_fun} +\alias{add_globalevent} \title{Global Actions} \usage{ -globalaction_tool(tool, prob, name = get_name_tool(tool), day = -99) +globalevent_tool(tool, prob, name = get_name_tool(tool), day = -99) -globalaction_tool_logit( +globalevent_tool_logit( tool, vars, coefs, @@ -24,16 +24,16 @@ globalaction_tool_logit( day = -99 ) -globalaction_set_params( +globalevent_set_params( param, value, name = paste0("Set ", param, " to ", value), day = -99 ) -globalaction_fun(fun, name = deparse(substitute(fun)), day = -99) +globalevent_fun(fun, name = deparse(substitute(fun)), day = -99) -add_global_action(model, action) +add_globalevent(model, action) } \arguments{ \item{tool}{An object of class \link{tool}.} @@ -60,16 +60,16 @@ add_global_action(model, action) } \value{ \itemize{ -\item The \code{globalaction_set_params} function returns an object of class -\link{epiworld_globalaction_set_param} and \link{epiworld_globalaction}. -\item \code{globalaction_tool} returns an object of class -\link{epiworld_globalaction_tool} and \link{epiworld_globalaction}. -\item \code{globalaction_tool_logit} returns an object of class -\link{epiworld_globalaction_tool_logit} and \link{epiworld_globalaction}. +\item The \code{globalevent_set_params} function returns an object of class +\link{epiworld_globalevent_set_param} and \link{epiworld_globalevent}. +\item \code{globalevent_tool} returns an object of class +\link{epiworld_globalevent_tool} and \link{epiworld_globalevent}. +\item \code{globalevent_tool_logit} returns an object of class +\link{epiworld_globalevent_tool_logit} and \link{epiworld_globalevent}. } \itemize{ -\item The function \code{add_global_action} returns the model with the added +\item The function \code{add_globalevent} returns the model with the added action. } } @@ -79,21 +79,21 @@ simulation. They are useful for implementing interventions, such as vaccination, isolation, and social distancing by means of tools. } \details{ -The function \code{globalaction_tool_logit} allows to specify a logistic +The function \code{globalevent_tool_logit} allows to specify a logistic regression model for the probability of using a tool. The model is specified by the vector of coefficients \code{coefs} and the vector of variables \code{vars}. \code{vars} is an integer vector indicating the position of the variables in the model. -The function \code{globalaction_set_param} allows to set a parameter of +The function \code{globalevent_set_param} allows to set a parameter of the model. The parameter is specified by its name \code{param} and the value by \code{value}. -The function \code{globalaction_fun} allows to specify a function to be +The function \code{globalevent_fun} allows to specify a function to be executed at a given day. The function object must receive an object of class \link{epiworld_model} as only argument. -The function \code{add_global_action} adds a global action to a model. +The function \code{add_globalevent} adds a global action to a model. The model checks for actions to be executed at each time step. If the added action matches the current time step, the action is executed. When \code{day} is negative, the action is executed at each time step. When \code{day} is positive, @@ -121,8 +121,8 @@ epitool <- tool( # Adding a global action -vaccine_day_20 <- globalaction_tool(epitool, .2, day = 20) -add_global_action(model_sirconn, vaccine_day_20) +vaccine_day_20 <- globalevent_tool(epitool, .2, day = 20) +add_globalevent(model_sirconn, vaccine_day_20) # Running and printing run(model_sirconn, ndays = 40, seed = 1912) @@ -139,14 +139,14 @@ model_sirconn2 <- ModelSIRCONN( recovery_rate = 0.95 ) -closure_day_10 <- globalaction_set_params("Contact rate", 0, day = 10) -add_global_action(model_sirconn2, closure_day_10) +closure_day_10 <- globalevent_set_params("Contact rate", 0, day = 10) +add_globalevent(model_sirconn2, closure_day_10) # Running and printing run(model_sirconn2, ndays = 40, seed = 1912) model_sirconn2 plot_incidence(model_sirconn2) -# Example using `globalaction_fun` to record the state of the +# Example using `globalevent_fun` to record the state of the # agents at each time step. # We start by creating an SIR connected model diff --git a/src/actions.cpp b/src/actions.cpp index e8a76c10..3868f090 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -9,7 +9,7 @@ using namespace epiworld; using namespace cpp11; [[cpp11::register]] -SEXP globalaction_tool_logit_cpp( +SEXP globalevent_tool_logit_cpp( SEXP tool, std::vector< int > vars, std::vector< double > coefs, @@ -19,14 +19,14 @@ SEXP globalaction_tool_logit_cpp( std::vector< size_t > vars_size_t(vars.begin(), vars.end()); - GlobalFun action(epimodels::globalaction_tool_logit( + GlobalFun action(epimodels::globalevent_tool_logit( *cpp11::external_pointer>(tool), vars_size_t, coefs )); - cpp11::external_pointer> ptr( - new GlobalAction(action, name, day) + cpp11::external_pointer> ptr( + new GlobalEvent(action, name, day) ); return ptr; @@ -34,20 +34,20 @@ SEXP globalaction_tool_logit_cpp( } [[cpp11::register]] -SEXP globalaction_tool_cpp( +SEXP globalevent_tool_cpp( SEXP tool, double prob, std::string name, int day ) { - GlobalFun action(epimodels::globalaction_tool( + GlobalFun action(epimodels::globalevent_tool( *cpp11::external_pointer>(tool), prob )); - cpp11::external_pointer> ptr( - new GlobalAction(action, name, day) + cpp11::external_pointer> ptr( + new GlobalEvent(action, name, day) ); return ptr; @@ -55,20 +55,20 @@ SEXP globalaction_tool_cpp( } [[cpp11::register]] -SEXP globalaction_set_param_cpp( +SEXP globalevent_set_param_cpp( std::string param, double value, std::string name, int day ) { - GlobalFun action(epimodels::globalaction_set_param( + GlobalFun action(epimodels::globalevent_set_param( param, value )); - cpp11::external_pointer> ptr( - new GlobalAction(action, name, day) + cpp11::external_pointer> ptr( + new GlobalEvent(action, name, day) ); return ptr; @@ -80,7 +80,7 @@ SEXP print_global_action_cpp( SEXP action ) { - external_pointer> actionptr(action); + external_pointer> actionptr(action); actionptr->print(); @@ -90,36 +90,36 @@ SEXP print_global_action_cpp( [[cpp11::register]] -SEXP add_global_action_cpp( +SEXP add_globalevent_cpp( SEXP model, SEXP action ) { external_pointer> modelptr(model); - external_pointer> actionptr(action); + external_pointer> actionptr(action); - modelptr->add_global_action(*actionptr); + modelptr->add_globalevent(*actionptr); return model; } [[cpp11::register]] -SEXP rm_global_action_cpp( +SEXP rm_globalevent_cpp( SEXP model, std::string name ) { external_pointer> modelptr(model); - modelptr->rm_global_action(name); + modelptr->rm_globalevent(name); return model; } [[cpp11::register]] -SEXP globalaction_fun_cpp( +SEXP globalevent_fun_cpp( cpp11::function fun, std::string name, int day @@ -138,8 +138,8 @@ SEXP globalaction_fun_cpp( }; - return external_pointer>( - new GlobalAction(fun_call, name, day) + return external_pointer>( + new GlobalEvent(fun_call, name, day) ); diff --git a/src/cpp11.cpp b/src/cpp11.cpp index fdf878a5..6ed1ba5f 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -6,24 +6,24 @@ #include // actions.cpp -SEXP globalaction_tool_logit_cpp(SEXP tool, std::vector< int > vars, std::vector< double > coefs, std::string name, int day); -extern "C" SEXP _epiworldR_globalaction_tool_logit_cpp(SEXP tool, SEXP vars, SEXP coefs, SEXP name, SEXP day) { +SEXP globalevent_tool_logit_cpp(SEXP tool, std::vector< int > vars, std::vector< double > coefs, std::string name, int day); +extern "C" SEXP _epiworldR_globalevent_tool_logit_cpp(SEXP tool, SEXP vars, SEXP coefs, SEXP name, SEXP day) { BEGIN_CPP11 - return cpp11::as_sexp(globalaction_tool_logit_cpp(cpp11::as_cpp>(tool), cpp11::as_cpp>>(vars), cpp11::as_cpp>>(coefs), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); + return cpp11::as_sexp(globalevent_tool_logit_cpp(cpp11::as_cpp>(tool), cpp11::as_cpp>>(vars), cpp11::as_cpp>>(coefs), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); END_CPP11 } // actions.cpp -SEXP globalaction_tool_cpp(SEXP tool, double prob, std::string name, int day); -extern "C" SEXP _epiworldR_globalaction_tool_cpp(SEXP tool, SEXP prob, SEXP name, SEXP day) { +SEXP globalevent_tool_cpp(SEXP tool, double prob, std::string name, int day); +extern "C" SEXP _epiworldR_globalevent_tool_cpp(SEXP tool, SEXP prob, SEXP name, SEXP day) { BEGIN_CPP11 - return cpp11::as_sexp(globalaction_tool_cpp(cpp11::as_cpp>(tool), cpp11::as_cpp>(prob), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); + return cpp11::as_sexp(globalevent_tool_cpp(cpp11::as_cpp>(tool), cpp11::as_cpp>(prob), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); END_CPP11 } // actions.cpp -SEXP globalaction_set_param_cpp(std::string param, double value, std::string name, int day); -extern "C" SEXP _epiworldR_globalaction_set_param_cpp(SEXP param, SEXP value, SEXP name, SEXP day) { +SEXP globalevent_set_param_cpp(std::string param, double value, std::string name, int day); +extern "C" SEXP _epiworldR_globalevent_set_param_cpp(SEXP param, SEXP value, SEXP name, SEXP day) { BEGIN_CPP11 - return cpp11::as_sexp(globalaction_set_param_cpp(cpp11::as_cpp>(param), cpp11::as_cpp>(value), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); + return cpp11::as_sexp(globalevent_set_param_cpp(cpp11::as_cpp>(param), cpp11::as_cpp>(value), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); END_CPP11 } // actions.cpp @@ -34,24 +34,24 @@ extern "C" SEXP _epiworldR_print_global_action_cpp(SEXP action) { END_CPP11 } // actions.cpp -SEXP add_global_action_cpp(SEXP model, SEXP action); -extern "C" SEXP _epiworldR_add_global_action_cpp(SEXP model, SEXP action) { +SEXP add_globalevent_cpp(SEXP model, SEXP action); +extern "C" SEXP _epiworldR_add_globalevent_cpp(SEXP model, SEXP action) { BEGIN_CPP11 - return cpp11::as_sexp(add_global_action_cpp(cpp11::as_cpp>(model), cpp11::as_cpp>(action))); + return cpp11::as_sexp(add_globalevent_cpp(cpp11::as_cpp>(model), cpp11::as_cpp>(action))); END_CPP11 } // actions.cpp -SEXP rm_global_action_cpp(SEXP model, std::string name); -extern "C" SEXP _epiworldR_rm_global_action_cpp(SEXP model, SEXP name) { +SEXP rm_globalevent_cpp(SEXP model, std::string name); +extern "C" SEXP _epiworldR_rm_globalevent_cpp(SEXP model, SEXP name) { BEGIN_CPP11 - return cpp11::as_sexp(rm_global_action_cpp(cpp11::as_cpp>(model), cpp11::as_cpp>(name))); + return cpp11::as_sexp(rm_globalevent_cpp(cpp11::as_cpp>(model), cpp11::as_cpp>(name))); END_CPP11 } // actions.cpp -SEXP globalaction_fun_cpp(cpp11::function fun, std::string name, int day); -extern "C" SEXP _epiworldR_globalaction_fun_cpp(SEXP fun, SEXP name, SEXP day) { +SEXP globalevent_fun_cpp(cpp11::function fun, std::string name, int day); +extern "C" SEXP _epiworldR_globalevent_fun_cpp(SEXP fun, SEXP name, SEXP day) { BEGIN_CPP11 - return cpp11::as_sexp(globalaction_fun_cpp(cpp11::as_cpp>(fun), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); + return cpp11::as_sexp(globalevent_fun_cpp(cpp11::as_cpp>(fun), cpp11::as_cpp>(name), cpp11::as_cpp>(day))); END_CPP11 } // agents.cpp @@ -784,7 +784,7 @@ static const R_CallMethodDef CallEntries[] = { {"_epiworldR_ModelSISD_cpp", (DL_FUNC) &_epiworldR_ModelSISD_cpp, 5}, {"_epiworldR_ModelSIS_cpp", (DL_FUNC) &_epiworldR_ModelSIS_cpp, 4}, {"_epiworldR_ModelSURV_cpp", (DL_FUNC) &_epiworldR_ModelSURV_cpp, 13}, - {"_epiworldR_add_global_action_cpp", (DL_FUNC) &_epiworldR_add_global_action_cpp, 2}, + {"_epiworldR_add_globalevent_cpp", (DL_FUNC) &_epiworldR_add_globalevent_cpp, 2}, {"_epiworldR_add_tool_agent_cpp", (DL_FUNC) &_epiworldR_add_tool_agent_cpp, 5}, {"_epiworldR_add_tool_cpp", (DL_FUNC) &_epiworldR_add_tool_cpp, 3}, {"_epiworldR_add_tool_n_cpp", (DL_FUNC) &_epiworldR_add_tool_n_cpp, 3}, @@ -822,10 +822,10 @@ static const R_CallMethodDef CallEntries[] = { {"_epiworldR_get_transition_probability_cpp", (DL_FUNC) &_epiworldR_get_transition_probability_cpp, 1}, {"_epiworldR_get_transmissions_cpp", (DL_FUNC) &_epiworldR_get_transmissions_cpp, 1}, {"_epiworldR_get_virus_model_cpp", (DL_FUNC) &_epiworldR_get_virus_model_cpp, 2}, - {"_epiworldR_globalaction_fun_cpp", (DL_FUNC) &_epiworldR_globalaction_fun_cpp, 3}, - {"_epiworldR_globalaction_set_param_cpp", (DL_FUNC) &_epiworldR_globalaction_set_param_cpp, 4}, - {"_epiworldR_globalaction_tool_cpp", (DL_FUNC) &_epiworldR_globalaction_tool_cpp, 4}, - {"_epiworldR_globalaction_tool_logit_cpp", (DL_FUNC) &_epiworldR_globalaction_tool_logit_cpp, 5}, + {"_epiworldR_globalevent_fun_cpp", (DL_FUNC) &_epiworldR_globalevent_fun_cpp, 3}, + {"_epiworldR_globalevent_set_param_cpp", (DL_FUNC) &_epiworldR_globalevent_set_param_cpp, 4}, + {"_epiworldR_globalevent_tool_cpp", (DL_FUNC) &_epiworldR_globalevent_tool_cpp, 4}, + {"_epiworldR_globalevent_tool_logit_cpp", (DL_FUNC) &_epiworldR_globalevent_tool_logit_cpp, 5}, {"_epiworldR_has_tool_cpp", (DL_FUNC) &_epiworldR_has_tool_cpp, 2}, {"_epiworldR_has_virus_cpp", (DL_FUNC) &_epiworldR_has_virus_cpp, 2}, {"_epiworldR_initial_states_cpp", (DL_FUNC) &_epiworldR_initial_states_cpp, 2}, @@ -838,7 +838,7 @@ static const R_CallMethodDef CallEntries[] = { {"_epiworldR_print_virus_cpp", (DL_FUNC) &_epiworldR_print_virus_cpp, 1}, {"_epiworldR_queuing_off_cpp", (DL_FUNC) &_epiworldR_queuing_off_cpp, 1}, {"_epiworldR_queuing_on_cpp", (DL_FUNC) &_epiworldR_queuing_on_cpp, 1}, - {"_epiworldR_rm_global_action_cpp", (DL_FUNC) &_epiworldR_rm_global_action_cpp, 2}, + {"_epiworldR_rm_globalevent_cpp", (DL_FUNC) &_epiworldR_rm_globalevent_cpp, 2}, {"_epiworldR_rm_tool_cpp", (DL_FUNC) &_epiworldR_rm_tool_cpp, 2}, {"_epiworldR_rm_virus_cpp", (DL_FUNC) &_epiworldR_rm_virus_cpp, 2}, {"_epiworldR_run_cpp", (DL_FUNC) &_epiworldR_run_cpp, 3},