[Avida-SVN] r1922 - in development: source/cpu source/main support/config

barrick at myxo.css.msu.edu barrick at myxo.css.msu.edu
Thu Aug 9 20:38:13 PDT 2007


Author: barrick
Date: 2007-08-09 23:38:13 -0400 (Thu, 09 Aug 2007)
New Revision: 1922

Modified:
   development/source/cpu/cHardwareBase.cc
   development/source/main/cAvidaConfig.h
   development/source/main/cPopulation.cc
   development/support/config/avida.cfg
Log:
* Slip Mutations
Now in flavors that fill duplications with nop-X, random instructions, and scrambled duplications.

And more options for CompeteOrganisms.



Modified: development/source/cpu/cHardwareBase.cc
===================================================================
--- development/source/cpu/cHardwareBase.cc	2007-08-09 19:55:10 UTC (rev 1921)
+++ development/source/cpu/cHardwareBase.cc	2007-08-10 03:38:13 UTC (rev 1922)
@@ -144,7 +144,7 @@
   
   organism->GetPhenotype().SetDivType(mut_multiplier);
   
-  // @JEB Slip Mutations
+  // @JEB Divide Slip Mutations
   // As if the read head jumped from one random position of the child
   // to another random position and continued reading to the end.
   // This can cause large deletions or tandem duplications.
@@ -153,16 +153,73 @@
   if ( organism->TestDivideSlip(ctx) )
   {
     cGenome child_copy = cGenome(child_genome);
-    int from = ctx.GetRandom().GetInt(child_copy.GetSize());
-    int to = ctx.GetRandom().GetInt(child_copy.GetSize());
+    int from = ctx.GetRandom().GetInt(child_copy.GetSize()+1);
+    int to = ctx.GetRandom().GetInt(child_copy.GetSize()+1);
     
     //Resize child genome
-    child_genome.Resize( child_genome.GetSize() + (from-to) );
-    for (int i=0; i < child_copy.GetSize() - to; i++) 
+    int insertion_length = (from-to);
+    child_genome.Resize( child_genome.GetSize() + insertion_length );
+    
+    //Fill insertion
+    if (insertion_length > 0)
     {
-      child_genome[from+i] = child_copy[to+i];
+      tArray<bool> copied_so_far(insertion_length);
+      copied_so_far.SetAll(false);
+      for (int i=0; i < insertion_length; i++) 
+      {
+        switch (m_world->GetConfig().SLIP_FILL_MODE.Get())
+        {
+          case 0:
+          child_genome[from+i] = child_copy[to+i];
+          break;
+          
+          case 1:        
+          child_genome[from+i] = m_inst_set->GetInst("nop-X");
+          break;
+          
+          case 2:        
+          child_genome[from+i] = m_inst_set->GetRandomInst(ctx);
+          break;
+          
+          //Randomized order of instructions
+          case 3:
+          {
+            int copy_index = m_world->GetRandom().GetInt(insertion_length-i);
+            int test = 0;
+            int passed = copy_index;
+            while (passed >= 0)
+            {
+              if (copied_so_far[test]) 
+              {
+                copy_index++; 
+              }
+              else //this one hasn't been chosen, so we count it.
+              {
+                passed--;
+              }
+              test++;
+            }
+            child_genome[from+i] = child_genome[to+copy_index];
+            copied_so_far[copy_index] = true;
+          }
+          break;
+          
+          default:
+          cout << "Unknown SLIP_FILL_MODE\n";
+          
+          }
+      }
     }
     
+    //Deletion / remaining genome
+    if (insertion_length < 0) insertion_length = 0;
+    for (int i=insertion_length; i < child_copy.GetSize() - to; i++) 
+    {
+        child_genome[from+i] = child_copy[to+i];
+
+    }
+
+    
     if (m_world->GetVerbosity() >= VERBOSE_DETAILS) 
     {
       cout << "SLIP MUTATION from " << from << " to " << to << endl;

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-08-09 19:55:10 UTC (rev 1921)
+++ development/source/main/cAvidaConfig.h	2007-08-10 03:38:13 UTC (rev 1922)
@@ -260,6 +260,7 @@
   CONFIG_ADD_VAR(DIVIDE_INS_PROB, double, 0.05, "Insertion rate (per divide)");
   CONFIG_ADD_VAR(DIVIDE_DEL_PROB, double, 0.05, "Deletion rate (per divide)");
   CONFIG_ADD_VAR(DIVIDE_SLIP_PROB, double, 0.0, "Slip rate (per divide) - creates large deletions/duplications");
+  CONFIG_ADD_VAR(SLIP_FILL_MODE, int, 0, "Fill insertions from slip mutations with 0=duplication, 1=nop-X, 2=random, 3=scrambled");
   CONFIG_ADD_VAR(PARENT_MUT_PROB, double, 0.0, "Per-site, in parent, on divide");
   CONFIG_ADD_VAR(SPECIAL_MUT_LINE, int, -1, "If this is >= 0, ONLY this line is mutated");
   CONFIG_ADD_VAR(INJECT_INS_PROB, double, 0.0, "Insertion rate (per site, applied on inject)");

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-08-09 19:55:10 UTC (rev 1921)
+++ development/source/main/cPopulation.cc	2007-08-10 03:38:13 UTC (rev 1922)
@@ -2995,8 +2995,7 @@
   tArray<double> max_trial_fitnesses(num_trials);
   tArray<double> bonus_sums(num_trials);
   bonus_sums.SetAll(0);
-  double max_bonus_sum = -1;
-
+  
   bool init = false;
   // What is the min and max fitness in each trial
   for (int i = 0; i < num_cells; i++) 
@@ -3069,6 +3068,15 @@
         }
         fitness = exp( (1/trial_fitnesses.GetSize()) * log(fitness) );
         break;
+        
+        //Addition of normalized values
+        case 3:
+        fitness = 0;
+        for (int t=0; t < trial_fitnesses.GetSize(); t++) 
+        { 
+          if (max_trial_fitnesses[t] > 0) fitness+=trial_fitnesses[t] / max_trial_fitnesses[t]; 
+        }
+        break;
                          
         default:
         cout << "Unknown CompeteOrganisms method!" << endl;

Modified: development/support/config/avida.cfg
===================================================================
--- development/support/config/avida.cfg	2007-08-09 19:55:10 UTC (rev 1921)
+++ development/support/config/avida.cfg	2007-08-10 03:38:13 UTC (rev 1922)
@@ -132,6 +132,7 @@
 DIVIDE_INS_PROB 0.05  # Insertion rate (per divide)
 DIVIDE_DEL_PROB 0.05  # Deletion rate (per divide)
 DIVIDE_SLIP_PROB 0.0  # Slip rate (per divide) - creates large deletions/duplications
+SLIP_FILL_MODE 0      # Fill insertions from slip mutations with 0=duplication, 1=nop-X, 2=random, 3=scrambled
 PARENT_MUT_PROB 0.0   # Per-site, in parent, on divide
 SPECIAL_MUT_LINE -1   # If this is >= 0, ONLY this line is mutated
 INJECT_INS_PROB 0.0   # Insertion rate (per site, applied on inject)




More information about the Avida-cvs mailing list