[Avida-SVN] r2752 - in branches/interrupt/source: cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Aug 15 09:14:39 PDT 2008


Author: beckma24
Date: 2008-08-15 12:14:39 -0400 (Fri, 15 Aug 2008)
New Revision: 2752

Modified:
   branches/interrupt/source/cpu/cCPUMemory.cc
   branches/interrupt/source/main/cGenome.cc
   branches/interrupt/source/main/cGenomeUtil.cc
Log:
added site protection to cCPUMemory and cGenomeUtil

Modified: branches/interrupt/source/cpu/cCPUMemory.cc
===================================================================
--- branches/interrupt/source/cpu/cCPUMemory.cc	2008-08-15 14:10:16 UTC (rev 2751)
+++ branches/interrupt/source/cpu/cCPUMemory.cc	2008-08-15 16:14:39 UTC (rev 2752)
@@ -55,7 +55,7 @@
     const int new_array_min = new_size + MEMORY_INCREASE_MINIMUM;
 		if (new_array_min > new_array_size) new_array_size = new_array_min;
     genome.Resize(new_array_size);
-		protected_sites.Resize(new_array_size);
+		protected_sites.Resize(new_array_size, false);
     flag_array.Resize(new_array_size);
   }
   
@@ -77,6 +77,7 @@
   // Shift any lines needed...
   for (int i = old_size - 1; i >= pos; i--) {
     genome[i+num_lines] = genome[i];
+		protected_sites[i+num_lines] = protected_sites[i];
     flag_array[i+num_lines] = flag_array[i];
   }
 }
@@ -89,6 +90,7 @@
 {
   SloppyResize(other_memory.active_size);
 
+	protected_sites.SetAll(false);
   // Fill in the new information...
   for (int i = 0; i < active_size; i++) {
     genome[i] = other_memory.genome[i];
@@ -102,6 +104,7 @@
 {
   SloppyResize(other_genome.GetSize());
 
+	protected_sites.SetAll(false);
   // Fill in the new information...
   for (int i = 0; i < active_size; i++) {
     genome[i] = other_genome[i];
@@ -118,6 +121,7 @@
   assert(from < genome.GetSize());
 
   genome[to] = genome[from];
+	protected_sites[to] = protected_sites[from];
   flag_array[to] = flag_array[from];
 }
 
@@ -141,6 +145,7 @@
   // Clean up all of the old memory that might need it...
   for (int i = old_size; i < new_size; i++) {
     genome[i].SetOp(0);
+		protected_sites[i] = false;
     flag_array[i] = 0;
   }
 }
@@ -168,6 +173,7 @@
 
   SloppyInsert(pos, 1);
   genome[pos] = in_inst;
+	protected_sites[pos] = false;
   flag_array[pos] = 0;
 }
 
@@ -179,6 +185,7 @@
   SloppyInsert(pos, in_genome.GetSize());
   for (int i = 0; i < in_genome.GetSize(); i++) {
     genome[i+pos] = in_genome[i];
+		protected_sites[i+pos] = protected_sites[i];
     flag_array[i+pos] = 0;
   }
 }
@@ -189,10 +196,15 @@
   assert(pos >= 0);                       // Removal must be in genome.
   assert(pos + num_insts <= active_size); // Cannot extend past end of genome.
 
-  const int new_size = active_size - num_insts;
+	int new_size = active_size - num_insts;
   for (int i = pos; i < new_size; i++) {
-    genome[i] = genome[i + num_insts];
-    flag_array[i] = flag_array[i + num_insts];
+		if(protected_sites[i]) {
+			new_size++;
+		} else {
+			genome[i] = genome[i + num_insts];
+			protected_sites[i] = protected_sites[i + num_insts];
+			flag_array[i] = flag_array[i + num_insts];
+		}
   }
   SloppyResize(new_size);
 }
@@ -207,7 +219,7 @@
 
   // First, get the size right.
   if (size_change > 0) SloppyInsert(pos, size_change);
