[Avida-SVN] r2155 - branches/energy/source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Oct 29 07:07:30 PDT 2007


Author: beckma24
Date: 2007-10-29 10:07:29 -0400 (Mon, 29 Oct 2007)
New Revision: 2155

Modified:
   branches/energy/source/main/cAvidaConfig.h
   branches/energy/source/main/cDeme.cc
   branches/energy/source/main/cDemeCellEvent.cc
   branches/energy/source/main/cDemeCellEvent.h
   branches/energy/source/main/cGermline.h
   branches/energy/source/main/cOrgMessagePredicate.h
   branches/energy/source/main/cPopulation.cc
Log:
Added LOG_GERMLINE config option, added event death, and fixed deme_sat_predicate.dat print error.  Still need to deside how to handle printing of different types of predicates.

Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cAvidaConfig.h	2007-10-29 14:07:29 UTC (rev 2155)
@@ -414,6 +414,7 @@
   CONFIG_ADD_VAR(LOG_GENOTYPES, int, 0, "0 = off, 1 = print ALL, 2 = print threshold ONLY.");
   CONFIG_ADD_VAR(LOG_THRESHOLD, bool, 0, "0/1 (off/on) toggle to print file.");
   CONFIG_ADD_VAR(LOG_SPECIES, bool, 0, "0/1 (off/on) toggle to print file.");
+  CONFIG_ADD_VAR(LOG_GERMLINE, bool, 0, "0/1 (off/on");
   
   CONFIG_ADD_GROUP(LINEAGE_GROUP, "Lineage\nNOTE: This should probably be called \"Clade\"\nThis one can slow down avida a lot. It is used to get an idea of how\noften an advantageous mutation arises, and where it goes afterwards.\nLineage creation options are.  Works only when LOG_LINEAGES is set to 1.\n  0 = manual creation (on inject, use successive integers as lineage labels).\n  1 = when a child's (potential) fitness is higher than that of its parent.\n  2 = when a child's (potential) fitness is higher than max in population.\n  3 = when a child's (potential) fitness is higher than max in dom. lineage\n*and* the child is in the dominant lineage, or (2)\n  4 = when a child's (potential) fitness is higher than max in dom. lineage\n(and that of its own lineage)\n  5 = same as child's (potential) fitness is higher than that of the\n      currently dominant organism, and also than that of any organism\n      currently in the same lineage.\n  6 = when a child's (potential) f!
 itness is higher than any organism\n      currently in the same lineage.\n  7 = when a child's (potential) fitness is higher than that of any\n      organism in its line of descent");
   CONFIG_ADD_VAR(LOG_LINEAGES, bool, 0, "");

Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cDeme.cc	2007-10-29 14:07:29 UTC (rev 2155)
@@ -121,13 +121,14 @@
   for(int i = cell_events.Size()-1; i >= 0; i--) {
     if(cell_events[i].GetTimeToLive() <= m_world->GetStats().GetUpdate()) {
       //remove predicates from stats and deme
-      for(int j = message_pred_list.Size()-1; j >= 0; j--) {
+/*      for(int j = message_pred_list.Size()-1; j >= 0; j--) {
         if(message_pred_list[j]->GetEvent()->GetEventID() == cell_events[i].GetEventID()) {
           m_world->GetStats().RemoveMessagePredicate(message_pred_list[j]);
           message_pred_list.RemoveAt(j);
         }
-      }
-      cell_events.RemoveAt(i);
+      }*/
+      cell_events[i].Terminate();
+//      cell_events.RemoveAt(i);
     }
   }
 
@@ -247,10 +248,12 @@
     exit(1);
   }
   for(int i = 0; i < cell_events.Size(); i++) {
-    int sink_cell = GetCellID(GetSize()/2);
-    cOrgMessagePred_EventReceivedCenter* pred = new cOrgMessagePred_EventReceivedCenter(&cell_events[i], sink_cell, times);
-    m_world->GetStats().AddMessagePredicate(pred);
-    message_pred_list.Add(pred);
+    if(!cell_events[i].IsDead()) {
+      int sink_cell = GetCellID(GetSize()/2);
+      cOrgMessagePred_EventReceivedCenter* pred = new cOrgMessagePred_EventReceivedCenter(&cell_events[i], sink_cell, times);
+      m_world->GetStats().AddMessagePredicate(pred);
+      message_pred_list.Add(pred);
+    }
   }
 }
 
