Skip to content

Commit

Permalink
Prevent and check for NaN memory scores
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Dec 13, 2023
1 parent 54e4987 commit fca2971
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 16 additions & 0 deletions avida-core/source/main/cDeme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ int cDeme::GetNumParasites() const
return count;
}

void cDeme::UpdateParasiteMemoryScore(const double decay) {
if (GetSize() == 0) return;
const double inc = static_cast<double>(GetNumParasites()) / GetSize();
SetParasiteMemoryScore(GetParasiteMemoryScore() * decay + inc);
}

void cDeme::SetParasiteMemoryScore(const double score) {
if (!std::isfinite(score)) {
cerr << "ERROR: SetParasiteMemoryScore() called with " << score
<< "current score is " << GetParasiteMemoryScore()
<< std::endl;
exit(1);
}
parasite_memory_score = score;
}

void cDeme::ProcessPreUpdate()
{
deme_resource_count.SetSpatialUpdate(m_world->GetStats().GetUpdate());
Expand Down
9 changes: 2 additions & 7 deletions avida-core/source/main/cDeme.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,9 @@ class cDeme
else return static_cast<double>(GetNumParasites()) / GetOrgCount();
}

void UpdateParasiteMemoryScore(const double decay) {
parasite_memory_score += static_cast<double>(GetNumParasites()) / GetSize();
parasite_memory_score *= decay;
}
void UpdateParasiteMemoryScore(const double decay);
double GetParasiteMemoryScore() const { return parasite_memory_score; }
void SetParasiteMemoryScore(const double score) {
parasite_memory_score = score;
}
void SetParasiteMemoryScore(const double score);

void IncOrgCount() { cur_org_count++; }
void DecOrgCount() { cur_org_count--; }
Expand Down

0 comments on commit fca2971

Please sign in to comment.