-  else if (size_change < 0) Remove(pos, -size_change);
+  else if (size_change < 0) Remove(pos, -size_change);  // BEB TODO: what should happen on an attempt to replace a protected site 
 
   // Now just copy everything over!
   for (int i = 0; i < in_genome.GetSize(); i++) {

Modified: branches/interrupt/source/main/cGenome.cc
===================================================================
--- branches/interrupt/source/main/cGenome.cc	2008-08-15 14:10:16 UTC (rev 2751)
+++ branches/interrupt/source/main/cGenome.cc	2008-08-15 16:14:39 UTC (rev 2752)
@@ -69,10 +69,14 @@
 cGenome::cGenome(cInstruction* begin, cInstruction* end)
 : active_size(0)
 {
+	genome.ResizeClear(0);
+  protected_sites.ResizeClear(0);
   for(cInstruction* i=begin; i!=end; ++i,++active_size) {
     genome.Push(*i);
 		protected_sites.Push(false);
   }
+	// active_size be incremented, right?
+	active_size++;
 }
 
 
@@ -87,6 +91,7 @@
   active_size = other_genome.GetSize();
   genome.ResizeClear(active_size);
 	protected_sites.ResizeClear(active_size);
+	protected_sites.SetAll(false);	
 
   // Now that both code arrays are the same size, copy the other one over.
 

Modified: branches/interrupt/source/main/cGenomeUtil.cc
===================================================================
--- branches/interrupt/source/main/cGenomeUtil.cc	2008-08-15 14:10:16 UTC (rev 2751)
+++ branches/interrupt/source/main/cGenomeUtil.cc	2008-08-15 16:14:39 UTC (rev 2752)
@@ -187,7 +187,7 @@
   const int out_length = end - start;
   cGenome out_genome(out_length);
   for (int i = 0; i < out_length; i++) {
-    out_genome[i] = in_genome[i+start];
+    out_genome.SetInst(i, in_genome[i+start], in_genome.IsProtected(i+start));//false); //BEB TODO: change false
   }
 
   return out_genome;
@@ -207,10 +207,10 @@
 
   cGenome out_genome(out_length);
   for (int i = 0; i < start; i++) {
-    out_genome[i] = in_genome[i];
+    out_genome.SetInst(i, in_genome[i], in_genome.IsProtected(i));
   }
   for (int i = start; i < out_length; i++) {
-    out_genome[i] = in_genome[i+cut_length];
+    out_genome.SetInst(i, in_genome[i+cut_length], in_genome.IsProtected(i+cut_length));
   }
 
   return out_genome;
@@ -225,10 +225,10 @@
 
   cGenome out_genome(out_length);
   for (int i = 0; i < length1; i++) {
-    out_genome[i] = genome1[i];
+    out_genome.SetInst(i, genome1[i], genome1.IsProtected(i));
   }
   for (int i = 0; i < length2; i++) {
-    out_genome[i+length1] = genome2[i];
+    out_genome.SetInst(i+length1, genome2[i], genome2.IsProtected(i));
   }
 
   return out_genome;
@@ -319,7 +319,7 @@
 {
   cGenome genome(length);
   for (int i = 0; i < length; i++) {
-    genome[i] = inst_set.GetRandomInst(ctx);
+    genome.SetInst(i, inst_set.GetRandomInst(ctx), false);
   }
   return genome;
 }
@@ -331,9 +331,9 @@
 	  cInstruction inst = inst_set.GetRandomInst(ctx);
 	  while (inst_set.GetRedundancy(inst)==0)
 		  inst = inst_set.GetRandomInst(ctx);
-    genome[i] = inst;
+    genome.SetInst(i, inst, false);
   }
-  genome[length] = inst_set.GetInst("repro");
+  genome.SetInst(length, inst_set.GetInst("repro"), false);
   return genome;
 }
 
@@ -344,9 +344,9 @@
 	  cInstruction inst = inst_set.GetRandomInst(ctx);
 	  while (inst_set.GetRedundancy(inst)==0)
 		  inst = inst_set.GetRandomInst(ctx);
-    genome[i] = inst;
+    genome.SetInst(i, inst, false);
   }
-  genome[length] = inst_set.GetInst("repro-sex");
+  genome.SetInst(length, inst_set.GetInst("repro-sex"), false);
   return genome;
 }
 




More information about the Avida-cvs mailing list