[Avida-cvs] [avida-svn] r702 - development/source/main

ofria@myxo.css.msu.edu ofria at myxo.css.msu.edu
Mon May 22 22:04:43 PDT 2006


Author: ofria
Date: 2006-05-23 01:04:43 -0400 (Tue, 23 May 2006)
New Revision: 702

Modified:
   development/source/main/cAvidaConfig.h
   development/source/main/cBirthChamber.cc
   development/source/main/cBirthChamber.h
Log:
Setup a new config option MAX_BIRTH_WAIT_TIME, which gives the maximum number
of updates that an incipient offspring can sit in the birth chamber and still
be used.


Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2006-05-23 02:04:55 UTC (rev 701)
+++ development/source/main/cAvidaConfig.h	2006-05-23 05:04:43 UTC (rev 702)
@@ -54,16 +54,16 @@
 private:                                                                      \
   TYPE value;                                                         /* 3 */ \
 public:                                                                       \
-    void LoadString(const cString & str_value) {                        /* 4 */ \
-      value = cStringUtil::Convert(str_value, value);                           \
-    }                                                                           \
+    void LoadString(const cString & str_value) {                      /* 4 */ \
+      value = cStringUtil::Convert(str_value, value);                         \
+    }                                                                         \
     cEntry_ ## NAME() : cBaseConfigEntry(#NAME, #TYPE, #DEFAULT, DESC) {/* 5 */ \
-      LoadString(GetDefault());                                         /* 6 */ \
-        global_group_list.GetLast()->AddEntry(this);                      /* 7 */ \
-    }                                                                           \
-    TYPE Get() const { return value; }                                  /* 8 */ \
-    void Set(TYPE in_value) { value = in_value; }                               \
-    cString AsString() { return cStringUtil::Convert(value); }          /* 9 */ \
+      LoadString(GetDefault());                                       /* 6 */ \
+        global_group_list.GetLast()->AddEntry(this);                  /* 7 */ \
+    }                                                                         \
+    TYPE Get() const { return value; }                                /* 8 */ \
+    void Set(TYPE in_value) { value = in_value; }                             \
+    cString AsString() { return cStringUtil::Convert(value); }        /* 9 */ \
 } NAME                                                               /* 10 */ \
 
 
@@ -185,7 +185,10 @@
   CONFIG_ADD_VAR(ALLOC_METHOD, int, 0, "(Orignal CPU Only)\n0 = Allocated space is set to default instruction.\n1 = Set to section of dead genome (Necrophilia)\n2 = Allocated space is set to random instruction.");
   CONFIG_ADD_VAR(DIVIDE_METHOD, int, 1, "0 = Divide leaves state of mother untouched.\n1 = Divide resets state of mother\n    (after the divide, we have 2 children)\n2 = Divide resets state of current thread only\n    (does not touch possible parasite threads)");
   CONFIG_ADD_VAR(GENERATION_INC_METHOD, int, 1, "0 = Only the generation of the child is\n    increased on divide.\n1 = Both the generation of the mother and child are\n    increased on divide (good with DIVIDE_METHOD 1).");
+
+  CONFIG_ADD_GROUP(RECOMBINATION_GROUP, "Sexual Recombination and Modularity");
   CONFIG_ADD_VAR(RECOMBINATION_PROB, double, 1.0, "probability of recombination in div-sex");
+  CONFIG_ADD_VAR(MAX_BIRTH_WAIT_TIME, int, -1, "Updates incipiant orgs can wait for crossover");
   CONFIG_ADD_VAR(MODULE_NUM, int, 0, "number of modules in the genome");
   CONFIG_ADD_VAR(CONT_REC_REGS, int, 1, "are (modular) recombination regions continuous");
   CONFIG_ADD_VAR(CORESPOND_REC_REGS, int, 1, "are (modular) recombination regions swapped randomly\n or with corresponding positions?");

Modified: development/source/main/cBirthChamber.cc
===================================================================
--- development/source/main/cBirthChamber.cc	2006-05-23 02:04:55 UTC (rev 701)
+++ development/source/main/cBirthChamber.cc	2006-05-23 05:04:43 UTC (rev 702)
@@ -43,7 +43,26 @@
   return false;
 }
 
