[avida-cvs] avida CVS commits: /current/source/cpu hardware_cpu.cc hardware_cpu.hh /current/source/main birth_chamber.cc phenotype.cc phenotype.hh

dule123 avida-cvs at alife.org
Wed Oct 1 20:03:48 PDT 2003


dule123		Wed Oct  1 12:03:48 2003 EDT

  Modified files:              
    /avida/current/source/cpu	hardware_cpu.cc hardware_cpu.hh 
    /avida/current/source/main	birth_chamber.cc phenotype.cc 
                              	phenotype.hh 
  Log:
  
  Added another phenotype flag, cross_num, to specify the number of 
  crossovers that will happen during the reproduction. It also makes it 
  possible to have asexual organisms which wait in the birth chamber, just 
  as sexuals, but don't actually recombine (i.e. they have cross_num = 0)
  This is important since there seems to be a cost associated with waiting 
  in the birth chamber.
  
  
  
-------------- next part --------------
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.55 avida/current/source/cpu/hardware_cpu.cc:1.56
--- avida/current/source/cpu/hardware_cpu.cc:1.55	Thu Aug  7 20:24:18 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Wed Oct  1 12:03:46 2003
@@ -431,7 +431,11 @@
     cInstEntryCPU("h-copy10",   &cHardwareCPU::Inst_HeadCopy10),
 
     cInstEntryCPU("divide-sex",    &cHardwareCPU::Inst_HeadDivideSex),
-    cInstEntryCPU("divide-asex",   &cHardwareCPU::Inst_HeadDivide1),
+    cInstEntryCPU("divide-asex",   &cHardwareCPU::Inst_HeadDivideAsex),
+
+    cInstEntryCPU("div-sex",    &cHardwareCPU::Inst_HeadDivideSex),
+    cInstEntryCPU("div-asex",   &cHardwareCPU::Inst_HeadDivideAsex),
+    cInstEntryCPU("div-asex-w",   &cHardwareCPU::Inst_HeadDivideAsexWait),
 
     cInstEntryCPU("h-divide1",      &cHardwareCPU::Inst_HeadDivide1),
     cInstEntryCPU("h-divide2",      &cHardwareCPU::Inst_HeadDivide2),
@@ -3108,12 +3112,21 @@
 bool cHardwareCPU::Inst_HeadDivideSex()  
 { 
   organism->GetPhenotype().SetDivideSex(true);
+  organism->GetPhenotype().SetCrossNum(1);
   return Inst_HeadDivide(); 
 }
 
 bool cHardwareCPU::Inst_HeadDivideAsex()  
 { 
   organism->GetPhenotype().SetDivideSex(false);
+  organism->GetPhenotype().SetCrossNum(0);
+  return Inst_HeadDivide(); 
+}
+
+bool cHardwareCPU::Inst_HeadDivideAsexWait()  
+{ 
+  organism->GetPhenotype().SetDivideSex(false);
+  organism->GetPhenotype().SetCrossNum(0);
   return Inst_HeadDivide(); 
 }
 
Index: avida/current/source/cpu/hardware_cpu.hh
diff -u avida/current/source/cpu/hardware_cpu.hh:1.34 avida/current/source/cpu/hardware_cpu.hh:1.35
--- avida/current/source/cpu/hardware_cpu.hh:1.34	Thu Aug  7 20:24:18 2003
+++ avida/current/source/cpu/hardware_cpu.hh	Wed Oct  1 12:03:46 2003
@@ -418,6 +418,7 @@
 
   bool Inst_HeadDivideSex();
   bool Inst_HeadDivideAsex();
+  bool Inst_HeadDivideAsexWait();
 
   bool Inst_HeadDivide1();
   bool Inst_HeadDivide2();
Index: avida/current/source/main/birth_chamber.cc
diff -u avida/current/source/main/birth_chamber.cc:1.5 avida/current/source/main/birth_chamber.cc:1.6
--- avida/current/source/main/birth_chamber.cc:1.5	Sat May 17 02:48:08 2003
+++ avida/current/source/main/birth_chamber.cc	Wed Oct  1 12:03:47 2003
@@ -35,14 +35,16 @@
     parent.GetPhenotype().GetEnvironment();
   
   if (parent.GetPhenotype().DivideSex() == false) {
-    // This is asexual -- just build the child and return.
+    // This is asexual who doesn't need to wait in the birth chamber
+    // just build the child and return.
     child_array.Resize(1);
     child_array[0] = new cOrganism(child_genome, pop_interface, environment);
     return true;
   }
 
-  // If we make it this far, it must be a sexual divide.  See if there is
-  // anything for it to mate with.
+  // If we make it this far, it must be a sexual or a waiting, 
+  // non-recombining  asexual   
+  // See if there is anything for it to mate with.
   if (genome_waiting == false) {
     // There is nothing waiting!
     wait_genome = child_genome;
@@ -50,7 +52,8 @@
     return false;
   }
 
