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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Aug 15 10:26:16 PDT 2007


Author: beckma24
Date: 2007-08-15 13:26:16 -0400 (Wed, 15 Aug 2007)
New Revision: 1939

Modified:
   branches/energy/source/main/cPopulation.cc
Log:
Added energy model specific portion to ReplicateDemes.  Orginal version of ReplicateDemes inserts into the population a copy of a copy, which is not good when resources can be absorbed by the organism on injsection.  Also, moved deme resets in ReplicateDemes to be in more appropriate place, but left orginal part alone (this part needs to be fixed).

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-08-15 16:50:47 UTC (rev 1938)
+++ branches/energy/source/main/cPopulation.cc	2007-08-15 17:26:16 UTC (rev 1939)
@@ -1123,12 +1123,7 @@
     for (int i=0; i<target_deme.GetSize(); i++) {
       KillOrganism(cell_array[target_deme.GetCellID(i)]);
     }
-    
-    // And reset both demes, in case they have any cleanup work to do.
-/*    source_deme.Reset();
-    target_deme.Reset();
-*/
-    
+        
     // Ok, there are two potential places where the seed for the target deme can
     // come from.  First, it could be a random organism in the source deme.
     // Second, it could be an offspring of the source deme's germline, if the config
@@ -1165,7 +1160,11 @@
       for (int i=0; i<source_deme.GetSize(); i++) {
         KillOrganism(cell_array[source_deme.GetCellID(i)]);
       }
-      
+    
+      // And reset both demes, in case they have any cleanup work to do.
+      source_deme.Reset();
+      target_deme.Reset();
+  
       // Lineage label is wrong here; fix.
       if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get()) {
         InjectGenome(source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1)),
@@ -1185,36 +1184,55 @@
         cell1_id = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
       }
       
-      cOrganism* seed = cell_array[cell1_id].GetOrganism();
-      
-      // And do the replication into the central cell of the target deme...
-      const int cell2_id = target_deme.GetCellID(target_deme.GetWidth()/2, target_deme.GetHeight()/2);
-      InjectClone(cell2_id, *seed);
-      
-      // Kill all the organisms in the source deme.
-      seed = 0; // Note that we're killing the organism that seed points to.
-      for (int i=0; i<source_deme.GetSize(); i++) {
-        KillOrganism(cell_array[source_deme.GetCellID(i)]);
+      if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
+        cOrganism* seed_org = cell_array[cell1_id].GetOrganism();
+        cGenome seed_genome = seed_org->GetGenome();
+        int seed_lineage = seed_org->GetLineageLabel();
+
+        // Kill all the organisms in the source deme.  Orgs. in dest. deme are already killed
+        for (int i=0; i<source_deme.GetSize(); i++) {
+          KillOrganism(cell_array[source_deme.GetCellID(i)]);
+        }
+
+        source_deme.Reset();
+        target_deme.Reset();
+
+        InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2),seed_genome,seed_lineage); // source deme
+        InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2),seed_genome,seed_lineage); // destination deme
+        
+      } else {
+        cOrganism* seed = cell_array[cell1_id].GetOrganism();
+        
+        // And do the replication into the central cell of the target deme...
+        const int cell2_id = target_deme.GetCellID(target_deme.GetWidth()/2, target_deme.GetHeight()/2);
+        InjectClone(cell2_id, *seed);
+        
+        // Kill all the organisms in the source deme.
+        seed = 0; // Note that we're killing the organism that seed points to.
+        for (int i=0; i<source_deme.GetSize(); i++) {
+          KillOrganism(cell_array[source_deme.GetCellID(i)]);
+        }
+        
+        // Inject the target offspring back into the source ID.
+        const int cell3_id = source_deme.GetCellID(source_deme.GetWidth()/2, source_deme.GetHeight()/2);
+        InjectClone(cell3_id, *cell_array[cell2_id].GetOrganism());
+        
+        // Rotate both injected cells to face northwest.
+        int offset=target_deme.GetCellID(0);
+        cell_array[cell2_id].Rotate(cell_array[GridNeighbor(cell2_id-offset,
+                                                            target_deme.GetWidth(), 
+                                                            target_deme.GetHeight(), -1, -1)+offset]);
+        offset = source_deme.GetCellID(0);
+        cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
+                                                            source_deme.GetWidth(),
+                                                            source_deme.GetHeight(), -1, -1)+offset]);
+                                                            
+                                          
+        // This is in the wrong place.  Reset should be done after the demes are cleared and before the org. is injected.
+        source_deme.Reset();
+        target_deme.Reset();
       }
-      
-      // Inject the target offspring back into the source ID.
-      const int cell3_id = source_deme.GetCellID(source_deme.GetWidth()/2, source_deme.GetHeight()/2);
-      InjectClone(cell3_id, *cell_array[cell2_id].GetOrganism());
-      
-      // Rotate both injected cells to face northwest.
-      int offset=target_deme.GetCellID(0);
-      cell_array[cell2_id].Rotate(cell_array[GridNeighbor(cell2_id-offset,
-                                                          target_deme.GetWidth(), 
-                                                          target_deme.GetHeight(), -1, -1)+offset]);
-      offset = source_deme.GetCellID(0);
-      cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
-                                                          source_deme.GetWidth(),
-                                                          source_deme.GetHeight(), -1, -1)+offset]);
     }
-    
-    // And reset both demes, in case they have any cleanup work to do.
-    source_deme.Reset();
-    target_deme.Reset();
   }
 }
 




More information about the Avida-cvs mailing list