[Avida-SVN] r1237 - in extras: . source/testsuites

avidaedward at myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Sat Jan 27 22:18:24 PST 2007


Author: avidaedward
Date: 2007-01-28 01:18:24 -0500 (Sun, 28 Jan 2007)
New Revision: 1237

Modified:
   extras/
   extras/source/testsuites/nAnalyze.cpp
Log:
 r1262 at clearly:  kaben | 2007-01-27 23:55:28 -0500
 Removed mocked-up version of COMPETE command from test
 cAnalyze_Brainstorm_SynchronousVsContinuous.



Property changes on: extras
___________________________________________________________________
Name: svk:merge
   - 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1260
   + 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1262

Modified: extras/source/testsuites/nAnalyze.cpp
===================================================================
--- extras/source/testsuites/nAnalyze.cpp	2007-01-28 06:18:16 UTC (rev 1236)
+++ extras/source/testsuites/nAnalyze.cpp	2007-01-28 06:18:24 UTC (rev 1237)
@@ -896,159 +896,6 @@
 
   /* cAnalyze_Brainstorm_SynchronousVsContinuous {{{2 */
   namespace Brainstorm_SynchronousVsContinuous {
-    /* COMPETE : brainstorm of new Analyze command. */
-    void Compete(cAnalyze &a, cString cur_string)
-    {
-      if (cur_string.GetSize() == 0) {
-        cerr << "Compete Error: Must include target batch size!" << endl;
-        if (a.exit_on_error) exit(1);
-      }
-      int batch_size = cur_string.PopWord().AsInt();
-      
-      if (cur_string.GetSize() == 0) {
-        cerr << "Compete Error: Must include from ID!" << endl;
-        if (a.exit_on_error) exit(1);
-      }
-      int batch_from = cur_string.PopWord().AsInt();
-      
-      int batch_to = a.cur_batch;
-      if (cur_string.GetSize() > 0) batch_to = cur_string.PopWord().AsInt();
-      
-      if (a.m_world->GetVerbosity() >= VERBOSE_ON) {
-        cout << "Compete from batch " << batch_from << " to batch " << batch_to << "." << endl;
-      }
-    
-      if(true){
-        /* Arguments to COMPETE: */
-        /*
-          batch_size
-          from_id
-          to_id=current
-        */
-        /* Get iterator into "from" batch. */ 
-        tListIterator<cAnalyzeGenotype> batch_it(a.batch[batch_from].List());
-        /* Get size of "from" batch. */
-        const int parent_batch_size = a.batch[batch_from].List().GetSize();
-
-        /* Create scheduler. */
-        cSchedule* schedule = new cProbSchedule(
-          parent_batch_size,
-          a.m_world->GetRandom().GetInt(0x7FFFFFFF)
-        );
-
-        /* Initialize scheduler with fitness values per-organism. */
-        tArray<cAnalyzeGenotype *> genotype_array(parent_batch_size);
-        tArray<cCPUMemory> offspring_genome_array(parent_batch_size);
-        tArray<cMerit> fitness_array(parent_batch_size);
-        cAnalyzeGenotype * genotype = NULL;
-
-        cTestCPU *testcpu = a.m_world->GetHardwareManager().CreateTestCPU();
-        TEST(0 != testcpu);
-
-        cCPUTestInfo *test_info = new cCPUTestInfo();
-        TEST(0 != test_info);
-
-        test_info->UseRandomInputs(false); 
-    
-        int array_pos = 0;
-        while ((genotype = batch_it.Next()) != NULL) {
-          //cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
-          //batch[batch_to].List().PushRear(new_genotype);
-          genotype_array[array_pos] = genotype;
-          genotype->Recalculate(a.m_world->GetDefaultContext(), testcpu, NULL, test_info);
-          if(genotype->GetViable()){
-            /*
-            kgn at XXX FIXME HACK
-            multiplication by 1000 because merits less than 1 are truncated to zero.
-            */
-            fitness_array[array_pos] = genotype->GetFitness() * 1000.;
-            offspring_genome_array[array_pos] = test_info->GetTestOrganism(0)->ChildGenome();
-          } else {
-            fitness_array[array_pos] = 0.0;
-            //offspring_genome_array[array_pos].Reset(0);
-          }
-          schedule->Adjust(array_pos, fitness_array[array_pos]);
-          array_pos++;
-        }
-
-
-        /* Use scheduler to sample organisms in "from" batch. */
-        for(int i=0; i<batch_size; /* don't increment i yet */){
-          /* Sample an organism. */
-          array_pos = schedule->GetNextID();
-          if(array_pos < 0){
-            cout << "Warning: No organisms in origin batch have positive fitness, cannot sample to destination batch." << endl; 
-            break;
-          }
-          genotype = genotype_array[array_pos];
-          /* If not viable, discard and continue. */
-          if(!genotype->GetViable()){
-            ERROR("scheduler sampled a non-viable organism!");
-            continue;
-          }
-
-          /*
-          Replication brainstorm :
-          - Try exact replicationm, without mutation or crossover.
-          - Now split-out a genome, such that it can be altered, and use
-            that genome (unaltered) for replication.
-          - Alter said genome in a controlled way.
-          - Mutations: Copy Mutation, Divide Insertion, Divide Deletion
-          */
-          if(true){
-            double copy_mut_prob = a.m_world->GetConfig().COPY_MUT_PROB.Get();
-            double ins_mut_prob = a.m_world->GetConfig().DIVIDE_INS_PROB.Get();
-            double del_mut_prob = a.m_world->GetConfig().DIVIDE_DEL_PROB.Get();
-            int ins_line = -1;
-            int del_line = -1;
-
-            cCPUMemory child_genome = offspring_genome_array[array_pos];
-
-            if (copy_mut_prob > 0.0) {
-              for (int n = 0; n < child_genome.GetSize(); n++) {
-                if (a.m_world->GetRandom().P(copy_mut_prob)) {
-                  child_genome[n] = a.inst_set.GetRandomInst(a.m_ctx);
-                }
-              }
-            }
-            
-            /* Perform an Insertion if it has one. */
-            if (a.m_world->GetRandom().P(ins_mut_prob)) {
-              ins_line = a.m_world->GetRandom().GetInt(child_genome.GetSize() + 1);
-              child_genome.Insert(ins_line, a.inst_set.GetRandomInst(a.m_ctx));
-            }
-            
-            /* Perform a Deletion if it has one. */
-            if (a.m_world->GetRandom().P(del_mut_prob)) {
-              del_line = a.m_world->GetRandom().GetInt(child_genome.GetSize());
-              child_genome.Remove(del_line);
-            }
-
-            /* Create (possibly mutated) offspring. */
-            cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(
-              a.m_world,
-              child_genome,
-              a.inst_set
-            );
-            /* Place offspring in "to" batch. */
-            a.batch[batch_to].List().PushRear(new_genotype);
-          }
-
-          a.batch[batch_to].SetLineage(false);
-          a.batch[batch_to].SetAligned(false);
-
-          /* Increment and continue. */
-          i++;
-        }
-
-        if(test_info){ delete test_info; test_info = 0; }
-        if(testcpu){ delete testcpu; testcpu = 0; }
-        if(schedule){ delete schedule; schedule = 0; }
-      }
-
-      return;
-    }
-
     void test(cTestSettings &settings){
       /* Check settings. {{{3 */
       if(
@@ -1167,7 +1014,7 @@
         a.Send("DETAIL archive_0/detail.dat id parent_id num_cpus fitness viable length sequence");
 
         /* 'num_gens' synchronous generations. {{{4 */
-        int num_gens = 60;
+        int num_gens = 100;
         for(int g=0; g<num_gens; g++){
           /* Mock-up of arguments to COMPETE command. {{{5 */
           int world_x = world->GetConfig().WORLD_X.Get();
@@ -1178,6 +1025,18 @@
           int batch_to = g + 1;
 
           {
+            s = "SET s ";
+            s += cStringUtil::Convert(batch_size);
+          }
+          a.Send(s);
+
+          {
+            s = "SET f ";
+            s += cStringUtil::Convert(batch_from);
+          }
+          a.Send(s);
+
+          {
             s = "SET t ";
             s += cStringUtil::Convert(batch_to);
           }
@@ -1186,24 +1045,14 @@
           a.Send("SET_BATCH $t");
           a.Send("PURGE_BATCH");
 
-          /* Arguments to COMPETE: */
-          /*
-            batch_size
-            from_id
-            to_id=current
-          */
-          cString arguments("");
-          arguments += cStringUtil::Convert(batch_size);
-          arguments += " ";
-          arguments += cStringUtil::Convert(batch_from);
-          arguments += " ";
-          arguments += cStringUtil::Convert(batch_to);
+          a.Send("COMPETE $s $f $t");
 
-          Compete(a, arguments);
-
           a.Send("SET_BATCH $t");
           a.Send("RECALCULATE");
           a.Send("DETAIL archive_$t/detail.dat id parent_id num_cpus fitness viable length sequence");
+
+          a.Send("SET_BATCH $f");
+          a.Send("PURGE_BATCH");
         }
 
         delete driver; driver=0;




More information about the Avida-cvs mailing list