@@ -260,9 +263,11 @@
     exit(1);
   }
   for(int i = 0; i < cell_events.Size(); i++) {
-    cOrgMessagePred_EventReceivedLeftSide* pred = new cOrgMessagePred_EventReceivedLeftSide(&cell_events[i], m_world->GetPopulation(), times);
-    m_world->GetStats().AddMessagePredicate(pred);
-    message_pred_list.Add(pred);
+    if(!cell_events[i].IsDead()) {
+      cOrgMessagePred_EventReceivedLeftSide* pred = new cOrgMessagePred_EventReceivedLeftSide(&cell_events[i], m_world->GetPopulation(), times);
+      m_world->GetStats().AddMessagePredicate(pred);
+      message_pred_list.Add(pred);
+    }
   }
 }
 
@@ -271,6 +276,7 @@
 }
 
 bool cDeme::PredicatePreviouslySatisfied(int pred_id) {
+  assert(pred_id < message_pred_list.Size());
   return message_pred_list[pred_id]->PreviouslySatisfied();
 }
 

Modified: branches/energy/source/main/cDemeCellEvent.cc
===================================================================
--- branches/energy/source/main/cDemeCellEvent.cc	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cDemeCellEvent.cc	2007-10-29 14:07:29 UTC (rev 2155)
@@ -10,6 +10,7 @@
   , m_time_to_live(time_to_live)
   , m_active(false)
   , m_static_pos(static_pos)
+  , m_dead (false)
 {
   assert(x1 <= x2);
   assert(y1 <= y2);
@@ -34,7 +35,7 @@
 }
 
 int cDemeCellEvent::GetNextEventCellID() {
-  if(m_active && m_iter < m_event_cells.GetSize()) {
+  if(!m_dead && m_active && m_iter < m_event_cells.GetSize()) {
     return m_event_cells[m_iter++];
   }
   m_iter = 0;
@@ -42,6 +43,10 @@
 }
 
 void cDemeCellEvent::ActivateEvent(cWorld* m_world) {
+  if(m_dead) {
+    return;
+  }
+
   m_eventID = m_world->GetRandom().GetInt(0x7FFFFFFF);
   if(!m_static_pos) {
     //non-static event position
@@ -58,6 +63,41 @@
   m_active = true;
 }
 
+int cDemeCellEvent::GetDelay() {
+  if(m_dead){
+    return 0;
+  }
+  return m_delay;
+}
+
+int cDemeCellEvent::GetDuration() {
+  if(m_dead){
+    return 0;
+  }
+  return m_duration;
+}
+
+int cDemeCellEvent::GetEventID() {
+  if(m_dead){
+    return -1;
+  }
+  return m_eventID;
+}
+
+int cDemeCellEvent::GetTimeToLive() {
+  if(m_dead){
+    return 0;
+  }
+  return m_time_to_live;
+}
+
+bool cDemeCellEvent::IsActive() {
+  if(m_dead){
+    return false;
+  }
+  return m_active;
+}
+
 void cDemeCellEvent::DeactivateEvent() {
   m_active = false;
 }

Modified: branches/energy/source/main/cDemeCellEvent.h
===================================================================
--- branches/energy/source/main/cDemeCellEvent.h	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cDemeCellEvent.h	2007-10-29 14:07:29 UTC (rev 2155)
@@ -10,19 +10,21 @@
   int m_eventID;
   int m_delay, m_duration, m_iter, m_deme_width, m_deme_height;
   int m_event_width, m_event_height, m_time_to_live;
-  bool m_active, m_static_pos;
+  bool m_active, m_static_pos, m_dead;
   
 public:
   cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0, 0, true, 0); }
   cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int deme_width, int deme_height, bool static_pos, int time_to_live);
   int GetNextEventCellID();
