See
- The definitions eventloggers.h
- The description Event Loggers
<project-file type=“source”/> <content> #include “eventloggers.h” #include <simemindividual.h> #include <simprocess.h> #include “node.h”
SimContactLogger::SimContactLogger() { }
SimContactLogger::~SimContactLogger() { }
bool SimContactLogger::loggable(SimSchedule *event) const {
return dynamic_cast<Link*>(event) != NULL;
}
void SimContactLogger::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (proc == NULL) return; const Node *n = dynamic_cast<const Node*>(agent); const Link *link = dynamic_cast<const Link*>(event); if (n == NULL || link == NULL || link->neighbor() == NULL) return; proc->logger()<<time<<" : "<<n->id()<<" : contacted with : "<<link->neighbor()->id()<<std::endl;
}
SimInfectionStateLogger::SimInfectionStateLogger() { }
SimInfectionStateLogger::~SimInfectionStateLogger() { }
bool SimInfectionStateLogger::loggable(SimSchedule *event) const {
return dynamic_cast<SimInfectionState*>(event) != NULL;
}
void SimInfectionStateLogger::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (agent == NULL || proc == NULL) return; const SimInfectionState *state = dynamic_cast<const SimInfectionState*>(event); if (state == NULL) return; proc->logger()<<time<<" : "<<agent->id(); switch (state->nextState()) { case SimInfectionState::SIM_PROGRESS : { const SimInfectionStage *stage = state->stage(); if (stage == NULL) proc->logger()<<" : recovered"; else proc->logger()<<" : Infection state changed to : "<<stage->id(); } break; case SimInfectionState::SIM_DIE : proc->logger()<<" : died"; break; case SimInfectionState::SIM_MUTATE : proc->logger()<<" : pathogen mutated to : "<<state->mutant()->id(); break; } proc->logger()<<std::endl;
}
Counter::Counter() {
reset();
}
Counter::~Counter() { }
void Counter::reset() {
I = 0; T = 0;
}
bool Counter::loggable(SimSchedule *event) const {
return dynamic_cast<SimInfectionState*>(event) != NULL;
}
void Counter::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (agent == NULL || proc == NULL) return; const SimInfectionState *state = dynamic_cast<const SimInfectionState*>(event); if (state == NULL) return; while (time > T) { proc->logger() << T << " : I : " << I << std::endl; T++; } if (state->nextState() == SimInfectionState::SIM_PROGRESS) { const SimInfectionStage *stage = state->stage(); if (stage == NULL) { I--; if (I == 0) { proc->logger() << T << " : I : " << I << std::endl; proc->quit(); } } else I++; }
}
void CaseCounter::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (agent == NULL || proc == NULL) return; const SimInfectionState *state = dynamic_cast<const SimInfectionState*>(event); if (state == NULL) return; while (time > T) { proc->logger() << T << " : I : " << I << std::endl; I = 0; T++; } if (state->nextState() == SimInfectionState::SIM_PROGRESS) { const SimInfectionStage *stage = state->stage(); if (stage != NULL && stage->id() == 2) I++; }
}
SimDieLogger::SimDieLogger() { }
SimDieLogger::~SimDieLogger() { }
bool SimDieLogger::loggable(SimSchedule *event) const {
return dynamic_cast<SimDieEvent*>(event) != NULL;
}
void SimDieLogger::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (agent == NULL || proc == NULL) return; proc->logger()<<time<<" : "<<agent->id()<<" : died"; proc->logger()<<std::endl;
}
SimChangeOwnerLogger::SimChangeOwnerLogger() { }
SimChangeOwnerLogger::~SimChangeOwnerLogger() { }
bool SimChangeOwnerLogger::loggable(SimSchedule *event) const {
return dynamic_cast<SimChangeOwnerEvent*>(event) != NULL;
}
void SimChangeOwnerLogger::log(SimProcess *proc, float time, const SimAgent *agent, const SimSchedule *event) {
if (agent == NULL || proc == NULL) return; proc->logger()<<time<<" : "<<agent->id()<<" : change owner "; if (agent->owner() == NULL) proc->logger()<<": failed"; else proc->logger()<<"to : "<<agent->owner()->id(); proc->logger()<<std::endl;
} </content> <use name=“eventloggers.h”/> <use name=“node.h”/>