[Avida-SVN] r2320 - in development: Avida.xcodeproj source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Tue Feb 12 14:00:10 PST 2008


Author: beckma24
Date: 2008-02-12 17:00:09 -0500 (Tue, 12 Feb 2008)
New Revision: 2320

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/main/cAvidaConfig.h
   development/source/main/cPopulation.cc
Log:
Added DEMES_PROB_ORG_TRANSFER config options which specifies the probablity that an organisms will be transferred to the offspring target deme when a parent deme replicates.  The organisms that are transferred are removed from the parent deme.  The organisms that are not transferred are collected and reinjected into the source deme.  The analogy is a fruiting body.  This option can not be used with germ lines, for now.      Also, 3 consistency were broken prior to this commit.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2008-02-12 16:19:22 UTC (rev 2319)
+++ development/Avida.xcodeproj/project.pbxproj	2008-02-12 22:00:09 UTC (rev 2320)
@@ -213,6 +213,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B5C965790D6211E400EFBFC8 /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B5C9657A0D6211E400EFBFC8 /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
 		56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1784,12 +1801,16 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
-			compatibilityVersion = "Xcode 2.4";
+			buildSettings = {
+			};
+			buildStyles = (
+				B5C965790D6211E400EFBFC8 /* Development */,
+				B5C9657A0D6211E400EFBFC8 /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
 			projectDirPath = "";
-			projectRoot = "";
 			targets = (
 				7023ED520C0A590200362B9C /* full-suite */,
 				DCC3164C07626CF3008F7A48 /* avida */,

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2008-02-12 16:19:22 UTC (rev 2319)
+++ development/source/main/cAvidaConfig.h	2008-02-12 22:00:09 UTC (rev 2320)
@@ -298,7 +298,8 @@
   CONFIG_ADD_VAR(DEMES_USE_GERMLINE, int, 0, "Whether demes use a distinct germline (default=0).");
   CONFIG_ADD_VAR(DEMES_HAVE_MERIT, int, 0, "Whether demes have merit (default=0).");
   CONFIG_ADD_VAR(DEMES_PREVENT_STERILE, int, 0, "Whether to prevent sterile demes from\nreplicating (default=0).");
-  CONFIG_ADD_VAR(DEMES_REPLICATE_SIZE, int, 1, "Number of organisms to create or copy from the\nsource deme to the target deme (default=1).");
+  CONFIG_ADD_VAR(DEMES_REPLICATE_SIZE, int, 1, "Number of identical organisms to create or copy from the\nsource deme to the target deme (default=1).");
+  CONFIG_ADD_VAR(DEMES_PROB_ORG_TRANSFER, double, 0.0, "Probablity of an organism being transferred from the\nsource deme to the target deme (default=0.0).");
   CONFIG_ADD_VAR(DEMES_ORGANISM_PLACEMENT, int, 0, "How organisms are placed during deme replication.\n0=cell-array middle (default).\n1=deme center.\n2=random placement.");
   CONFIG_ADD_VAR(DEMES_ORGANISM_FACING, int, 0, "How organisms are facing during deme replication.\n0=unchanged (default).\n1=northwest.\n2=random.");
   CONFIG_ADD_VAR(DEMES_MAX_AGE, int, 500, "The maximum age of a deme (in updates) to be\nused for age-based replication (default=500).");

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-12 16:19:22 UTC (rev 2319)
+++ development/source/main/cPopulation.cc	2008-02-12 22:00:09 UTC (rev 2320)
@@ -1249,7 +1249,6 @@
   }
 }
 
