Skip to content

Commit

Permalink
Virus now hold info about dist
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 6, 2024
1 parent 5cc1bcd commit 917d21d
Show file tree
Hide file tree
Showing 35 changed files with 238 additions and 285 deletions.
246 changes: 114 additions & 132 deletions epiworld.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/00-hello-world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ int main()
model.add_state("Removed");

// Adding the tool and virus
epiworld::Virus<int> virus("covid 19");
epiworld::Virus<int> 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<int> tool("vaccine");
model.add_tool(tool, .5);
Expand Down
4 changes: 2 additions & 2 deletions examples/03-simple-sir/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions examples/04-advanced-usage/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main() {
model.add_param(0.01, "virus death");

// Initializing disease ---------------------------------------------------
epiworld::Virus<DAT> covid19("COVID19");
epiworld::Virus<DAT> covid19("COVID19", 0.01, true);
covid19.set_sequence(base_seq);
covid19.set_mutation(covid19_mut);
covid19.set_post_recovery(post_covid);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/05-user-data/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions examples/07-surveillance/07-surveillance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/epiworld/agent-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class Agent {
int get_id() const; ///< Id of the individual

VirusPtr<TSeq> & get_virus();
const VirusPtr<TSeq> & get_virus() const;

ToolPtr<TSeq> & get_tool(int i);
Tools<TSeq> get_tools();
Expand Down
5 changes: 5 additions & 0 deletions include/epiworld/agent-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ inline VirusPtr<TSeq> & Agent<TSeq>::get_virus() {
return virus;
}

template<typename TSeq>
inline const VirusPtr<TSeq> & Agent<TSeq>::get_virus() const {
return virus;
}


template<typename TSeq>
inline Tools<TSeq> Agent<TSeq>::get_tools() {
Expand Down
4 changes: 1 addition & 3 deletions include/epiworld/model-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ class Model {
* indicating number of individuals.
*/
///@{
void add_virus(Virus<TSeq> & v, epiworld_double preval);
void add_virus_n(Virus<TSeq> & v, epiworld_fast_uint preval);
void add_virus_fun(Virus<TSeq> & v, VirusToAgentFun<TSeq> fun);
void add_virus(Virus<TSeq> & v);
void add_tool(Tool<TSeq> & t, epiworld_double preval);
void add_tool_n(Tool<TSeq> & t, epiworld_fast_uint preval);
void add_tool_fun(Tool<TSeq> & t, ToolToAgentFun<TSeq> fun);
Expand Down
12 changes: 6 additions & 6 deletions include/epiworld/model-meat-print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ inline const Model<TSeq> & Model<TSeq>::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
);

}
Expand All @@ -172,8 +172,8 @@ inline const Model<TSeq> & Model<TSeq>::print(bool lite) const

printf_epiworld(
" - %s (baseline prevalence: %i seeds)\n",
virus.get_name().c_str(),
static_cast<int>(virus.get_prevalence())
virus->get_name().c_str(),
static_cast<int>(virus->get_prevalence())
);

}
Expand All @@ -182,7 +182,7 @@ inline const Model<TSeq> & Model<TSeq>::print(bool lite) const

printf_epiworld(
" - %s (originated in the model...)\n",
virus.get_name().c_str()
virus->get_name().c_str()
);

}
Expand Down
63 changes: 4 additions & 59 deletions include/epiworld/model-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ inline void Model<TSeq>::dist_virus()
for (auto & v: viruses)
{

v.distribute(this);
v->distribute(this);

// Apply the events
events_run();
Expand Down Expand Up @@ -972,15 +972,11 @@ inline void Model<TSeq>::seed(size_t s) {
}

template<typename TSeq>
inline void Model<TSeq>::add_virus(Virus<TSeq> & v, epiworld_double preval)
inline void Model<TSeq>::add_virus(
Virus<TSeq> & 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_);
Expand All @@ -1002,57 +998,6 @@ inline void Model<TSeq>::add_virus(Virus<TSeq> & v, epiworld_double preval)

}

