double energy;
std::set<unsigned int> mutated_sites;
+ Virus();
Virus(const Virus &v);
Virus(const Hamiltonian &H);
Virus(const Hamiltonian &H, const std::set<unsigned int> &mutated_sites);
unsigned int L_nt;
unsigned int L_aa;
+ NTVirus();
NTVirus(const NTVirus &v);
NTVirus(const std::string &NT);
NTVirus(const PottsHamiltonian &H, const std::string &NT);
VirusSpecies(std::string x) : Species(x) {}
VirusSpecies(std::string x, long c) : Species(x,c) {}
virus_map pop;
+ virus_map::iterator lastModified;
+ Virus lastDeleted;
};
class NTVirusSpecies : public Species {
NTVirusSpecies(std::string x) : Species(x) {}
NTVirusSpecies(std::string x, long c) : Species(x,c) {}
NTVirus_map pop;
+ NTVirus_map::iterator lastModified;
+ NTVirus lastDeleted;
};
class CTLSpecies : public Species {
if (V->pop.count(v)==0) V->pop[v] = 1; // new variant
else V->pop[v] += 1; // add to existing pool
+ V->lastModified = V->pop.find(v);
}
// update copy number
V->pop[iter->first] -= 1;
+ V->lastModified = iter;
+
// delete zero-population strains
- if (V->pop[iter->first] == 0)
- V->pop.erase(iter);
+ if (V->pop[iter->first] == 0) {
+ V->lastDeleted = iter->first;
+ V->lastModified = V->pop.end();
+ V->pop.erase(iter); // does not modify iter in C++11
+ }
+
}
return propensity;
}
-double KillingReaction::recalc(Reaction *rxn)
+double KillingReaction::recalc(Reaction *rxn_in)
{
- return this->recalc();
+ RxnType type = get_rxn_type(rxn_in);
+
+ switch (type) {
+
+ case RxnType::Virus: { // increased V->count
+ //VirusReaction *rxn = dynamic_cast<Reaction*>(rxn_in);
+ virus_map::iterator iter = V->lastModified;
+ propensity += rate_constant * T->count * T->recognized(iter->first);
+ break;
+ }
+
+ case RxnType::VirusDeath:
+ case RxnType::Killing: { // decreased V->count
+ virus_map::iterator iter = V->lastModified;
+ if (iter == V->pop.end()) {
+ propensity -= rate_constant * T->count * T->recognized(V->lastDeleted);
+ }
+ else {
+ propensity -= rate_constant * T->count * T->recognized(iter->first);
+ }
+
+ break;
+ }
+
+ case RxnType::Elementary:
+ case RxnType::CTLActivation:
+ case RxnType::NTVirus:
+ case RxnType::NTVirusDeath:
+ case RxnType::AAKilling:
+ case RxnType::CTLaaActivation: { // did not change V->count
+ propensity = this->recalc();
+ // TODO
+ //std::cerr << "shouldn't have hit here in KillingReaction::recalc(Reaction*)....\n";
+ break;
+ }
+
+ } // switch (type)
+
+ if (V->lastModified == V->pop.end()) { // deleted such that none is left
+ // TODO
+ }
+
+ //return this->recalc();
+ return propensity;
}
void KillingReaction::fire()
// update copy number
V->pop[iter->first] -= 1;
+ V->lastModified = iter;
// delete zero-population strains
- if (V->pop[iter->first] == 0)
- V->pop.erase(iter);
+ if (V->pop[iter->first] == 0) {
+ V->lastDeleted = iter->first;
+ V->lastModified = V->pop.end();
+ V->pop.erase(iter); // does not modify iter in C++11
+ }
}
if (V->pop.count(v)==0) V->pop[v] = 1; // new variant
else V->pop[v] += 1; // add to existing pool
+ V->lastModified = V->pop.find(v);
+
}
// update copy number
V->pop[iter->first] -= 1;
+ V->lastModified = iter;
+
// delete zero-population strains
- if (V->pop[iter->first] == 0)
- V->pop.erase(iter);
+ if (V->pop[iter->first] == 0) {
+ V->lastDeleted = iter->first;
+ V->lastModified = V->pop.end();
+ V->pop.erase(iter); // does not modify iter in C++11
+ }
}
return propensity;
}
-double AAKillingReaction::recalc(Reaction *rxn)
+double AAKillingReaction::recalc(Reaction *rxn_in)
{
- return this->recalc();
+ RxnType type = get_rxn_type(rxn_in);
+
+ switch (type) {
+
+ case RxnType::NTVirus: { // increased V->count
+ //VirusReaction *rxn = dynamic_cast<Reaction*>(rxn_in);
+ NTVirus_map::iterator iter = V->lastModified;
+ propensity += rate_constant * T->count * T->recognized(iter->first);
+ break;
+ }
+
+ case RxnType::NTVirusDeath:
+ case RxnType::AAKilling: { // decreased V->count
+ NTVirus_map::iterator iter = V->lastModified;
+ if (iter == V->pop.end()) {
+ propensity -= rate_constant * T->count * T->recognized(V->lastDeleted);
+ }
+ else {
+ propensity -= rate_constant * T->count * T->recognized(iter->first);
+ }
+
+ break;
+ }
+
+ case RxnType::Elementary:
+ case RxnType::CTLActivation:
+ case RxnType::Virus:
+ case RxnType::VirusDeath:
+ case RxnType::Killing:
+ case RxnType::CTLaaActivation: { // did not change V->count
+ propensity = this->recalc();
+ // TODO
+ //std::cerr << "shouldn't have hit here in KillingReaction::recalc(Reaction*)....\n";
+ break;
+ }
+
+ } // switch (type)
+
+ if (V->lastModified == V->pop.end()) { // deleted such that none is left
+ // TODO
+ }
+
+ //return this->recalc();
+ return propensity;
}
void AAKillingReaction::fire()
// update copy number
V->pop[iter->first] -= 1;
+ V->lastModified = iter;
// delete zero-population strains
- if (V->pop[iter->first] == 0)
- V->pop.erase(iter);
+ if (V->pop[iter->first] == 0) {
+ V->lastDeleted = iter->first;
+ V->lastModified = V->pop.end();
+ V->pop.erase(iter); // does not modify iter in C++11
+ }
}