-
 /*! Helper method to seed a target deme from the organisms in the source deme.
 All organisms in the target deme are terminated, and a subset of the organisms in
 the source will be cloned to the target.
@@ -1257,41 +1256,91 @@
 void cPopulation::SeedDeme(cDeme& source_deme, cDeme& target_deme) {
   cRandom& random = m_world->GetRandom();
 
-  // Select a random organism from the source.  All we need to do here is get a
-  // genome and a lineage label.
-  cOrganism* seed = 0;
-  while(seed == 0) {
-    int cellid = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
-    if(cell_array[cellid].IsOccupied()) {
-      seed = cell_array[cellid].GetOrganism();
+  if(m_world->GetConfig().DEMES_PROB_ORG_TRANSFER.Get() == 0.0) {
+    // Select a random organism from the source.  All we need to do here is get a
+    // genome and a lineage label.
+    cOrganism* seed = 0;
+    while(seed == 0) {
+      int cellid = source_deme.GetCellID(random.GetUInt(source_deme.GetSize()));
+      if(cell_array[cellid].IsOccupied()) {
+        seed = cell_array[cellid].GetOrganism();
+      }
     }
-  }
+    
+    cGenome genome = seed->GetGenome();
+    int lineage = seed->GetLineageLabel();
+    seed = 0; // We're done with the seed organism.
+    
+    // Kill all the organisms in the source and target demes.
+    for (int i=0; i<target_deme.GetSize(); i++) {
+      KillOrganism(cell_array[target_deme.GetCellID(i)]);
+    }
+    for (int i=0; i<source_deme.GetSize(); i++) {
+      KillOrganism(cell_array[source_deme.GetCellID(i)]);
+    }
 
-  cGenome genome = seed->GetGenome();
-  int lineage = seed->GetLineageLabel();
-  seed = 0; // We're done with the seed organism.
-  
-  // Kill all the organisms in the source and target demes.
-  for (int i=0; i<target_deme.GetSize(); i++) {
-    KillOrganism(cell_array[target_deme.GetCellID(i)]);
-  }
-  for (int i=0; i<source_deme.GetSize(); i++) {
-    KillOrganism(cell_array[source_deme.GetCellID(i)]);
-  }
+    // Repopulation the source.
+    for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
+      int cellid = DemeSelectInjectionCell(source_deme, i);
+      InjectGenome(cellid, genome, lineage);
+      DemePostInjection(source_deme, cell_array[cellid]);
+    }
     
-  // Repopulation the source.
-  for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
-    int cellid = DemeSelectInjectionCell(source_deme, i);
-    InjectGenome(cellid, genome, lineage);
-    DemePostInjection(source_deme, cell_array[cellid]);
+    // And repopulate the target.
+    for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
+      int cellid = DemeSelectInjectionCell(target_deme, i);
+      InjectGenome(cellid, genome, lineage);
+      DemePostInjection(target_deme, cell_array[cellid]);
+    }
+  } else {
+    assert(m_world->GetConfig().DEMES_USE_GERMLINE.Get() != 1);
+    vector< pair<cGenome, int> > fruiting_body;
+
+    // Kill all the organisms in the target deme.
+    for (int i=0; i<target_deme.GetSize(); i++) {
+      KillOrganism(cell_array[target_deme.GetCellID(i)]);
+    }
+
+    for(int i = 0; i < source_deme.GetSize(); i++) {
+      int source_cellid = source_deme.GetCellID(i);
+      
+      if(cell_array[source_cellid].IsOccupied() && random.GetDouble(0.0, 1.0) < m_world->GetConfig().DEMES_PROB_ORG_TRANSFER.Get()) {
+        // save genome and lineage label of organism being transfered
+        cOrganism* seed = cell_array[source_cellid].GetOrganism();
+        cGenome genome = seed->GetGenome();
+        int lineage = seed->GetLineageLabel();
+        seed = 0; // We're done with the seed organism.
+        
+        // remove organism from source deme
+        KillOrganism(cell_array[source_cellid]);
+        
+        // inject into target deme
+        int target_cellid = DemeSelectInjectionCell(target_deme, i);
+        InjectGenome(target_cellid, genome, lineage);
+        DemePostInjection(target_deme, cell_array[target_cellid]);
+      }
+      
+      // collect genome and lineage label of organisms that remain in source deme
+      if(cell_array[source_cellid].IsOccupied()) {
+        cOrganism* seed = cell_array[source_cellid].GetOrganism();
+        fruiting_body.push_back(make_pair(seed->GetGenome(), seed->GetLineageLabel()));
+        seed = 0;
+
+        // kill remaining organisms
+        KillOrganism(cell_array[source_cellid]);
+      }
+    }
+    
+    int i = 0;
+    // reseed source deme
+    for(vector< pair<cGenome, int> >::iterator iter = fruiting_body.begin(); iter < fruiting_body.end(); iter++) {
+      // inject back into source deme
+      int source_offspring_cellid = DemeSelectInjectionCell(source_deme, i);
+      InjectGenome(source_offspring_cellid, (*iter).first, (*iter).second);
+      DemePostInjection(source_deme, cell_array[source_offspring_cellid]);
+      i++;
+    }
   }
-  
-  // And repopulate the target.
-  for(int i=0; i< m_world->GetConfig().DEMES_REPLICATE_SIZE.Get(); ++i) {
-    int cellid = DemeSelectInjectionCell(target_deme, i);
-    InjectGenome(cellid, genome, lineage);
-    DemePostInjection(target_deme, cell_array[cellid]);
-  }
 }
 
 
@@ -1301,14 +1350,15 @@
 int cPopulation::DemeSelectInjectionCell(cDeme& deme, int sequence) {
   int cellid = -1;
   
-  assert(sequence == 0); //we only support one for now...
+  assert(sequence < deme.GetSize()); // cannot inject a sequence bigger then the deme
   
   switch(m_world->GetConfig().DEMES_ORGANISM_PLACEMENT.Get()) {
     case 0: { // Array-middle.
-      cellid = deme.GetCellID(deme.GetSize()/2);
+      cellid = deme.GetCellID((deme.GetSize()/2 + sequence) % deme.GetSize());
       break;
     }
     case 1: { // Sequential placement, start in the center of the deme.
+      assert(sequence == 0);  // not sure how to handle a sequence in this case (Ben)
       cellid = deme.GetCellID(deme.GetWidth()/2, deme.GetHeight()/2);
       break;
     }




More information about the Avida-cvs mailing list