/home/marcle/src/R/microsimulation/src/simple-example2.cc
Go to the documentation of this file.
#include <microsimulation.h>
namespace {
using namespace std;
using namespace ssim;
enum state_t {Healthy,Cancer,Death};
enum event_t {toOtherDeath, toCancer, toCancerDeath};
class SimplePerson : public cProcess
{
public:
state_t state;
int id;
SimplePerson(const int i = 0) : id(i) {};
void init();
virtual void handleMessage(const cMessage* msg);
static EventReport<short,short,double> report;
};
EventReport<short,short,double> SimplePerson::report;
void SimplePerson::init() {
state = Healthy;
scheduleAt(R::rweibull(8.0,85.0),toOtherDeath);
scheduleAt(R::rweibull(3.0,90.0),toCancer);
}
void SimplePerson::handleMessage(const cMessage* msg) {
SimplePerson::report.add(state,msg->kind,previousEventTime,now());
switch(msg->kind) {
case toOtherDeath:
case toCancerDeath:
Sim::stop_process();
break;
case toCancer:
state = Cancer;
if (R::runif(0.0,1.0) < 0.5)
scheduleAt(now() + R::rweibull(2.0,10.0), toCancerDeath);
break;
default:
REprintf("No valid kind of event\n");
break;
} // switch
} // handleMessage()
RcppExport SEXP callSimplePerson2(SEXP parms) {
SimplePerson person;
Rcpp::RNGScope scope;
Rcpp::List parmsl(parms);
int n = Rcpp::as<int>(parmsl["n"]);
SimplePerson::report.clear();
vector<double> ages;
for (double age=0.0; age<=100.0; age++) {
ages.push_back(age);
}
ages.push_back(1.0e+6);
SimplePerson::report.setPartition(ages);
for (int i = 0; i < n; i++) {
person = SimplePerson(i);
Sim::create_process(&person);
Sim::run_simulation();
Sim::clear();
}
return SimplePerson::report.wrap();
}
} // namespace simpleExample2
ssim::cMessage
cMessage class for OMNET++ API compatibility. This provides a heavier message class than Sim::Event,...
Definition: microsimulation.h:211
illnessDeath::Cancer
@ Cancer
Definition: illness-death.cpp:9
ssim::cProcess
cProcess class for OMNET++ API compatibility.
Definition: microsimulation.h:314
illnessDeath::toOtherDeath
@ toOtherDeath
Definition: illness-death.cpp:11
ssim::now
Time now()
now() function for compatibility with C++SIM
Definition: microsimulation.cc:9
illnessDeath::state_t
state_t
Definition: illness-death.cpp:9
Death
@ Death
Definition: person-r-20121231.cc:41
callSimplePerson2
SEXP callSimplePerson2(SEXP)
illnessDeath::toCancerDeath
@ toCancerDeath
Definition: illness-death.cpp:11
illnessDeath::toCancer
@ toCancer
Definition: illness-death.cpp:11
ssim
name space for the Siena simulator.
Definition: microsimulation.cc:3
ssim::EventReport
EventReport class for collecting statistics on person-time, prevalence and numbers of events.
Definition: microsimulation.h:666
Healthy
@ Healthy
Definition: person-r-20121231.cc:40
illnessDeath::report
EventReport< short, short, double > report
Definition: illness-death.cpp:13
illnessDeath::event_t
event_t
Definition: illness-death.cpp:11
microsimulation.h
ssim::cMessage::kind
short kind
Definition: microsimulation.h:222