-  int GetDelay() { return m_delay; }
-  int GetDuration() { return m_duration; }
-  int GetEventID() { return m_eventID; }
-  int GetTimeToLive() { return m_time_to_live; }
-  bool IsActive() { return m_active; }
+  int GetDelay();
+  int GetDuration();
+  int GetEventID();
+  int GetTimeToLive();
+  bool IsActive();
+  bool IsDead() { return m_dead; }
 
   void ActivateEvent(cWorld* m_world);
   void DeactivateEvent();
+  void Terminate() { m_dead = true; }
 };
 #endif

Modified: branches/energy/source/main/cGermline.h
===================================================================
--- branches/energy/source/main/cGermline.h	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cGermline.h	2007-10-29 14:07:29 UTC (rev 2155)
@@ -42,6 +42,7 @@
     
 	cGenome& GetLatest() { return m_germline.back(); }
 	void Add(const cGenome& genome) { m_germline.push_back(genome); }
+        void RemoveOldest() { m_germline.erase(m_germline.begin()); }
 	unsigned int Size() const { return m_germline.size(); }
 };
 

Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cOrgMessagePredicate.h	2007-10-29 14:07:29 UTC (rev 2155)
@@ -163,6 +163,10 @@
   ~cOrgMessagePred_EventReceivedCenter() { }
   
   virtual bool operator()(const cOrgMessage& msg) {
+    if(m_event->IsDead()) {
+      return false;
+    }
+    
     if(m_event->IsActive() && 
        ((unsigned int)m_event->GetEventID() == msg.GetData() ||
         (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
@@ -180,6 +184,10 @@
   
   //need to print update!!!
   virtual void Print(std::ostream& out) {
+    if(m_event->IsDead()) {
+      return;
+    }
+
     out << m_event->GetEventID() << " [ ";
     for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); i++) {
       out << *i << " ";
@@ -239,6 +247,10 @@
   ~cOrgMessagePred_EventReceivedLeftSide() { }
   
   virtual bool operator()(const cOrgMessage& msg) {
+    if(m_event->IsDead()) {
+      return false;
+    }
+
     if(m_event->IsActive() && 
        ((unsigned int)m_event->GetEventID() == msg.GetData() ||
         (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
@@ -262,6 +274,10 @@
   }
   
   virtual void Print(std::ostream& out) {
+    if(m_event->IsDead()) {
+      return;
+    }
+
     out << m_event->GetEventID() << " [ ";
     for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); i++) {
       out << *i << " ";

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-10-24 14:05:38 UTC (rev 2154)
+++ branches/energy/source/main/cPopulation.cc	2007-10-29 14:07:29 UTC (rev 2155)
@@ -1165,6 +1165,11 @@
         source_germline.Add(next_germ);
       }
       
+      if(!m_world->GetConfig().LOG_GERMLINE.Get()) {
+        target_germline.RemoveOldest();
+        source_germline.RemoveOldest();
+      }
+      
       // Kill all the organisms in the source deme.
       for (int i=0; i<source_deme.GetSize(); i++) {
         KillOrganism(cell_array[source_deme.GetCellID(i)]);
@@ -1850,6 +1855,9 @@
 }
 
 void cPopulation::PrintDemeSatPredicate(const cString& filename) {
+
+  //ignore events that are dead
+
   int num_predicates = GetDeme(1).GetNumPredicates();
   tArray<int> predicateTotals(num_predicates);
   tArray<cString> predicateNames(num_predicates);
@@ -1867,6 +1875,7 @@
   
   cDataFile& df = m_world->GetDataFile(filename);
   df.WriteComment("Number of demes satisfying predicates");
+  df.WriteComment("WARNING: if predicates change type this data could be wrong");
   df.WriteTimeStamp();
   df.Write(m_world->GetStats().GetUpdate(), "Update");
   for(int i = 0; i < predicateTotals.GetSize(); i++) {




More information about the Avida-cvs mailing list