+bool cBirthChamber::EvaluateEntry(const cBirthEntry & entry) const
+{
+  // If there is no organism in the entry, return false.
+  if (entry.update_in == -1) return false;
 
+  // If there is an organis, determien if it is still alive.
+  const int max_wait_time = m_world->GetConfig().MAX_BIRTH_WAIT_TIME.Get();
+
+  // If the max_wait_time is -1, there is no timeout, so its alive.
+  if (max_wait_time == -1) return true;
+
+  // Otherwise, check if few enough updates have gone by...
+  const int cur_update = m_world->GetStats().GetUpdate();
+  const int max_update = entry.update_in + max_wait_time;
+
+  if (cur_update > max_update) return false;  // Too many updates...
+
+  return true;
+}
+
 int cBirthChamber::PickRandRecGenome(cAvidaContext& ctx, const int& parent_id, int world_x, int world_y)
 {
   bool done = false; 
@@ -134,8 +153,12 @@
   return true;
 }
 
-bool cBirthChamber::DoPairAsexBirth(cAvidaContext& ctx, const cBirthEntry& old_entry, const cGenome& new_genome,
-                                    cOrganism& parent, tArray<cOrganism*>& child_array, tArray<cMerit>& merit_array)
+bool cBirthChamber::DoPairAsexBirth(cAvidaContext& ctx,
+				    const cBirthEntry& old_entry,
+				    const cGenome& new_genome,
+                                    cOrganism& parent,
+				    tArray<cOrganism*>& child_array,
+				    tArray<cMerit>& merit_array)
 {
   // Build both child organisms...
   child_array.Resize(2);
@@ -171,7 +194,7 @@
   }
 
   // Determine if we have an offspring of this length waiting already...
-  if (size_wait_entry[child_length].update_in == -1) {
+  if ( EvaluateEntry(size_wait_entry[child_length]) == false ) {
     cGenotype * parent_genotype = parent.GetGenotype();
     parent_genotype->IncDeferAdjust();
     size_wait_entry[child_length].genome = child_genome;
@@ -196,7 +219,7 @@
   }
 
   // Determine if we have an offspring of this length waiting already...
-  if (mate_select_wait_entry[mate_id].update_in == -1) {
+  if ( EvaluateEntry(mate_select_wait_entry[mate_id]) == false ) {
     cGenotype * parent_genotype = parent.GetGenotype();
     parent_genotype->IncDeferAdjust();
     mate_select_wait_entry[mate_id].genome = child_genome;
@@ -245,7 +268,7 @@
   const int parent_deme = (int) parent_id/(world_y*world_x/num_demes);
 
   // If nothing is waiting, store child locally.
-  if (deme_wait_entry[parent_deme].update_in == -1) { 
+  if ( EvaluateEntry(deme_wait_entry[parent_deme]) == false ) { 
     cGenotype * parent_genotype = parent.GetGenotype();
     parent_genotype->IncDeferAdjust();
     deme_wait_entry[parent_deme].genome = child_genome;
@@ -263,7 +286,7 @@
 cBirthChamber::cBirthEntry* cBirthChamber::FindSexGlobalWaiting(const cGenome& child_genome, cOrganism& parent)
 {
   // If no other child is waiting, store this one.
-  if (global_wait_entry.update_in == -1){
+  if ( EvaluateEntry(global_wait_entry) == false ) {
     cGenotype * parent_genotype = parent.GetGenotype();
     parent_genotype->IncDeferAdjust();
     global_wait_entry.genome = child_genome; 

Modified: development/source/main/cBirthChamber.h
===================================================================
--- development/source/main/cBirthChamber.h	2006-05-23 02:04:55 UTC (rev 701)
+++ development/source/main/cBirthChamber.h	2006-05-23 05:04:43 UTC (rev 702)
@@ -61,6 +61,8 @@
 
 
   // Private methods...
+  bool EvaluateEntry(const cBirthEntry & entry) const;
+
   bool RegionSwap(cCPUMemory& genome0, cCPUMemory& genome1, int start0, int end0, int start1, int end1);
   void GenomeSwap(cCPUMemory& genome0, cCPUMemory& genome1, double& merit0, double& merit1);
 




More information about the Avida-cvs mailing list