template<typename TSeq>
inline void Model<TSeq>::add_virus_n(Virus<TSeq> & 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<TSeq> >(v));

}

template<typename TSeq>
inline void Model<TSeq>::add_virus_fun(Virus<TSeq> & v, VirusToAgentFun<TSeq> 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<TSeq> >(v));

}

template<typename TSeq>
inline void Model<TSeq>::add_tool(Tool<TSeq> & t, epiworld_double preval)
{
Expand Down
4 changes: 2 additions & 2 deletions include/epiworld/models/diffnet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ inline ModelDiffNet<TSeq>::ModelDiffNet(
model.add_param(prob_adopt, parname);

// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> innovation(innovation_name);
epiworld::Virus<TSeq> 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);
Expand Down
24 changes: 12 additions & 12 deletions include/epiworld/models/init-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ inline std::function<void(epiworld::Model<TSeq>*)> create_init_function_sir(
double n = static_cast<double>(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
Expand Down Expand Up @@ -106,10 +106,10 @@ inline std::function<void(epiworld::Model<TSeq>*)> create_init_function_sird(
double n = static_cast<double>(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
Expand Down Expand Up @@ -184,10 +184,10 @@ inline std::function<void(epiworld::Model<TSeq>*)> create_init_function_seir(
double n = static_cast<double>(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
Expand Down Expand Up @@ -266,10 +266,10 @@ inline std::function<void(epiworld::Model<TSeq>*)> create_init_function_seird(
double n = static_cast<double>(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
Expand Down
4 changes: 2 additions & 2 deletions include/epiworld/models/seir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ inline ModelSEIR<TSeq>::ModelSEIR(
model.add_param(recovery_rate, "Recovery rate");

// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> virus(vname);
epiworld::Virus<TSeq> virus(vname, prevalence, true);
virus.set_state(ModelSEIR<TSeq>::EXPOSED, ModelSEIR<TSeq>::REMOVED, ModelSEIR<TSeq>::REMOVED);

virus.set_prob_infecting(&model("Transmission rate"));
virus.set_incubation(&model("Incubation days"));
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)");

Expand Down
4 changes: 2 additions & 2 deletions include/epiworld/models/seirconnected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ inline ModelSEIRCONN<TSeq>::ModelSEIRCONN(


// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> virus(vname);
epiworld::Virus<TSeq> virus(vname, prevalence, true);
virus.set_state(
ModelSEIRCONN<TSeq>::EXPOSED,
ModelSEIRCONN<TSeq>::RECOVERED,
Expand All @@ -333,7 +333,7 @@ inline ModelSEIRCONN<TSeq>::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

Expand Down
4 changes: 2 additions & 2 deletions include/epiworld/models/seird.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ inline ModelSEIRD<TSeq>::ModelSEIRD(
model.add_param(death_rate, "Death rate");

// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> virus(vname);
epiworld::Virus<TSeq> virus(vname, prevalence, true);
virus.set_state(ModelSEIRD<TSeq>::EXPOSED, ModelSEIRD<TSeq>::REMOVED, ModelSEIRD<TSeq>::DECEASED);

virus.set_prob_infecting(&model("Transmission rate"));
Expand All @@ -177,7 +177,7 @@ inline ModelSEIRD<TSeq>::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)");

Expand Down
4 changes: 2 additions & 2 deletions include/epiworld/models/seirdconnected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ inline ModelSEIRDCONN<TSeq>::ModelSEIRDCONN(


// Preparing the virus -------------------------------------------
epiworld::Virus<TSeq> virus(vname);
epiworld::Virus<TSeq> virus(vname, prevalence, true);
virus.set_state(
ModelSEIRDCONN<TSeq>::EXPOSED,
ModelSEIRDCONN<TSeq>::REMOVED,
Expand All @@ -352,7 +352,7 @@ inline ModelSEIRDCONN<TSeq>::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

Expand Down
Loading

0 comments on commit 917d21d

Please sign in to comment.