From 917d21d8df3133ee165ed9e42ade7a57ef180b8b Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Thu, 6 Jun 2024 16:28:03 -0600 Subject: [PATCH] Virus now hold info about dist --- epiworld.hpp | 246 +++++++++----------- examples/00-hello-world/main.cpp | 4 +- examples/03-simple-sir/main.cpp | 4 +- examples/04-advanced-usage/main.cpp | 4 +- examples/05-user-data/main.cpp | 4 +- examples/07-surveillance/07-surveillance.md | 4 +- include/epiworld/agent-bones.hpp | 1 + include/epiworld/agent-meat.hpp | 5 + include/epiworld/model-bones.hpp | 4 +- include/epiworld/model-meat-print.hpp | 12 +- include/epiworld/model-meat.hpp | 63 +---- include/epiworld/models/diffnet.hpp | 4 +- include/epiworld/models/init-functions.hpp | 24 +- include/epiworld/models/seir.hpp | 4 +- include/epiworld/models/seirconnected.hpp | 4 +- include/epiworld/models/seird.hpp | 4 +- include/epiworld/models/seirdconnected.hpp | 4 +- include/epiworld/models/seirmixing.hpp | 4 +- include/epiworld/models/sir.hpp | 4 +- include/epiworld/models/sirconnected.hpp | 4 +- include/epiworld/models/sird.hpp | 4 +- include/epiworld/models/sirdconnected.hpp | 4 +- include/epiworld/models/sirlogit.hpp | 4 +- include/epiworld/models/sirmixing.hpp | 4 +- include/epiworld/models/sis.hpp | 4 +- include/epiworld/models/sisd.hpp | 4 +- include/epiworld/models/surveillance.hpp | 4 +- include/epiworld/virus-bones.hpp | 4 +- include/epiworld/virus-meat.hpp | 62 +++-- readme.cpp | 4 +- tests/00-cloning-model.cpp | 4 +- tests/01-queue.cpp | 4 +- tests/01-sample.cpp | 4 +- tests/05-mixing.cpp | 3 +- tests/06-mixing.cpp | 3 +- 35 files changed, 238 insertions(+), 285 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index ad84698b8..83bf73ae9 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -6316,9 +6316,7 @@ class Model { * indicating number of individuals. */ ///@{ - void add_virus(Virus & v, epiworld_double preval); - void add_virus_n(Virus & v, epiworld_fast_uint preval); - void add_virus_fun(Virus & v, VirusToAgentFun fun); + void add_virus(Virus & v); void add_tool(Tool & t, epiworld_double preval); void add_tool_n(Tool & t, epiworld_fast_uint preval); void add_tool_fun(Tool & t, ToolToAgentFun fun); @@ -7497,7 +7495,7 @@ inline void Model::dist_virus() for (auto & v: viruses) { - v.distribute(this); + v->distribute(this); // Apply the events events_run(); @@ -7715,15 +7713,11 @@ inline void Model::seed(size_t s) { } template -inline void Model::add_virus(Virus & v, epiworld_double preval) +inline void Model::add_virus( + Virus & v + ) { - if (preval > 1.0) - throw std::range_error("Prevalence of virus cannot be above 1.0"); - - if (preval < 0.0) - throw std::range_error("Prevalence of virus cannot be negative"); - // Checking the state epiworld_fast_int init_, post_, rm_; v.get_state(&init_, &post_, &rm_); @@ -7745,57 +7739,6 @@ inline void Model::add_virus(Virus & v, epiworld_double preval) } -template -inline void Model::add_virus_n(Virus & v, epiworld_fast_uint preval) -{ - - // Checking the ids - epiworld_fast_int init_, post_, rm_; - v.get_state(&init_, &post_, &rm_); - - if (init_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -init- state." - ); - else if (post_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -post- state." - ); - - // Setting the id - db.record_virus(v); - - // Adding new virus - viruses.push_back(std::make_shared< Virus >(v)); - -} - -template -inline void Model::add_virus_fun(Virus & v, VirusToAgentFun fun) -{ - - // Checking the ids - epiworld_fast_int init_, post_, rm_; - v.get_state(&init_, &post_, &rm_); - - if (init_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -init- state." - ); - else if (post_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -post- state." - ); - - // Setting the id - db.record_virus(v); - // v.set_id(viruses.size()); - - // Adding new virus - viruses.push_back(std::make_shared< Virus >(v)); - -} - template inline void Model::add_tool(Tool & t, epiworld_double preval) { @@ -8995,13 +8938,13 @@ inline const Model & Model::print(bool lite) const if (i < n_viruses_model) { - if (virus.get_prevalence_as_proportion()) + if (virus->get_prevalence_as_proportion()) { printf_epiworld( " - %s (baseline prevalence: %.2f%%)\n", - virus.get_name().c_str(), - virus.get_prevalence() * 100.00 + virus->get_name().c_str(), + virus->get_prevalence() * 100.00 ); } @@ -9010,8 +8953,8 @@ inline const Model & Model::print(bool lite) const printf_epiworld( " - %s (baseline prevalence: %i seeds)\n", - virus.get_name().c_str(), - static_cast(virus.get_prevalence()) + virus->get_name().c_str(), + static_cast(virus->get_prevalence()) ); } @@ -9020,7 +8963,7 @@ inline const Model & Model::print(bool lite) const printf_epiworld( " - %s (originated in the model...)\n", - virus.get_name().c_str() + virus->get_name().c_str() ); } @@ -10308,10 +10251,10 @@ class Virus { */ ///@{ epiworld_double get_prevalence() const; - void set_prevalence(epiworld_double prevalence); + void set_prevalence(epiworld_double prevalence, bool as_proportion); bool get_prevalence_as_proportion() const; - void set_prevalence_as_proportion(bool prevalence_as_proportion); void distribute(Model * model); + void set_distribution(VirusToAgentFun fun); ///@} @@ -10425,9 +10368,9 @@ inline Virus::Virus( VirusToAgentFun dist_fun ) { set_name(name); - this->prevalence = prevalence; - this->prevalence_as_proportion = prevalence_as_proportion; - this->dist_fun = dist_fun; + + set_prevalence(prevalence, prevalence_as_proportion); + set_distribution(dist_fun); } template @@ -11045,15 +10988,23 @@ inline bool Virus::get_prevalence_as_proportion() const } template -inline void Virus::set_prevalence(epiworld_double preval) +inline void Virus::set_prevalence( + epiworld_double preval, + bool as_proportion + ) { - prevalence = preval; -} -template -inline void Virus::set_prevalence_as_proportion(bool preval_as_proportion) -{ - prevalence_as_proportion = preval_as_proportion; + if (as_proportion) { + + if ((preval < 0.0) || (preval > 1.0)) + throw std::range_error( + "The prevalence should be between 0 and 1. " + + std::string("Got ") + std::to_string(preval) + ); + } + + prevalence = preval; + prevalence_as_proportion = as_proportion; } template @@ -11067,27 +11018,47 @@ inline void Virus::distribute(Model * model) } else { + // Figuring out how what agents are available + std::vector< size_t > idx; + for (const auto & agent: model->get_agents()) + if (agent.get_virus() == nullptr) + idx.push_back(agent.get_id()); + // Picking how many - int nsampled; size_t n = model->size(); + int n_available = static_cast(idx.size()); + int n_to_sample; if (prevalence_as_proportion) { - nsampled = static_cast(std::floor(prevalence * n)); + n_to_sample = static_cast(std::floor(prevalence * n)); + + if (n_to_sample == static_cast(n)) + n_to_sample--; } else { - nsampled = static_cast(prevalence); + n_to_sample = static_cast(prevalence); } - if (nsampled > static_cast(n)) - throw std::range_error("There are only " + std::to_string(n) + - " individuals in the population. Cannot add the virus to " + std::to_string(nsampled)); + if (n_to_sample > n_available) + throw std::range_error( + "There are only " + std::to_string(n_available) + + " individuals with no virus in the population. " + + "Cannot add the virus to " + + std::to_string(n_to_sample) + ); auto & population = model->get_agents(); - while (nsampled > 0) + for (int i = 0; i < n_to_sample; ++i) { - int loc = static_cast(floor(model->runif() * (n_left--))); + int loc = static_cast( + floor(model->runif() * (n_available--)) + ); + + // Correcting for possible overflow + if ((loc > 0) && (loc >= n_available)) + loc = n_available - 1; Agent & agent = population[idx[loc]]; @@ -11100,8 +11071,7 @@ inline void Virus::distribute(Model * model) ); // Adjusting sample - nsampled--; - std::swap(idx[loc], idx[n_left]); + std::swap(idx[loc], idx[n_available]); } @@ -11109,6 +11079,12 @@ inline void Virus::distribute(Model * model) } +template +inline void Virus::set_distribution(VirusToAgentFun fun) +{ + dist_fun = fun; +} + #endif /*////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -13521,6 +13497,7 @@ class Agent { int get_id() const; ///< Id of the individual VirusPtr & get_virus(); + const VirusPtr & get_virus() const; ToolPtr & get_tool(int i); Tools get_tools(); @@ -14400,6 +14377,11 @@ inline VirusPtr & Agent::get_virus() { return virus; } +template +inline const VirusPtr & Agent::get_virus() const { + return virus; +} + template inline Tools Agent::get_tools() { @@ -15593,10 +15575,10 @@ inline std::function*)> create_init_function_sir( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -15667,10 +15649,10 @@ inline std::function*)> create_init_function_sird( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -15745,10 +15727,10 @@ inline std::function*)> create_init_function_seir( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -15827,10 +15809,10 @@ inline std::function*)> create_init_function_seird( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -16130,14 +16112,14 @@ inline ModelSIS::ModelSIS( model.add_param(recovery_rate, "Recovery rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSIS::INFECTED, ModelSIS::SUSCEPTIBLE, ModelSIS::SUSCEPTIBLE); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(0.0); - model.add_virus(virus, prevalence); + model.add_virus(virus); return; @@ -16249,13 +16231,13 @@ inline ModelSIR::ModelSIR( model.add_param(transmission_rate, "Transmission rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,2,2); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_infecting(&model("Transmission rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Recovered (SIR)"); @@ -16423,7 +16405,7 @@ inline ModelSEIR::ModelSEIR( model.add_param(recovery_rate, "Recovery rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSEIR::EXPOSED, ModelSEIR::REMOVED, ModelSEIR::REMOVED); virus.set_prob_infecting(&model("Transmission rate")); @@ -16431,7 +16413,7 @@ inline ModelSEIR::ModelSEIR( virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Exposed-Infected-Removed (SEIR)"); @@ -16801,7 +16783,7 @@ inline ModelSURV::ModelSURV( model.add_param(prob_noreinfect, "Prob. no reinfect"); // Virus ------------------------------------------------------------------ - epiworld::Virus covid("Covid19"); + epiworld::Virus covid("Covid19", prevalence, true); covid.set_state(LATENT, RECOVERED, REMOVED); covid.set_post_immunity(&model("Prob. no reinfect")); covid.set_prob_death(&model("Prob. death")); @@ -16827,7 +16809,7 @@ inline ModelSURV::ModelSURV( covid.set_prob_infecting_fun(ptransmitfun); - model.add_virus_n(covid, prevalence); + model.add_virus(covid); model.set_user_data({"nsampled", "ndetected", "ndetected_asympt", "nasymptomatic"}); model.add_globalevent(surveillance_program, "Surveilance program", -1); @@ -17210,12 +17192,12 @@ inline ModelSIRCONN::ModelSIRCONN( model.add_globalevent(update, "Update infected individuals"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1, 2, 2); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need @@ -17610,7 +17592,7 @@ inline ModelSEIRCONN::ModelSEIRCONN( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRCONN::EXPOSED, ModelSEIRCONN::RECOVERED, @@ -17621,7 +17603,7 @@ inline ModelSEIRCONN::ModelSEIRCONN( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need @@ -17775,13 +17757,13 @@ inline ModelSIRD::ModelSIRD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,2,3); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Recovered-Deceased (SIRD)"); @@ -17908,14 +17890,14 @@ inline ModelSISD::ModelSISD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,0,2); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(0.01); - model.add_virus(virus, prevalence); + model.add_virus(virus); return; @@ -18133,7 +18115,7 @@ inline ModelSEIRD::ModelSEIRD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSEIRD::EXPOSED, ModelSEIRD::REMOVED, ModelSEIRD::DECEASED); virus.set_prob_infecting(&model("Transmission rate")); @@ -18142,7 +18124,7 @@ inline ModelSEIRD::ModelSEIRD( virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Exposed-Infected-Removed-Deceased (SEIRD)"); @@ -18501,13 +18483,13 @@ inline ModelSIRDCONN::ModelSIRDCONN( // model.add_param(prob_reinfection, "Prob. Reinfection"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1, 2, 3); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need @@ -18909,7 +18891,7 @@ inline ModelSEIRDCONN::ModelSEIRDCONN( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRDCONN::EXPOSED, ModelSEIRDCONN::REMOVED, @@ -18920,7 +18902,7 @@ inline ModelSEIRDCONN::ModelSEIRDCONN( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need @@ -19296,7 +19278,7 @@ inline ModelSIRLogit::ModelSIRLogit( // model.add_param(prob_reinfection, "Prob. Reinfection"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSIRLogit::INFECTED, ModelSIRLogit::RECOVERED, @@ -19308,7 +19290,7 @@ inline ModelSIRLogit::ModelSIRLogit( // virus.set_prob - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Removed (SIR) (logit)"); @@ -19535,12 +19517,12 @@ inline ModelDiffNet::ModelDiffNet( model.add_param(prob_adopt, parname); // Preparing the virus ------------------------------------------- - epiworld::Virus innovation(innovation_name); + epiworld::Virus innovation(innovation_name, prevalence, true); innovation.set_state(1,1,1); innovation.set_prob_infecting(&model(parname)); - model.add_virus(innovation, prevalence); + model.add_virus(innovation); model.set_name( std::string("Diffusion of Innovations - ") + innovation_name); @@ -20049,7 +20031,7 @@ inline ModelSEIRMixing::ModelSEIRMixing( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRMixing::EXPOSED, ModelSEIRMixing::RECOVERED, @@ -20060,7 +20042,7 @@ inline ModelSEIRMixing::ModelSEIRMixing( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need @@ -20566,7 +20548,7 @@ inline ModelSIRMixing::ModelSIRMixing( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSIRMixing::INFECTED, ModelSIRMixing::RECOVERED, @@ -20576,7 +20558,7 @@ inline ModelSIRMixing::ModelSIRMixing( virus.set_prob_infecting(&model("Prob. Transmission")); virus.set_prob_recovery(&model("Prob. Recovery")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/examples/00-hello-world/main.cpp b/examples/00-hello-world/main.cpp index dc4d93fcc..fb6a2ea0c 100644 --- a/examples/00-hello-world/main.cpp +++ b/examples/00-hello-world/main.cpp @@ -17,11 +17,11 @@ int main() model.add_state("Removed"); // Adding the tool and virus - epiworld::Virus virus("covid 19"); + epiworld::Virus virus("covid 19", 50, false); virus.set_post_immunity(1.0); virus.set_state(1,2,3); virus.set_prob_death(.01); - model.add_virus_n(virus, 50); + model.add_virus(virus); epiworld::Tool tool("vaccine"); model.add_tool(tool, .5); diff --git a/examples/03-simple-sir/main.cpp b/examples/03-simple-sir/main.cpp index a19be1b21..aed018fa8 100644 --- a/examples/03-simple-sir/main.cpp +++ b/examples/03-simple-sir/main.cpp @@ -5,7 +5,7 @@ int main() { // Creating a virus - epiworld::Virus<> covid19("covid 19"); + epiworld::Virus<> covid19("covid 19", 0.05, true); covid19.set_prob_infecting(0.8); covid19.set_state(1,2,2); @@ -21,7 +21,7 @@ int main() model.add_state("Removed"); // Adding the tool and virus - model.add_virus(covid19, .05); + model.add_virus(covid19); model.add_tool(vax, .5); diff --git a/examples/04-advanced-usage/main.cpp b/examples/04-advanced-usage/main.cpp index 8f750236d..1339a7384 100644 --- a/examples/04-advanced-usage/main.cpp +++ b/examples/04-advanced-usage/main.cpp @@ -63,7 +63,7 @@ int main() { model.add_param(0.01, "virus death"); // Initializing disease --------------------------------------------------- - epiworld::Virus covid19("COVID19"); + epiworld::Virus covid19("COVID19", 0.01, true); covid19.set_sequence(base_seq); covid19.set_mutation(covid19_mut); covid19.set_post_recovery(post_covid); @@ -94,7 +94,7 @@ int main() { post_immunity.set_susceptibility_reduction(1.0); // Adding the virus and the tools to the model ---------------------------- - model.add_virus(covid19, 0.01); + model.add_virus(covid19); model.add_tool(immune, 1.0); model.add_tool(vaccine, 0.5); diff --git a/examples/05-user-data/main.cpp b/examples/05-user-data/main.cpp index 0302b3cd9..f2be2ac8e 100644 --- a/examples/05-user-data/main.cpp +++ b/examples/05-user-data/main.cpp @@ -21,7 +21,7 @@ int main() model.add_param(.3, "recovery"); // Setting up virus -------------------------------------------------------- - epiworld::Virus<> v("covid"); + epiworld::Virus<> v("covid", 5, false); v.set_state(1,2,2); EPI_NEW_POSTRECOVERYFUN_LAMBDA(immunity, int) @@ -51,7 +51,7 @@ int main() model.add_tool(is, 1.0); model.add_tool_n(postImm, 0u); - model.add_virus_n(v, 5); + model.add_virus(v); model.run(112, 30); model.print(); diff --git a/examples/07-surveillance/07-surveillance.md b/examples/07-surveillance/07-surveillance.md index 0f0fef1d4..722b0d613 100644 --- a/examples/07-surveillance/07-surveillance.md +++ b/examples/07-surveillance/07-surveillance.md @@ -57,7 +57,7 @@ int main() { // Creating a virus - epiworld::Virus<> covid19("covid 19"); + epiworld::Virus<> covid19("covid 19", .01, true); covid19.set_infectiousness(.8); // Creating a tool @@ -68,7 +68,7 @@ int main() epiworld::Model<> model; // Adding the tool and virus - model.add_virus(covid19, .01); + model.add_virus(covid19); model.add_tool(vax, .5); // Generating a random pop diff --git a/include/epiworld/agent-bones.hpp b/include/epiworld/agent-bones.hpp index cd703a32c..c3d2fe263 100644 --- a/include/epiworld/agent-bones.hpp +++ b/include/epiworld/agent-bones.hpp @@ -218,6 +218,7 @@ class Agent { int get_id() const; ///< Id of the individual VirusPtr & get_virus(); + const VirusPtr & get_virus() const; ToolPtr & get_tool(int i); Tools get_tools(); diff --git a/include/epiworld/agent-meat.hpp b/include/epiworld/agent-meat.hpp index 0fbc98a61..aadb8f835 100644 --- a/include/epiworld/agent-meat.hpp +++ b/include/epiworld/agent-meat.hpp @@ -455,6 +455,11 @@ inline VirusPtr & Agent::get_virus() { return virus; } +template +inline const VirusPtr & Agent::get_virus() const { + return virus; +} + template inline Tools Agent::get_tools() { diff --git a/include/epiworld/model-bones.hpp b/include/epiworld/model-bones.hpp index 1d68dee24..3c7f7ca21 100644 --- a/include/epiworld/model-bones.hpp +++ b/include/epiworld/model-bones.hpp @@ -335,9 +335,7 @@ class Model { * indicating number of individuals. */ ///@{ - void add_virus(Virus & v, epiworld_double preval); - void add_virus_n(Virus & v, epiworld_fast_uint preval); - void add_virus_fun(Virus & v, VirusToAgentFun fun); + void add_virus(Virus & v); void add_tool(Tool & t, epiworld_double preval); void add_tool_n(Tool & t, epiworld_fast_uint preval); void add_tool_fun(Tool & t, ToolToAgentFun fun); diff --git a/include/epiworld/model-meat-print.hpp b/include/epiworld/model-meat-print.hpp index 673f28500..0de4c86fe 100644 --- a/include/epiworld/model-meat-print.hpp +++ b/include/epiworld/model-meat-print.hpp @@ -157,13 +157,13 @@ inline const Model & Model::print(bool lite) const if (i < n_viruses_model) { - if (virus.get_prevalence_as_proportion()) + if (virus->get_prevalence_as_proportion()) { printf_epiworld( " - %s (baseline prevalence: %.2f%%)\n", - virus.get_name().c_str(), - virus.get_prevalence() * 100.00 + virus->get_name().c_str(), + virus->get_prevalence() * 100.00 ); } @@ -172,8 +172,8 @@ inline const Model & Model::print(bool lite) const printf_epiworld( " - %s (baseline prevalence: %i seeds)\n", - virus.get_name().c_str(), - static_cast(virus.get_prevalence()) + virus->get_name().c_str(), + static_cast(virus->get_prevalence()) ); } @@ -182,7 +182,7 @@ inline const Model & Model::print(bool lite) const printf_epiworld( " - %s (originated in the model...)\n", - virus.get_name().c_str() + virus->get_name().c_str() ); } diff --git a/include/epiworld/model-meat.hpp b/include/epiworld/model-meat.hpp index 6a888fc5e..c52b64b0f 100644 --- a/include/epiworld/model-meat.hpp +++ b/include/epiworld/model-meat.hpp @@ -754,7 +754,7 @@ inline void Model::dist_virus() for (auto & v: viruses) { - v.distribute(this); + v->distribute(this); // Apply the events events_run(); @@ -972,15 +972,11 @@ inline void Model::seed(size_t s) { } template -inline void Model::add_virus(Virus & v, epiworld_double preval) +inline void Model::add_virus( + Virus & v + ) { - if (preval > 1.0) - throw std::range_error("Prevalence of virus cannot be above 1.0"); - - if (preval < 0.0) - throw std::range_error("Prevalence of virus cannot be negative"); - // Checking the state epiworld_fast_int init_, post_, rm_; v.get_state(&init_, &post_, &rm_); @@ -1002,57 +998,6 @@ inline void Model::add_virus(Virus & v, epiworld_double preval) } -template -inline void Model::add_virus_n(Virus & v, epiworld_fast_uint preval) -{ - - // Checking the ids - epiworld_fast_int init_, post_, rm_; - v.get_state(&init_, &post_, &rm_); - - if (init_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -init- state." - ); - else if (post_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -post- state." - ); - - // Setting the id - db.record_virus(v); - - // Adding new virus - viruses.push_back(std::make_shared< Virus >(v)); - -} - -template -inline void Model::add_virus_fun(Virus & v, VirusToAgentFun fun) -{ - - // Checking the ids - epiworld_fast_int init_, post_, rm_; - v.get_state(&init_, &post_, &rm_); - - if (init_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -init- state." - ); - else if (post_ == -99) - throw std::logic_error( - "The virus \"" + v.get_name() + "\" has no -post- state." - ); - - // Setting the id - db.record_virus(v); - // v.set_id(viruses.size()); - - // Adding new virus - viruses.push_back(std::make_shared< Virus >(v)); - -} - template inline void Model::add_tool(Tool & t, epiworld_double preval) { diff --git a/include/epiworld/models/diffnet.hpp b/include/epiworld/models/diffnet.hpp index b7ab07243..1ca9e4f7f 100644 --- a/include/epiworld/models/diffnet.hpp +++ b/include/epiworld/models/diffnet.hpp @@ -164,12 +164,12 @@ inline ModelDiffNet::ModelDiffNet( model.add_param(prob_adopt, parname); // Preparing the virus ------------------------------------------- - epiworld::Virus innovation(innovation_name); + epiworld::Virus innovation(innovation_name, prevalence, true); innovation.set_state(1,1,1); innovation.set_prob_infecting(&model(parname)); - model.add_virus(innovation, prevalence); + model.add_virus(innovation); model.set_name( std::string("Diffusion of Innovations - ") + innovation_name); diff --git a/include/epiworld/models/init-functions.hpp b/include/epiworld/models/init-functions.hpp index 2b6ec41c8..136d45b01 100644 --- a/include/epiworld/models/init-functions.hpp +++ b/include/epiworld/models/init-functions.hpp @@ -32,10 +32,10 @@ inline std::function*)> create_init_function_sir( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -106,10 +106,10 @@ inline std::function*)> create_init_function_sird( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -184,10 +184,10 @@ inline std::function*)> create_init_function_seir( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context @@ -266,10 +266,10 @@ inline std::function*)> create_init_function_seird( double n = static_cast(model->size()); for (const auto & virus: model->get_viruses()) { - if (virus.get_prevalence_as_proportion()) - tot += virus.get_prevalence(); + if (virus->get_prevalence_as_proportion()) + tot += virus->get_prevalence(); else - tot += virus.get_prevalence() / n; + tot += virus->get_prevalence() / n; } // Putting the total into context diff --git a/include/epiworld/models/seir.hpp b/include/epiworld/models/seir.hpp index 301796ee9..4a0818fb4 100644 --- a/include/epiworld/models/seir.hpp +++ b/include/epiworld/models/seir.hpp @@ -104,7 +104,7 @@ inline ModelSEIR::ModelSEIR( model.add_param(recovery_rate, "Recovery rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSEIR::EXPOSED, ModelSEIR::REMOVED, ModelSEIR::REMOVED); virus.set_prob_infecting(&model("Transmission rate")); @@ -112,7 +112,7 @@ inline ModelSEIR::ModelSEIR( virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Exposed-Infected-Removed (SEIR)"); diff --git a/include/epiworld/models/seirconnected.hpp b/include/epiworld/models/seirconnected.hpp index 7295dbac2..5e73d675e 100644 --- a/include/epiworld/models/seirconnected.hpp +++ b/include/epiworld/models/seirconnected.hpp @@ -322,7 +322,7 @@ inline ModelSEIRCONN::ModelSEIRCONN( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRCONN::EXPOSED, ModelSEIRCONN::RECOVERED, @@ -333,7 +333,7 @@ inline ModelSEIRCONN::ModelSEIRCONN( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/seird.hpp b/include/epiworld/models/seird.hpp index fe6089347..f1b407f77 100644 --- a/include/epiworld/models/seird.hpp +++ b/include/epiworld/models/seird.hpp @@ -168,7 +168,7 @@ inline ModelSEIRD::ModelSEIRD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSEIRD::EXPOSED, ModelSEIRD::REMOVED, ModelSEIRD::DECEASED); virus.set_prob_infecting(&model("Transmission rate")); @@ -177,7 +177,7 @@ inline ModelSEIRD::ModelSEIRD( virus.set_prob_recovery(&model("Recovery rate")); // Adding the tool and the virus - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Exposed-Infected-Removed-Deceased (SEIRD)"); diff --git a/include/epiworld/models/seirdconnected.hpp b/include/epiworld/models/seirdconnected.hpp index e34f023f6..8b6184fe8 100644 --- a/include/epiworld/models/seirdconnected.hpp +++ b/include/epiworld/models/seirdconnected.hpp @@ -341,7 +341,7 @@ inline ModelSEIRDCONN::ModelSEIRDCONN( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRDCONN::EXPOSED, ModelSEIRDCONN::REMOVED, @@ -352,7 +352,7 @@ inline ModelSEIRDCONN::ModelSEIRDCONN( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/seirmixing.hpp b/include/epiworld/models/seirmixing.hpp index 50304a0ec..7d6e33cbe 100644 --- a/include/epiworld/models/seirmixing.hpp +++ b/include/epiworld/models/seirmixing.hpp @@ -450,7 +450,7 @@ inline ModelSEIRMixing::ModelSEIRMixing( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSEIRMixing::EXPOSED, ModelSEIRMixing::RECOVERED, @@ -461,7 +461,7 @@ inline ModelSEIRMixing::ModelSEIRMixing( virus.set_prob_recovery(&model("Prob. Recovery")); virus.set_incubation(&model("Avg. Incubation days")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/sir.hpp b/include/epiworld/models/sir.hpp index ae9ca2e30..dbe647cc2 100644 --- a/include/epiworld/models/sir.hpp +++ b/include/epiworld/models/sir.hpp @@ -64,13 +64,13 @@ inline ModelSIR::ModelSIR( model.add_param(transmission_rate, "Transmission rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,2,2); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_infecting(&model("Transmission rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Recovered (SIR)"); diff --git a/include/epiworld/models/sirconnected.hpp b/include/epiworld/models/sirconnected.hpp index 705a309ff..b85c3df63 100644 --- a/include/epiworld/models/sirconnected.hpp +++ b/include/epiworld/models/sirconnected.hpp @@ -305,12 +305,12 @@ inline ModelSIRCONN::ModelSIRCONN( model.add_globalevent(update, "Update infected individuals"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1, 2, 2); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/sird.hpp b/include/epiworld/models/sird.hpp index f9f518469..01cbf061f 100644 --- a/include/epiworld/models/sird.hpp +++ b/include/epiworld/models/sird.hpp @@ -78,13 +78,13 @@ inline ModelSIRD::ModelSIRD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,2,3); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Recovered-Deceased (SIRD)"); diff --git a/include/epiworld/models/sirdconnected.hpp b/include/epiworld/models/sirdconnected.hpp index 68f2db0e2..1fffa5a23 100644 --- a/include/epiworld/models/sirdconnected.hpp +++ b/include/epiworld/models/sirdconnected.hpp @@ -290,13 +290,13 @@ inline ModelSIRDCONN::ModelSIRDCONN( // model.add_param(prob_reinfection, "Prob. Reinfection"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1, 2, 3); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(&model("Death rate")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/sirlogit.hpp b/include/epiworld/models/sirlogit.hpp index 9af13166f..49ab553f8 100644 --- a/include/epiworld/models/sirlogit.hpp +++ b/include/epiworld/models/sirlogit.hpp @@ -299,7 +299,7 @@ inline ModelSIRLogit::ModelSIRLogit( // model.add_param(prob_reinfection, "Prob. Reinfection"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSIRLogit::INFECTED, ModelSIRLogit::RECOVERED, @@ -311,7 +311,7 @@ inline ModelSIRLogit::ModelSIRLogit( // virus.set_prob - model.add_virus(virus, prevalence); + model.add_virus(virus); model.set_name("Susceptible-Infected-Removed (SIR) (logit)"); diff --git a/include/epiworld/models/sirmixing.hpp b/include/epiworld/models/sirmixing.hpp index d87a7eaef..8a4f2f03a 100644 --- a/include/epiworld/models/sirmixing.hpp +++ b/include/epiworld/models/sirmixing.hpp @@ -426,7 +426,7 @@ inline ModelSIRMixing::ModelSIRMixing( // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state( ModelSIRMixing::INFECTED, ModelSIRMixing::RECOVERED, @@ -436,7 +436,7 @@ inline ModelSIRMixing::ModelSIRMixing( virus.set_prob_infecting(&model("Prob. Transmission")); virus.set_prob_recovery(&model("Prob. Recovery")); - model.add_virus(virus, prevalence); + model.add_virus(virus); model.queuing_off(); // No queuing need diff --git a/include/epiworld/models/sis.hpp b/include/epiworld/models/sis.hpp index 3736b9e89..431c20a4a 100644 --- a/include/epiworld/models/sis.hpp +++ b/include/epiworld/models/sis.hpp @@ -58,14 +58,14 @@ inline ModelSIS::ModelSIS( model.add_param(recovery_rate, "Recovery rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(ModelSIS::INFECTED, ModelSIS::SUSCEPTIBLE, ModelSIS::SUSCEPTIBLE); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(0.0); - model.add_virus(virus, prevalence); + model.add_virus(virus); return; diff --git a/include/epiworld/models/sisd.hpp b/include/epiworld/models/sisd.hpp index 1d3a424b2..1a17f81ec 100644 --- a/include/epiworld/models/sisd.hpp +++ b/include/epiworld/models/sisd.hpp @@ -61,14 +61,14 @@ inline ModelSISD::ModelSISD( model.add_param(death_rate, "Death rate"); // Preparing the virus ------------------------------------------- - epiworld::Virus virus(vname); + epiworld::Virus virus(vname, prevalence, true); virus.set_state(1,0,2); virus.set_prob_infecting(&model("Transmission rate")); virus.set_prob_recovery(&model("Recovery rate")); virus.set_prob_death(0.01); - model.add_virus(virus, prevalence); + model.add_virus(virus); return; diff --git a/include/epiworld/models/surveillance.hpp b/include/epiworld/models/surveillance.hpp index 5afd6abb8..c51eccce4 100644 --- a/include/epiworld/models/surveillance.hpp +++ b/include/epiworld/models/surveillance.hpp @@ -304,7 +304,7 @@ inline ModelSURV::ModelSURV( model.add_param(prob_noreinfect, "Prob. no reinfect"); // Virus ------------------------------------------------------------------ - epiworld::Virus covid("Covid19"); + epiworld::Virus covid("Covid19", prevalence, true); covid.set_state(LATENT, RECOVERED, REMOVED); covid.set_post_immunity(&model("Prob. no reinfect")); covid.set_prob_death(&model("Prob. death")); @@ -330,7 +330,7 @@ inline ModelSURV::ModelSURV( covid.set_prob_infecting_fun(ptransmitfun); - model.add_virus_n(covid, prevalence); + model.add_virus(covid); model.set_user_data({"nsampled", "ndetected", "ndetected_asympt", "nasymptomatic"}); model.add_globalevent(surveillance_program, "Surveilance program", -1); diff --git a/include/epiworld/virus-bones.hpp b/include/epiworld/virus-bones.hpp index b432559f6..8820f939b 100644 --- a/include/epiworld/virus-bones.hpp +++ b/include/epiworld/virus-bones.hpp @@ -171,10 +171,10 @@ class Virus { */ ///@{ epiworld_double get_prevalence() const; - void set_prevalence(epiworld_double prevalence); + void set_prevalence(epiworld_double prevalence, bool as_proportion); bool get_prevalence_as_proportion() const; - void set_prevalence_as_proportion(bool prevalence_as_proportion); void distribute(Model * model); + void set_distribution(VirusToAgentFun fun); ///@} diff --git a/include/epiworld/virus-meat.hpp b/include/epiworld/virus-meat.hpp index 897dd29ca..8c571d58f 100644 --- a/include/epiworld/virus-meat.hpp +++ b/include/epiworld/virus-meat.hpp @@ -87,9 +87,9 @@ inline Virus::Virus( VirusToAgentFun dist_fun ) { set_name(name); - this->prevalence = prevalence; - this->prevalence_as_proportion = prevalence_as_proportion; - this->dist_fun = dist_fun; + + set_prevalence(prevalence, prevalence_as_proportion); + set_distribution(dist_fun); } template @@ -707,15 +707,23 @@ inline bool Virus::get_prevalence_as_proportion() const } template -inline void Virus::set_prevalence(epiworld_double preval) +inline void Virus::set_prevalence( + epiworld_double preval, + bool as_proportion + ) { - prevalence = preval; -} -template -inline void Virus::set_prevalence_as_proportion(bool preval_as_proportion) -{ - prevalence_as_proportion = preval_as_proportion; + if (as_proportion) { + + if ((preval < 0.0) || (preval > 1.0)) + throw std::range_error( + "The prevalence should be between 0 and 1. " + + std::string("Got ") + std::to_string(preval) + ); + } + + prevalence = preval; + prevalence_as_proportion = as_proportion; } template @@ -737,32 +745,39 @@ inline void Virus::distribute(Model * model) // Picking how many size_t n = model->size(); - size_t n_available = idx.size(); + int n_available = static_cast(idx.size()); + int n_to_sample; if (prevalence_as_proportion) { - nsampled = static_cast(std::floor(prevalence * n)); + n_to_sample = static_cast(std::floor(prevalence * n)); - if (nsampled == n) - nsampled--; + if (n_to_sample == static_cast(n)) + n_to_sample--; } else { - nsampled = static_cast(prevalence); + n_to_sample = static_cast(prevalence); } - if (nsampled > static_cast(n_available)) + if (n_to_sample > n_available) throw std::range_error( "There are only " + std::to_string(n_available) + " individuals with no virus in the population. " + "Cannot add the virus to " + - std::to_string(nsampled) + std::to_string(n_to_sample) ); auto & population = model->get_agents(); - while (nsampled > 0) + for (int i = 0; i < n_to_sample; ++i) { - int loc = static_cast(floor(model->runif() * (n_left--))); + int loc = static_cast( + floor(model->runif() * (n_available--)) + ); + + // Correcting for possible overflow + if ((loc > 0) && (loc >= n_available)) + loc = n_available - 1; Agent & agent = population[idx[loc]]; @@ -775,8 +790,7 @@ inline void Virus::distribute(Model * model) ); // Adjusting sample - nsampled--; - std::swap(idx[loc], idx[n_left]); + std::swap(idx[loc], idx[n_available]); } @@ -784,4 +798,10 @@ inline void Virus::distribute(Model * model) } +template +inline void Virus::set_distribution(VirusToAgentFun fun) +{ + dist_fun = fun; +} + #endif diff --git a/readme.cpp b/readme.cpp index 4f05c9392..7e93deef0 100644 --- a/readme.cpp +++ b/readme.cpp @@ -20,14 +20,14 @@ int main() // - Infected individuals become "Infected" (status 1) // - Recovered individuals become "Recovered" (status 2) // 100 individuals will have the virus from the beginning. - Virus<> virus("covid 19"); + Virus<> virus("covid 19", 1000, false); virus.set_prob_infecting(.90); virus.set_prob_recovery(.30); virus.set_state(1, 2); - model.add_virus_n(virus, 1000); + model.add_virus(virus); // Generating a random pop from a smallworld network model.agents_smallworld(100000, 4L, false, .01); diff --git a/tests/00-cloning-model.cpp b/tests/00-cloning-model.cpp index fd466a112..ccdad29f1 100644 --- a/tests/00-cloning-model.cpp +++ b/tests/00-cloning-model.cpp @@ -9,14 +9,14 @@ EPIWORLD_TEST_CASE("Cloning", "[clone]") { m.add_state("Susceptible", default_update_susceptible); m.add_state("Recovered"); - epiworld::Virus v; + epiworld::Virus v("covid 19", 0.5, true); epiworld::Tool t; v.set_state(0, 1); m.seed(1333); m.agents_smallworld(1000); - m.add_virus(v, .5); + m.add_virus(v); m.add_tool(t, .5); // Cloning diff --git a/tests/01-queue.cpp b/tests/01-queue.cpp index fa54f13d8..d8adc9610 100644 --- a/tests/01-queue.cpp +++ b/tests/01-queue.cpp @@ -8,9 +8,9 @@ int main() Model<> model; model.agents_smallworld(100, 2); - Virus<> v("covid"); + Virus<> v("covid", 10, false); - model.add_virus_n(v, 10); + model.add_virus(v); Queue<> q; q.initialize(&model, nullptr); diff --git a/tests/01-sample.cpp b/tests/01-sample.cpp index ed41da2eb..4e9c379f2 100644 --- a/tests/01-sample.cpp +++ b/tests/01-sample.cpp @@ -17,11 +17,11 @@ int main() model.add_status("Removed"); // Adding the tool and virus - Virus virus("covid 19"); + Virus virus("covid 19", 50, false); virus.set_post_immunity(1.0); virus.set_status(1,2,3); virus.set_prob_death(.01); - model.add_virus_n(virus, 50); + model.add_virus(virus); epiworld::Tool tool("vaccine"); model.add_tool(tool, .5); diff --git a/tests/05-mixing.cpp b/tests/05-mixing.cpp index f4bd439d6..a04eb1b8e 100644 --- a/tests/05-mixing.cpp +++ b/tests/05-mixing.cpp @@ -28,8 +28,9 @@ EPIWORLD_TEST_CASE("SEIRMixing", "[SEIR-mixing]") { // Copy the original virus Virus<> v1 = model.get_virus(0); model.rm_virus(0); + v1.set_distribution(dist_virus<>(0)); - model.add_virus_fun(v1, dist_virus<>(0)); + model.add_virus(v1); // Creating three groups Entity<> e1("Entity 1", 0.0, false, dist_factory<>(0, 3000)); diff --git a/tests/06-mixing.cpp b/tests/06-mixing.cpp index a32fa602f..c21e06d0d 100644 --- a/tests/06-mixing.cpp +++ b/tests/06-mixing.cpp @@ -29,8 +29,9 @@ EPIWORLD_TEST_CASE("SIRMixing", "[SIR-mixing]") { // Copy the original virus Virus<> v1 = model.get_virus(0); model.rm_virus(0); + v1.set_distribution(dist_virus<>(0)); - model.add_virus_fun(v1, dist_virus<>(0)); + model.add_virus(v1); // Creating three groups Entity<> e1("Entity 1", 0, false, dist_factory<>(0, 3000));