From 7a144034637a822567d71dfe5a35d9a2132dac50 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Dec 2023 14:48:42 -0700 Subject: [PATCH 1/5] First step renaming actions to events --- epiworld.hpp | 194 +++++++++--------- include/epiworld/agent-actions-meat.hpp | 14 +- include/epiworld/agent-bones.hpp | 30 +-- include/epiworld/agent-meat.hpp | 2 +- include/epiworld/config.hpp | 12 +- include/epiworld/database-bones.hpp | 20 +- include/epiworld/entity-bones.hpp | 8 +- include/epiworld/epiworld.hpp | 4 +- ...ctions-bones.hpp => globalevent-bones.hpp} | 20 +- ...lactions-meat.hpp => globalevent-meat.hpp} | 22 +- include/epiworld/model-bones.hpp | 16 +- include/epiworld/model-meat.hpp | 14 +- .../{globalactions.hpp => globalevents.hpp} | 16 +- include/epiworld/models/models.hpp | 2 +- include/epiworld/tool-bones.hpp | 4 +- include/epiworld/virus-bones.hpp | 4 +- 16 files changed, 191 insertions(+), 191 deletions(-) rename include/epiworld/{globalactions-bones.hpp => globalevent-bones.hpp} (66%) rename include/epiworld/{globalactions-meat.hpp => globalevent-meat.hpp} (60%) rename include/epiworld/models/{globalactions.hpp => globalevents.hpp} (86%) diff --git a/epiworld.hpp b/epiworld.hpp index a6630bf28..a99407ecf 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -117,10 +117,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 @@ -141,12 +141,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; @@ -158,7 +158,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. * @@ -173,7 +173,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_, @@ -2647,19 +2647,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 @@ -2669,11 +2669,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; @@ -5786,26 +5786,26 @@ inline bool Queue::operator==(const Queue & other) const /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - Start of -include/epiworld/globalactions-bones.hpp- + Start of -include/epiworld/globalevent-bones.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ -#ifndef EPIWORLD_GLOBALACTIONS_BONES_HPP -#define EPIWORLD_GLOBALACTIONS_BONES_HPP +#ifndef EPIWORLD_GLOBALEVENT_BONES_HPP +#define EPIWORLD_GLOBALEVENT_BONES_HPP // template // using GlobalFun = std::function*)>; /** - * @brief Template for a Global Action + * @brief Template for a Global Event * @details Global actions are functions that Model executes * at the end of a day. * */ template -class GlobalAction +class GlobalEvent { private: GlobalFun fun = nullptr; @@ -5813,18 +5813,18 @@ class GlobalAction int day = -99; public: - GlobalAction() {}; + GlobalEvent() {}; /** - * @brief Construct a new Global Action object + * @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. */ - GlobalAction(GlobalFun fun, std::string name, int day = -99); + GlobalEvent(GlobalFun fun, std::string name, int day = -99); - ~GlobalAction() {}; + ~GlobalEvent() {}; void operator()(Model * m, int day); @@ -5837,8 +5837,8 @@ class GlobalAction void print() const; // Comparison operators - bool operator==(const GlobalAction & other) const; - bool operator!=(const GlobalAction & other) const; + bool operator==(const GlobalEvent & other) const; + bool operator!=(const GlobalEvent & other) const; }; @@ -5848,7 +5848,7 @@ class GlobalAction /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - End of -include/epiworld/globalactions-bones.hpp- + End of -include/epiworld/globalevent-bones.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ @@ -5857,17 +5857,17 @@ class GlobalAction /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - Start of -include/epiworld/globalactions-meat.hpp- + Start of -include/epiworld/globalevent-meat.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ -#ifndef EPIWORLD_GLOBALACTIONS_MEAT_HPP -#define EPIWORLD_GLOBALACTIONS_MEAT_HPP +#ifndef EPIWORLD_GLOBALEVENT_MEAT_HPP +#define EPIWORLD_GLOBALEVENT_MEAT_HPP template -inline GlobalAction::GlobalAction( +inline GlobalEvent::GlobalEvent( GlobalFun fun, std::string name, int day @@ -5879,7 +5879,7 @@ inline GlobalAction::GlobalAction( } template -inline void GlobalAction::operator()(Model * m, int day) +inline void GlobalEvent::operator()(Model * m, int day) { if (this->fun == nullptr) @@ -5894,31 +5894,31 @@ inline void GlobalAction::operator()(Model * m, int day) } template -inline void GlobalAction::set_name(std::string name) +inline void GlobalEvent::set_name(std::string name) { this->name = name; } template -inline std::string GlobalAction::get_name() const +inline std::string GlobalEvent::get_name() const { return this->name; } template -inline void GlobalAction::set_day(int day) +inline void GlobalEvent::set_day(int day) { this->day = day; } template -inline int GlobalAction::get_day() const +inline int GlobalEvent::get_day() const { return this->day; } template -inline void GlobalAction::print() const +inline void GlobalEvent::print() const { printf_epiworld( "Global action: %s\n" @@ -5929,13 +5929,13 @@ inline void GlobalAction::print() const } template -inline bool GlobalAction::operator==(const GlobalAction & other) const +inline bool GlobalEvent::operator==(const GlobalEvent & other) const { return (this->name == other.name) && (this->day == other.day); } template -inline bool GlobalAction::operator!=(const GlobalAction & other) const +inline bool GlobalEvent::operator!=(const GlobalEvent & other) const { return !(*this == other); } @@ -5944,7 +5944,7 @@ inline bool GlobalAction::operator!=(const GlobalAction & other) con /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - End of -include/epiworld/globalactions-meat.hpp- + End of -include/epiworld/globalevent-meat.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ @@ -5990,10 +5990,10 @@ template class Queue; template -struct Action; +struct Event; template -class GlobalAction; +class GlobalEvent; template inline epiworld_double susceptibility_reduction_mixer_default( @@ -6157,7 +6157,7 @@ class Model { void chrono_start(); void chrono_end(); - std::vector> global_actions; + std::vector> global_actions; Queue queue; bool use_queuing = true; @@ -6166,11 +6166,11 @@ class Model { * @brief Variables used to keep track of the actions * to be made regarding viruses. */ - std::vector< Action > actions = {}; + std::vector< Event > actions = {}; 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 @@ -6606,11 +6606,11 @@ class Model { ); void add_global_action( - GlobalAction action + 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_global_action(std::string name); ///< Retrieve a global action by name + GlobalEvent & get_global_action(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 @@ -6883,7 +6883,7 @@ inline void Model::actions_add( { actions.emplace_back( - Action( + Event( agent_, virus_, tool_, entity_, new_state_, queue_, call_, idx_agent_, idx_object_ )); @@ -6892,7 +6892,7 @@ inline void Model::actions_add( else { - Action & A = actions.at(nactions - 1u); + Event & A = actions.at(nactions - 1u); A.agent = agent_; A.virus = virus_; @@ -6918,7 +6918,7 @@ inline void Model::actions_run() while (nactions_tmp < nactions) { - Action & a = actions[nactions_tmp++]; + Event & a = actions[nactions_tmp++]; Agent * p = a.agent; #ifdef EPI_DEBUG @@ -9486,7 +9486,7 @@ inline void Model::add_global_action( { global_actions.push_back( - GlobalAction( + GlobalEvent( fun, name, date @@ -9497,14 +9497,14 @@ inline void Model::add_global_action( template inline void Model::add_global_action( - GlobalAction action + GlobalEvent action ) { global_actions.push_back(action); } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_global_action( std::string name ) { @@ -9518,7 +9518,7 @@ GlobalAction & Model::get_global_action( } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_global_action( size_t index ) { @@ -10160,8 +10160,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; @@ -11274,8 +11274,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; @@ -11911,18 +11911,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; @@ -13059,7 +13059,7 @@ template class Queue; template -struct Action; +struct Event; template class Entity; @@ -13068,25 +13068,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); @@ -13105,13 +13105,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; @@ -13376,7 +13376,7 @@ class Agent { #define EPIWORLD_AGENT_ACTIONS_MEAT_HPP template -inline void default_add_virus(Action & a, Model * m) +inline void default_add_virus(Event & a, Model * m) { Agent * p = a.agent; @@ -13422,7 +13422,7 @@ inline void default_add_virus(Action & a, Model * m) } template -inline void default_add_tool(Action & a, Model * m) +inline void default_add_tool(Event & a, Model * m) { Agent * p = a.agent; @@ -13459,7 +13459,7 @@ inline void default_add_tool(Action & a, Model * m) } template -inline void default_rm_virus(Action & a, Model * model) +inline void default_rm_virus(Event & a, Model * model) { Agent * p = a.agent; @@ -13494,7 +13494,7 @@ inline void default_rm_virus(Action & a, Model * model) } template -inline void default_rm_tool(Action & a, Model * m) +inline void default_rm_tool(Event & a, Model * m) { Agent * p = a.agent; @@ -13532,7 +13532,7 @@ inline void default_rm_tool(Action & a, Model * m) } template -inline void default_change_state(Action & a, Model * m) +inline void default_change_state(Event & a, Model * m) { Agent * p = a.agent; @@ -13553,7 +13553,7 @@ inline void default_change_state(Action & a, Model * m) } template -inline void default_add_entity(Action & a, Model *) +inline void default_add_entity(Event & a, Model *) { Agent * p = a.agent; @@ -13613,7 +13613,7 @@ inline void default_add_entity(Action & a, Model *) } template -inline void default_rm_entity(Action & a, Model * m) +inline void default_rm_entity(Event & a, Model * m) { Agent * p = a.agent; @@ -13905,7 +13905,7 @@ inline void Agent::add_entity( // model entity { - Action a( + Event a( this, nullptr, nullptr, &entity, state_new, queue, default_add_entity, -1, -1 ); @@ -15421,19 +15421,19 @@ inline std::function*)> create_init_function_seird( /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - Start of -include/epiworld//models/globalactions.hpp- + Start of -include/epiworld//models/globalevents.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ -#ifndef EPIWORLD_GLOBALACTIONS_HPP -#define EPIWORLD_GLOBALACTIONS_HPP +#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 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. @@ -15441,7 +15441,7 @@ inline std::function*)> create_init_function_seird( * @return std::function*)> */ template -inline std::function*)> globalaction_tool( +inline std::function*)> globalevent_tool( Tool & tool, double p ) { @@ -15480,7 +15480,7 @@ inline std::function*)> globalaction_tool( // Same function as above, but p is now a function of a vector of coefficients // and a vector of variables. /** - * @brief Global action that distributes a tool to agents with probability + * @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) @@ -15490,7 +15490,7 @@ inline std::function*)> globalaction_tool( * @return std::function*)> */ template -inline std::function*)> globalaction_tool_logit( +inline std::function*)> globalevent_tool_logit( Tool & tool, std::vector< size_t > vars, std::vector< double > coefs @@ -15540,7 +15540,7 @@ inline std::function*)> globalaction_tool_logit( // A global action that updates a parameter in the model. /** - * @brief 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. @@ -15548,7 +15548,7 @@ inline std::function*)> globalaction_tool_logit( * @return std::function*)> */ template -inline std::function*)> globalaction_set_param( +inline std::function*)> globalevent_set_param( std::string param, double value ) { @@ -15571,7 +15571,7 @@ inline std::function*)> globalaction_set_param( /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - End of -include/epiworld//models/globalactions.hpp- + End of -include/epiworld//models/globalevents.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ diff --git a/include/epiworld/agent-actions-meat.hpp b/include/epiworld/agent-actions-meat.hpp index ef078cbbd..ddb11e5b0 100644 --- a/include/epiworld/agent-actions-meat.hpp +++ b/include/epiworld/agent-actions-meat.hpp @@ -2,7 +2,7 @@ #define EPIWORLD_AGENT_ACTIONS_MEAT_HPP template -inline void default_add_virus(Action & a, Model * m) +inline void default_add_virus(Event & a, Model * m) { Agent * p = a.agent; @@ -48,7 +48,7 @@ inline void default_add_virus(Action & a, Model * m) } template -inline void default_add_tool(Action & a, Model * m) +inline void default_add_tool(Event & a, Model * m) { Agent * p = a.agent; @@ -85,7 +85,7 @@ inline void default_add_tool(Action & a, Model * m) } template -inline void default_rm_virus(Action & a, Model * model) +inline void default_rm_virus(Event & a, Model * model) { Agent * p = a.agent; @@ -120,7 +120,7 @@ inline void default_rm_virus(Action & a, Model * model) } template -inline void default_rm_tool(Action & a, Model * m) +inline void default_rm_tool(Event & a, Model * m) { Agent * p = a.agent; @@ -158,7 +158,7 @@ inline void default_rm_tool(Action & a, Model * m) } template -inline void default_change_state(Action & a, Model * m) +inline void default_change_state(Event & a, Model * m) { Agent * p = a.agent; @@ -179,7 +179,7 @@ inline void default_change_state(Action & a, Model * m) } template -inline void default_add_entity(Action & a, Model *) +inline void default_add_entity(Event & a, Model *) { Agent * p = a.agent; @@ -239,7 +239,7 @@ inline void default_add_entity(Action & a, Model *) } template -inline void default_rm_entity(Action & a, Model * m) +inline void default_rm_entity(Event & a, Model * m) { Agent * p = a.agent; diff --git a/include/epiworld/agent-bones.hpp b/include/epiworld/agent-bones.hpp index 06bc77ce7..1e83c069f 100644 --- a/include/epiworld/agent-bones.hpp +++ b/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/include/epiworld/agent-meat.hpp b/include/epiworld/agent-meat.hpp index 6bed922b8..6ab8cc21a 100644 --- a/include/epiworld/agent-meat.hpp +++ b/include/epiworld/agent-meat.hpp @@ -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 ); diff --git a/include/epiworld/config.hpp b/include/epiworld/config.hpp index 633dd0fd8..852243d93 100644 --- a/include/epiworld/config.hpp +++ b/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/include/epiworld/database-bones.hpp b/include/epiworld/database-bones.hpp index a57f37a1d..3d64ea002 100644 --- a/include/epiworld/database-bones.hpp +++ b/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/include/epiworld/entity-bones.hpp b/include/epiworld/entity-bones.hpp index b5666a42e..6e2ac160d 100644 --- a/include/epiworld/entity-bones.hpp +++ b/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/include/epiworld/epiworld.hpp b/include/epiworld/epiworld.hpp index 583878ffa..d1693bdee 100644 --- a/include/epiworld/epiworld.hpp +++ b/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/include/epiworld/globalactions-bones.hpp b/include/epiworld/globalevent-bones.hpp similarity index 66% rename from include/epiworld/globalactions-bones.hpp rename to include/epiworld/globalevent-bones.hpp index 22cb254c6..41367972a 100644 --- a/include/epiworld/globalactions-bones.hpp +++ b/include/epiworld/globalevent-bones.hpp @@ -1,17 +1,17 @@ -#ifndef EPIWORLD_GLOBALACTIONS_BONES_HPP -#define EPIWORLD_GLOBALACTIONS_BONES_HPP +#ifndef EPIWORLD_GLOBALEVENT_BONES_HPP +#define EPIWORLD_GLOBALEVENT_BONES_HPP // template // using GlobalFun = std::function*)>; /** - * @brief Template for a Global Action + * @brief Template for a Global Event * @details Global actions are functions that Model executes * at the end of a day. * */ template -class GlobalAction +class GlobalEvent { private: GlobalFun fun = nullptr; @@ -19,18 +19,18 @@ class GlobalAction int day = -99; public: - GlobalAction() {}; + GlobalEvent() {}; /** - * @brief Construct a new Global Action object + * @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. */ - GlobalAction(GlobalFun fun, std::string name, int day = -99); + GlobalEvent(GlobalFun fun, std::string name, int day = -99); - ~GlobalAction() {}; + ~GlobalEvent() {}; void operator()(Model * m, int day); @@ -43,8 +43,8 @@ class GlobalAction void print() const; // Comparison operators - bool operator==(const GlobalAction & other) const; - bool operator!=(const GlobalAction & other) const; + bool operator==(const GlobalEvent & other) const; + bool operator!=(const GlobalEvent & other) const; }; diff --git a/include/epiworld/globalactions-meat.hpp b/include/epiworld/globalevent-meat.hpp similarity index 60% rename from include/epiworld/globalactions-meat.hpp rename to include/epiworld/globalevent-meat.hpp index 815d0576c..1f6fdaa27 100644 --- a/include/epiworld/globalactions-meat.hpp +++ b/include/epiworld/globalevent-meat.hpp @@ -1,8 +1,8 @@ -#ifndef EPIWORLD_GLOBALACTIONS_MEAT_HPP -#define EPIWORLD_GLOBALACTIONS_MEAT_HPP +#ifndef EPIWORLD_GLOBALEVENT_MEAT_HPP +#define EPIWORLD_GLOBALEVENT_MEAT_HPP template -inline GlobalAction::GlobalAction( +inline GlobalEvent::GlobalEvent( GlobalFun fun, std::string name, int day @@ -14,7 +14,7 @@ inline GlobalAction::GlobalAction( } template -inline void GlobalAction::operator()(Model * m, int day) +inline void GlobalEvent::operator()(Model * m, int day) { if (this->fun == nullptr) @@ -29,31 +29,31 @@ inline void GlobalAction::operator()(Model * m, int day) } template -inline void GlobalAction::set_name(std::string name) +inline void GlobalEvent::set_name(std::string name) { this->name = name; } template -inline std::string GlobalAction::get_name() const +inline std::string GlobalEvent::get_name() const { return this->name; } template -inline void GlobalAction::set_day(int day) +inline void GlobalEvent::set_day(int day) { this->day = day; } template -inline int GlobalAction::get_day() const +inline int GlobalEvent::get_day() const { return this->day; } template -inline void GlobalAction::print() const +inline void GlobalEvent::print() const { printf_epiworld( "Global action: %s\n" @@ -64,13 +64,13 @@ inline void GlobalAction::print() const } template -inline bool GlobalAction::operator==(const GlobalAction & other) const +inline bool GlobalEvent::operator==(const GlobalEvent & other) const { return (this->name == other.name) && (this->day == other.day); } template -inline bool GlobalAction::operator!=(const GlobalAction & other) const +inline bool GlobalEvent::operator!=(const GlobalEvent & other) const { return !(*this == other); } diff --git a/include/epiworld/model-bones.hpp b/include/epiworld/model-bones.hpp index 01efeea3d..9420b3077 100644 --- a/include/epiworld/model-bones.hpp +++ b/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,7 +195,7 @@ class Model { void chrono_start(); void chrono_end(); - std::vector> global_actions; + std::vector> global_actions; Queue queue; bool use_queuing = true; @@ -204,11 +204,11 @@ class Model { * @brief Variables used to keep track of the actions * to be made regarding viruses. */ - std::vector< Action > actions = {}; + std::vector< Event > actions = {}; 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 @@ -644,11 +644,11 @@ class Model { ); void add_global_action( - GlobalAction action + 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_global_action(std::string name); ///< Retrieve a global action by name + GlobalEvent & get_global_action(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 diff --git a/include/epiworld/model-meat.hpp b/include/epiworld/model-meat.hpp index ce7e59b8b..69c8ee070 100644 --- a/include/epiworld/model-meat.hpp +++ b/include/epiworld/model-meat.hpp @@ -173,7 +173,7 @@ inline void Model::actions_add( { actions.emplace_back( - Action( + 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 = actions.at(nactions - 1u); A.agent = agent_; A.virus = virus_; @@ -208,7 +208,7 @@ inline void Model::actions_run() while (nactions_tmp < nactions) { - Action & a = actions[nactions_tmp++]; + Event & a = actions[nactions_tmp++]; Agent * p = a.agent; #ifdef EPI_DEBUG @@ -2420,7 +2420,7 @@ inline void Model::add_global_action( { global_actions.push_back( - GlobalAction( + GlobalEvent( fun, name, date @@ -2431,14 +2431,14 @@ inline void Model::add_global_action( template inline void Model::add_global_action( - GlobalAction action + GlobalEvent action ) { global_actions.push_back(action); } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_global_action( std::string name ) { @@ -2452,7 +2452,7 @@ GlobalAction & Model::get_global_action( } template -GlobalAction & Model::get_global_action( +GlobalEvent & Model::get_global_action( size_t index ) { diff --git a/include/epiworld/models/globalactions.hpp b/include/epiworld/models/globalevents.hpp similarity index 86% rename from include/epiworld/models/globalactions.hpp rename to include/epiworld/models/globalevents.hpp index 432928d49..10097bcd0 100644 --- a/include/epiworld/models/globalactions.hpp +++ b/include/epiworld/models/globalevents.hpp @@ -1,10 +1,10 @@ -#ifndef EPIWORLD_GLOBALACTIONS_HPP -#define EPIWORLD_GLOBALACTIONS_HPP +#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 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. @@ -12,7 +12,7 @@ * @return std::function*)> */ template -inline std::function*)> globalaction_tool( +inline std::function*)> globalevent_tool( Tool & tool, double p ) { @@ -51,7 +51,7 @@ inline std::function*)> globalaction_tool( // Same function as above, but p is now a function of a vector of coefficients // and a vector of variables. /** - * @brief Global action that distributes a tool to agents with probability + * @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) @@ -61,7 +61,7 @@ inline std::function*)> globalaction_tool( * @return std::function*)> */ template -inline std::function*)> globalaction_tool_logit( +inline std::function*)> globalevent_tool_logit( Tool & tool, std::vector< size_t > vars, std::vector< double > coefs @@ -111,7 +111,7 @@ inline std::function*)> globalaction_tool_logit( // A global action that updates a parameter in the model. /** - * @brief 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. @@ -119,7 +119,7 @@ inline std::function*)> globalaction_tool_logit( * @return std::function*)> */ template -inline std::function*)> globalaction_set_param( +inline std::function*)> globalevent_set_param( std::string param, double value ) { diff --git a/include/epiworld/models/models.hpp b/include/epiworld/models/models.hpp index 6c01abe48..72cfc8607 100644 --- a/include/epiworld/models/models.hpp +++ b/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/include/epiworld/tool-bones.hpp b/include/epiworld/tool-bones.hpp index 9cd56b272..8e877eab8 100644 --- a/include/epiworld/tool-bones.hpp +++ b/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/include/epiworld/virus-bones.hpp b/include/epiworld/virus-bones.hpp index 8397e4539..81a88368a 100644 --- a/include/epiworld/virus-bones.hpp +++ b/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; From 32a8b241f633394dfd8288e4dbc298fc614ea9af Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Dec 2023 14:49:48 -0700 Subject: [PATCH 2/5] No more global actions, but events --- epiworld.hpp | 8 ++++---- include/epiworld/model-bones.hpp | 4 ++-- include/epiworld/model-meat.hpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index a99407ecf..ab9b5cbc3 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -6609,8 +6609,8 @@ class Model { GlobalEvent action ); - GlobalEvent & get_global_action(std::string name); ///< Retrieve a global action by name - GlobalEvent & 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 @@ -9504,7 +9504,7 @@ inline void Model::add_global_action( } template -GlobalEvent & Model::get_global_action( +GlobalEvent & Model::get_globalevent( std::string name ) { @@ -9518,7 +9518,7 @@ GlobalEvent & Model::get_global_action( } template -GlobalEvent & Model::get_global_action( +GlobalEvent & Model::get_globalevent( size_t index ) { diff --git a/include/epiworld/model-bones.hpp b/include/epiworld/model-bones.hpp index 9420b3077..844a4c9c9 100644 --- a/include/epiworld/model-bones.hpp +++ b/include/epiworld/model-bones.hpp @@ -647,8 +647,8 @@ class Model { GlobalEvent action ); - GlobalEvent & get_global_action(std::string name); ///< Retrieve a global action by name - GlobalEvent & 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 diff --git a/include/epiworld/model-meat.hpp b/include/epiworld/model-meat.hpp index 69c8ee070..deb03b51f 100644 --- a/include/epiworld/model-meat.hpp +++ b/include/epiworld/model-meat.hpp @@ -2438,7 +2438,7 @@ inline void Model::add_global_action( } template -GlobalEvent & Model::get_global_action( +GlobalEvent & Model::get_globalevent( std::string name ) { @@ -2452,7 +2452,7 @@ GlobalEvent & Model::get_global_action( } template -GlobalEvent & Model::get_global_action( +GlobalEvent & Model::get_globalevent( size_t index ) { From 629f8a59f495edf01f95df30748715f2e9ef878f Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Dec 2023 15:02:24 -0700 Subject: [PATCH 3/5] More updates on action->event --- README.md | 2 +- epiworld.hpp | 158 +++++++++--------- examples/00-hello-world/README.md | 2 +- examples/01-sir/README.md | 2 +- examples/02b-sir_multiple_runs/README.md | 2 +- examples/04-advanced-usage/README.md | 4 +- examples/06-sir-omp/README.md | 8 +- examples/06b-sir-omp/README.md | 2 +- examples/07-surveillance/07-surveillance.md | 2 +- examples/07-surveillance/README.md | 4 +- examples/10-likelihood-free-mcmc/README.md | 2 +- ...actions-meat.hpp => agent-events-meat.hpp} | 4 +- include/epiworld/agent-meat.hpp | 22 +-- include/epiworld/entity-meat.hpp | 2 +- include/epiworld/globalevent-bones.hpp | 2 +- include/epiworld/globalevent-meat.hpp | 2 +- include/epiworld/model-bones.hpp | 20 +-- include/epiworld/model-meat-print.hpp | 8 +- include/epiworld/model-meat.hpp | 74 ++++---- include/epiworld/models/init-functions.hpp | 20 +-- .../epiworld/models/seirconnected_logit.hpp | 2 +- include/epiworld/models/surveillance.hpp | 2 +- 22 files changed, 173 insertions(+), 173 deletions(-) rename include/epiworld/{agent-actions-meat.hpp => agent-events-meat.hpp} (99%) diff --git a/README.md b/README.md index b12b6e249..c303f83ee 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ on the same day. A single step of `epiworld` features the following procedures: 1. **Status update**: Agents are updated according to the status they are at. -2. (optional) **Execute global actions**: A call of user-defined functions affecting +2. (optional) **Execute Global events**: A call of user-defined functions affecting the system. These can make any type of change in the system. 3. (optional) **Apply rewiring algorithm**: When specified, the network is rewired diff --git a/epiworld.hpp b/epiworld.hpp index ab9b5cbc3..a4acde6e8 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -5800,7 +5800,7 @@ inline bool Queue::operator==(const Queue & other) const /** * @brief Template for a Global Event - * @details Global actions are functions that Model executes + * @details Global events are functions that Model executes * at the end of a day. * */ @@ -5885,7 +5885,7 @@ inline void GlobalEvent::operator()(Model * m, int day) if (this->fun == nullptr) return; - // Actions apply if day is negative or if day is equal to the day of the action + // 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); @@ -6157,16 +6157,16 @@ 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< Event > actions = {}; + std::vector< Event > events = {}; epiworld_fast_uint nactions = 0u; /** @@ -6182,7 +6182,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_, @@ -6599,23 +6599,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( + void add_globalevent( GlobalEvent action ); 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(); @@ -6684,7 +6684,7 @@ class Model { * * @param model_ Model over which it will be executed. */ - void actions_run(); + void events_run(); }; @@ -6860,7 +6860,7 @@ inline std::function*)> make_save_run( template -inline void Model::actions_add( +inline void Model::events_add( Agent * agent_, VirusPtr virus_, ToolPtr tool_, @@ -6879,10 +6879,10 @@ 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( + events.emplace_back( Event( agent_, virus_, tool_, entity_, new_state_, queue_, call_, idx_agent_, idx_object_ @@ -6892,7 +6892,7 @@ inline void Model::actions_add( else { - Event & A = actions.at(nactions - 1u); + Event & A = events.at(nactions - 1u); A.agent = agent_; A.virus = virus_; @@ -6911,14 +6911,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) { - Event & a = actions[nactions_tmp++]; + Event & a = events[nevents_tmp++]; Agent * p = a.agent; #ifdef EPI_DEBUG @@ -7113,7 +7113,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()), @@ -7198,7 +7198,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()), @@ -7273,7 +7273,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; @@ -7508,8 +7508,8 @@ inline void Model::dist_virus() } - // Apply the actions - actions_run(); + // Apply the events + events_run(); } } @@ -7568,8 +7568,8 @@ inline void Model::dist_tools() } - // Apply the actions - actions_run(); + // Apply the events + events_run(); } @@ -7625,8 +7625,8 @@ inline void Model::dist_tools() // } -// // Apply the actions -// actions_run(); +// // Apply the events +// events_run(); // } @@ -8256,8 +8256,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. @@ -8499,7 +8499,7 @@ inline void Model::update_state() { } - actions_run(); + events_run(); } @@ -8941,9 +8941,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) { @@ -8953,7 +8953,7 @@ inline const Model & Model::print(bool lite) const } } - if (global_actions.size() == 0u) + if (globalevents.size() == 0u) { printf_epiworld(" (none)\n"); } @@ -9478,14 +9478,14 @@ 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( + globalevents.push_back( GlobalEvent( fun, name, @@ -9496,11 +9496,11 @@ inline void Model::add_global_action( } template -inline void Model::add_global_action( +inline void Model::add_globalevent( GlobalEvent action ) { - global_actions.push_back(action); + globalevents.push_back(action); } template @@ -9509,7 +9509,7 @@ GlobalEvent & Model::get_globalevent( ) { - for (auto & a : global_actions) + for (auto & a : globalevents) if (a.name == name) return a; @@ -9523,25 +9523,25 @@ GlobalEvent & Model::get_globalevent( ) { - 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; } } @@ -9552,26 +9552,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(); } } @@ -9854,7 +9854,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, @@ -12028,7 +12028,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); } @@ -13366,14 +13366,14 @@ class Agent { /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - Start of -include/epiworld//agent-actions-meat.hpp- + Start of -include/epiworld//agent-events-meat.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ -#ifndef EPIWORLD_AGENT_ACTIONS_MEAT_HPP -#define EPIWORLD_AGENT_ACTIONS_MEAT_HPP +#ifndef EPIWORLD_AGENT_EVENTS_MEAT_HPP +#define EPIWORLD_AGENT_EVENTS_MEAT_HPP template inline void default_add_virus(Event & a, Model * m) @@ -13671,7 +13671,7 @@ inline void default_rm_entity(Event & a, Model * m) /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// - End of -include/epiworld//agent-actions-meat.hpp- + End of -include/epiworld//agent-events-meat.hpp- //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////*/ @@ -13827,7 +13827,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 ); @@ -13863,7 +13863,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 ); @@ -13896,7 +13896,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 ); @@ -13934,7 +13934,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 ); @@ -13952,7 +13952,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 ); @@ -13974,7 +13974,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 ); @@ -14003,7 +14003,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 ); @@ -14035,7 +14035,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 ); @@ -14052,7 +14052,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 ); @@ -14255,7 +14255,7 @@ inline void Agent::change_state( ) { - model->actions_add( + model->events_add( this, nullptr, nullptr, nullptr, new_state, queue, default_change_state, -1, -1 ); @@ -15127,8 +15127,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; @@ -15215,8 +15215,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; @@ -15295,8 +15295,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; @@ -15380,8 +15380,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( @@ -15395,8 +15395,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; @@ -16346,7 +16346,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/examples/00-hello-world/README.md b/examples/00-hello-world/README.md index 28aeeb110..a40bfa730 100644 --- a/examples/00-hello-world/README.md +++ b/examples/00-hello-world/README.md @@ -21,7 +21,7 @@ Last run elapsed t : 16.00ms Last run speed : 59.75 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/examples/01-sir/README.md b/examples/01-sir/README.md index 40e3367a5..2c9201048 100644 --- a/examples/01-sir/README.md +++ b/examples/01-sir/README.md @@ -19,7 +19,7 @@ Last run elapsed t : 70.00ms Last run speed : 35.62 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/examples/02b-sir_multiple_runs/README.md b/examples/02b-sir_multiple_runs/README.md index 926cdf45f..1f4bccf20 100644 --- a/examples/02b-sir_multiple_runs/README.md +++ b/examples/02b-sir_multiple_runs/README.md @@ -24,7 +24,7 @@ Last run speed : 104.73 million agents x day / second Average run speed : 103.36 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/examples/04-advanced-usage/README.md b/examples/04-advanced-usage/README.md index 8c0b98460..c0171ea7e 100644 --- a/examples/04-advanced-usage/README.md +++ b/examples/04-advanced-usage/README.md @@ -17,7 +17,7 @@ Number of viruses : 1 Last run elapsed t : - Rewiring : on (0.10) -Global actions: +Global events: (none) Virus(es): @@ -54,7 +54,7 @@ Last run elapsed t : 35.00ms Last run speed : 1.68 million agents x day / second Rewiring : on (0.10) -Global actions: +Global events: (none) Virus(es): diff --git a/examples/06-sir-omp/README.md b/examples/06-sir-omp/README.md index c5ad1f761..adb6f52f2 100644 --- a/examples/06-sir-omp/README.md +++ b/examples/06-sir-omp/README.md @@ -18,7 +18,7 @@ Last run elapsed t : 706.00ms Last run speed : 35.37 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): @@ -55,7 +55,7 @@ Last run elapsed t : 651.00ms Last run speed : 38.34 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): @@ -92,7 +92,7 @@ Last run elapsed t : 710.00ms Last run speed : 35.19 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): @@ -129,7 +129,7 @@ Last run elapsed t : 651.00ms Last run speed : 38.38 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/examples/06b-sir-omp/README.md b/examples/06b-sir-omp/README.md index 2faebb16e..d57094a16 100644 --- a/examples/06b-sir-omp/README.md +++ b/examples/06b-sir-omp/README.md @@ -24,7 +24,7 @@ Last run speed : 99.18 million agents x day / second Average run speed : 189.38 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/examples/07-surveillance/07-surveillance.md b/examples/07-surveillance/07-surveillance.md index d7745c0c2..0f0fef1d4 100644 --- a/examples/07-surveillance/07-surveillance.md +++ b/examples/07-surveillance/07-surveillance.md @@ -39,7 +39,7 @@ Run - Update state for susceptible/infected/removed(?) - Mutate virus(es) (each individual) - - Run global actions (e.g., surveillance) + - Run Global events (e.g., surveillance) - Run rewiring algorithm Along update: diff --git a/examples/07-surveillance/README.md b/examples/07-surveillance/README.md index c2b02c4f2..4460563a5 100644 --- a/examples/07-surveillance/README.md +++ b/examples/07-surveillance/README.md @@ -17,7 +17,7 @@ Number of viruses : 1 Last run elapsed t : - Rewiring : off -Global actions: +Global events: - Surveilance program (runs daily) Virus(es): @@ -52,7 +52,7 @@ Last run elapsed t : 3.00ms Last run speed : 252.72 million agents x day / second Rewiring : off -Global actions: +Global events: - Surveilance program (runs daily) Virus(es): diff --git a/examples/10-likelihood-free-mcmc/README.md b/examples/10-likelihood-free-mcmc/README.md index eafa9ff08..3e4a0385a 100644 --- a/examples/10-likelihood-free-mcmc/README.md +++ b/examples/10-likelihood-free-mcmc/README.md @@ -17,7 +17,7 @@ Last run elapsed t : 685.00µs Last run speed : 72.99 million agents x day / second Rewiring : off -Global actions: +Global events: (none) Virus(es): diff --git a/include/epiworld/agent-actions-meat.hpp b/include/epiworld/agent-events-meat.hpp similarity index 99% rename from include/epiworld/agent-actions-meat.hpp rename to include/epiworld/agent-events-meat.hpp index ddb11e5b0..8da043fb9 100644 --- a/include/epiworld/agent-actions-meat.hpp +++ b/include/epiworld/agent-events-meat.hpp @@ -1,5 +1,5 @@ -#ifndef EPIWORLD_AGENT_ACTIONS_MEAT_HPP -#define EPIWORLD_AGENT_ACTIONS_MEAT_HPP +#ifndef EPIWORLD_AGENT_EVENTS_MEAT_HPP +#define EPIWORLD_AGENT_EVENTS_MEAT_HPP template inline void default_add_virus(Event & a, Model * m) diff --git a/include/epiworld/agent-meat.hpp b/include/epiworld/agent-meat.hpp index 6ab8cc21a..03295f75a 100644 --- a/include/epiworld/agent-meat.hpp +++ b/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 ); @@ -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 ); diff --git a/include/epiworld/entity-meat.hpp b/include/epiworld/entity-meat.hpp index 6912ec527..4c5a30d42 100644 --- a/include/epiworld/entity-meat.hpp +++ b/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/include/epiworld/globalevent-bones.hpp b/include/epiworld/globalevent-bones.hpp index 41367972a..22d3069c9 100644 --- a/include/epiworld/globalevent-bones.hpp +++ b/include/epiworld/globalevent-bones.hpp @@ -6,7 +6,7 @@ /** * @brief Template for a Global Event - * @details Global actions are functions that Model executes + * @details Global events are functions that Model executes * at the end of a day. * */ diff --git a/include/epiworld/globalevent-meat.hpp b/include/epiworld/globalevent-meat.hpp index 1f6fdaa27..62993bab9 100644 --- a/include/epiworld/globalevent-meat.hpp +++ b/include/epiworld/globalevent-meat.hpp @@ -20,7 +20,7 @@ inline void GlobalEvent::operator()(Model * m, int day) if (this->fun == nullptr) return; - // Actions apply if day is negative or if day is equal to the day of the action + // 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); diff --git a/include/epiworld/model-bones.hpp b/include/epiworld/model-bones.hpp index 844a4c9c9..3b51e2a83 100644 --- a/include/epiworld/model-bones.hpp +++ b/include/epiworld/model-bones.hpp @@ -195,16 +195,16 @@ 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< Event > actions = {}; + std::vector< Event > events = {}; epiworld_fast_uint nactions = 0u; /** @@ -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( + void add_globalevent( GlobalEvent action ); 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/include/epiworld/model-meat-print.hpp b/include/epiworld/model-meat-print.hpp index 41dc154f6..7e431bbb5 100644 --- a/include/epiworld/model-meat-print.hpp +++ b/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"); } diff --git a/include/epiworld/model-meat.hpp b/include/epiworld/model-meat.hpp index deb03b51f..03075212c 100644 --- a/include/epiworld/model-meat.hpp +++ b/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,10 +169,10 @@ 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( + 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 { - Event & 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) { - Event & 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,14 +2412,14 @@ 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( + globalevents.push_back( GlobalEvent( fun, name, @@ -2430,11 +2430,11 @@ inline void Model::add_global_action( } template -inline void Model::add_global_action( +inline void Model::add_globalevent( GlobalEvent action ) { - global_actions.push_back(action); + globalevents.push_back(action); } template @@ -2443,7 +2443,7 @@ GlobalEvent & Model::get_globalevent( ) { - for (auto & a : global_actions) + for (auto & a : globalevents) if (a.name == name) return a; @@ -2457,25 +2457,25 @@ GlobalEvent & Model::get_globalevent( ) { - 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/include/epiworld/models/init-functions.hpp b/include/epiworld/models/init-functions.hpp index 660d5db84..f63366df2 100644 --- a/include/epiworld/models/init-functions.hpp +++ b/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/include/epiworld/models/seirconnected_logit.hpp b/include/epiworld/models/seirconnected_logit.hpp index 397aa95bb..ba871ac35 100644 --- a/include/epiworld/models/seirconnected_logit.hpp +++ b/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/include/epiworld/models/surveillance.hpp b/include/epiworld/models/surveillance.hpp index 81fd83b97..5afd6abb8 100644 --- a/include/epiworld/models/surveillance.hpp +++ b/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"); From 045840bbc7e35ed7d4cd1bf2c507cb5cf29be341 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Dec 2023 16:03:46 -0700 Subject: [PATCH 4/5] Virus io --- epiworld.hpp | 4 ++-- include/epiworld/database-meat.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index a4acde6e8..e4cd145b5 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -3784,9 +3784,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/include/epiworld/database-meat.hpp b/include/epiworld/database-meat.hpp index 926c52275..eabcf954f 100644 --- a/include/epiworld/database-meat.hpp +++ b/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) From f11e49efd1ff35e444cb0adcd2456f7874079500 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 7 Dec 2023 16:08:06 -0700 Subject: [PATCH 5/5] Virus io --- epiworld.hpp | 2 +- include/epiworld/database-meat.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index e4cd145b5..07e67c9be 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -3786,7 +3786,7 @@ inline void DataBase::write_data( #ifdef EPI_DEBUG "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/include/epiworld/database-meat.hpp b/include/epiworld/database-meat.hpp index eabcf954f..95e641bba 100644 --- a/include/epiworld/database-meat.hpp +++ b/include/epiworld/database-meat.hpp @@ -823,7 +823,7 @@ inline void DataBase::write_data( #ifdef EPI_DEBUG "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)