-  // We must now do a crossover.
+  // There is already someone in the birth chamber
+  // We must now do a crossover between the two 
 
   cCPUMemory genome0 = wait_genome;
   cCPUMemory genome1 = child_genome;
@@ -64,48 +67,57 @@
   int start1 = genome1.GetSize() * start0 / genome0.GetSize();
   int end1   = genome1.GetSize() * end0 / genome0.GetSize();
 
-  assert( start0 >= 0  &&  start0 < genome0.GetSize() );
-  assert( end0   >= 0  &&  end0   < genome0.GetSize() );
-  assert( start1 >= 0  &&  start1 < genome1.GetSize() );
-  assert( end1   >= 0  &&  end1   < genome1.GetSize() );
+  // How many crossovers should be do? For now, 0 or 1
+  if (parent.GetPhenotype().CrossNum() ==0) {
+    child_array.Resize(2);
+    child_array[0] = new cOrganism(genome0, pop_interface, environment);
+    child_array[1] = new cOrganism(genome1, pop_interface, environment);    
+    return true;
+  }
+  else {
+    assert( start0 >= 0  &&  start0 < genome0.GetSize() );
+    assert( end0   >= 0  &&  end0   < genome0.GetSize() ); 
+    assert( start1 >= 0  &&  start1 < genome1.GetSize() );
+    assert( end1   >= 0  &&  end1   < genome1.GetSize() );
   
-  // @CAO for the moment, force start to be less than end.
-  if (start0 > end0) Swap(start0, end0);
-  if (start1 > end1) Swap(start1, end1);
+    // @CAO for the moment, force start to be less than end.
+    if (start0 > end0) Swap(start0, end0);
+    if (start1 > end1) Swap(start1, end1);
   
-  // Calculate size of sections crossing over...
-  int size0 = end0 - start0;
-  int size1 = end1 - start1;
+    // Calculate size of sections crossing over...
+    int size0 = end0 - start0;
+    int size1 = end1 - start1;
   
-  int new_size0 = genome0.GetSize() - size0 + size1;
-  int new_size1 = genome1.GetSize() - size1 + size0;
+    int new_size0 = genome0.GetSize() - size0 + size1;
+    int new_size1 = genome1.GetSize() - size1 + size0;
   
-  // Don't Crossover if offspring will be illegal!!!
-  if( new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
-      new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE ){
-    return false;
-  }
+    // Don't Crossover if offspring will be illegal!!!
+    if( new_size0 < MIN_CREATURE_SIZE || new_size0 > MAX_CREATURE_SIZE ||
+        new_size1 < MIN_CREATURE_SIZE || new_size1 > MAX_CREATURE_SIZE ){
+      return false;
+    }
+
+    if (size0 > 0 && size1 > 0) {
+      cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
+      cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
+      genome0.Replace(start0, size0, cross1);
+      genome1.Replace(start1, size1, cross0);
+    }
+    else if (size0 > 0) {
+      cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
+      genome1.Replace(start1, size1, cross0);
+    }
+    else if (size1 > 0) {
+      cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
+      genome0.Replace(start0, size0, cross1);
+    }
+
+    // Build the two organisms.
+    child_array.Resize(2);
+    child_array[0] = new cOrganism(genome0, pop_interface, environment);
+    child_array[1] = new cOrganism(genome1, pop_interface, environment);
 
-  if (size0 > 0 && size1 > 0) {
-    cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
-    cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
-    genome0.Replace(start0, size0, cross1);
-    genome1.Replace(start1, size1, cross0);
-  }
-  else if (size0 > 0) {
-    cGenome cross0 = cGenomeUtil::Crop(genome0, start0, end0);
-    genome1.Replace(start1, size1, cross0);
-  }
-  else if (size1 > 0) {
-    cGenome cross1 = cGenomeUtil::Crop(genome1, start1, end1);
-    genome0.Replace(start0, size0, cross1);
+    return true;
   }
-
-  // Build the two organisms.
-  child_array.Resize(2);
-  child_array[0] = new cOrganism(genome0, pop_interface, environment);
-  child_array[1] = new cOrganism(genome1, pop_interface, environment);
-
-  return true;
 }
 
Index: avida/current/source/main/phenotype.cc
diff -u avida/current/source/main/phenotype.cc:1.35 avida/current/source/main/phenotype.cc:1.36
--- avida/current/source/main/phenotype.cc:1.35	Wed Jul 16 19:36:55 2003
+++ avida/current/source/main/phenotype.cc	Wed Oct  1 12:03:47 2003
@@ -124,11 +124,13 @@
   is_multi_thread = parent_phenotype.is_multi_thread;
   parent_true   = parent_phenotype.copy_true;
   parent_sex    = parent_phenotype.divide_sex;
+  parent_cross_num    = parent_phenotype.cross_num;
   to_die = false; 
 
   // Setup child info...
   copy_true          = false;
   divide_sex         = false;
+  cross_num          = 0;
   last_child_fertile = is_fertile;
   child_fertile      = true;
   child_copied_size  = 0;
@@ -192,11 +194,13 @@
   is_multi_thread = false;
   parent_true   = true;
   parent_sex    = false;
+  parent_cross_num    = 0;
   to_die = false;
 
   // Setup child info...
   copy_true         = false;
   divide_sex        = false;
+  cross_num        = 0;
   child_fertile     = true;
   last_child_fertile = true;
   child_copied_size = 0;
@@ -259,10 +263,12 @@
   (void) is_multi_thread;
   (void) parent_true;
   (void) parent_sex;
+  (void) parent_cross_num;
 
   // Reset child info...
   (void) copy_true;
   (void) divide_sex;
+  (void) cross_num;
   last_child_fertile = child_fertile;
   child_fertile     = true;
   (void) child_copied_size;;
@@ -335,10 +341,12 @@
   (void) is_multi_thread;
   (void) parent_true;
   (void) parent_sex;
+  (void) parent_cross_num;
 
   // Reset child info...
   (void) copy_true;
   (void) divide_sex;
+  (void) cross_num;
   (void) child_fertile;
   (void) last_child_fertile;
   (void) child_copied_size;
@@ -463,9 +471,11 @@
   fp << is_mutated          << " ";
   fp << parent_true         << " ";
   fp << parent_sex          << " ";
+  fp << parent_cross_num    << " ";
 
   fp << copy_true           << " ";
   fp << divide_sex          << " ";
+  fp << cross_num          << " ";
   fp << child_fertile       << " ";
   fp << last_child_fertile  << " ";
 
@@ -528,9 +538,11 @@
   fp >> is_mutated;
   fp >> parent_true;
   fp >> parent_sex;
+  fp >> parent_cross_num;
 
   fp >> copy_true;
   fp >> divide_sex;
+  fp >> cross_num;
   fp >> child_fertile;
   fp >> last_child_fertile;
 
Index: avida/current/source/main/phenotype.hh
diff -u avida/current/source/main/phenotype.hh:1.36 avida/current/source/main/phenotype.hh:1.37
--- avida/current/source/main/phenotype.hh:1.36	Tue Jun 24 14:56:39 2003
+++ avida/current/source/main/phenotype.hh	Wed Oct  1 12:03:47 2003
@@ -92,10 +92,12 @@
   bool is_multi_thread;  // Does this organism have 2 or more threads?
   bool parent_true;      // Is this genome an exact copy of its parent's?
   bool parent_sex;       // Did the parent divide with sex?
+  int  parent_cross_num; // How many corssovers did the parent do? 
 
   // 6. Child information...
   bool copy_true;        // Can this genome produce an exact copy of itself?
   bool divide_sex;       // Was this child created with a sexual divide?
+  int  cross_num  ;      // How many crossovers should this child do?
   bool child_fertile;    // Will this organism's next child be fertile?
   bool last_child_fertile;  // Was the child being born to be fertile?
   int child_copied_size; // Instruction copied into child.
@@ -206,10 +208,12 @@
   bool IsMultiThread() const { assert(initialized == true); return is_multi_thread; }
   bool ParentTrue() const { assert(initialized == true); return parent_true; }
   bool ParentSex() const  { assert(initialized == true); return parent_sex; }
+  int  ParentCrossNum() const  { assert(initialized == true); return parent_cross_num; }
 
   bool CopyTrue() const   { assert(initialized == true); return copy_true; }
   bool DivideSex() const  { assert(initialized == true); return divide_sex; }
-  bool ChildFertile() const
+  int  CrossNum() const  { assert(initialized == true); return cross_num; }
+  bool  ChildFertile() const
     { assert(initialized == true); return child_fertile;}
   int GetChildCopiedSize() const
     { assert(initialized == true); return child_copied_size; }
@@ -224,6 +228,7 @@
   void SetLinesCopied(int _copied_size) { child_copied_size = _copied_size; }
   void SetDivType(double _div_type) { div_type = _div_type; }  
   void SetDivideSex(bool _divide_sex) { divide_sex = _divide_sex; }  
+  void SetCrossNum(int _cross_num) { cross_num = _cross_num; }
 
   void IncCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]++; } 
   void DecCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]--; } 
@@ -240,8 +245,10 @@
   bool & IsMutated()  { assert(initialized == true); return is_mutated; }
   bool & ParentTrue() { assert(initialized == true); return parent_true; }
   bool & ParentSex()  { assert(initialized == true); return parent_sex; }
+  int & ParentCrossNum()  { assert(initialized == true); return parent_cross_num; }
   bool & CopyTrue()   { assert(initialized == true); return copy_true; }
   bool & DivideSex()  { assert(initialized == true); return divide_sex; }
+  int & CrossNum()     { assert(initialized == true); return cross_num; }
   bool & ChildFertile() { assert(initialized == true); return child_fertile; }
   bool & IsMultiThread() { assert(initialized == true); return is_multi_thread; }
 };


More information about the Avida-cvs mailing list