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

avidaedward at myxo.css.msu.edu avidaedward at myxo.css.msu.edu
Sat Jan 27 22:17:14 PST 2007


Author: avidaedward
Date: 2007-01-28 01:17:14 -0500 (Sun, 28 Jan 2007)
New Revision: 1227

Modified:
   extras/
   extras/source/testsuites/nAnalyze.cpp
Log:
 r1244 at clearly:  kaben | 2007-01-21 19:50:01 -0500
 Added test "cAnalyze_Brainstorm_EpochalVsContinuous".



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

Modified: extras/source/testsuites/nAnalyze.cpp
===================================================================
--- extras/source/testsuites/nAnalyze.cpp	2007-01-28 06:17:06 UTC (rev 1226)
+++ extras/source/testsuites/nAnalyze.cpp	2007-01-28 06:17:14 UTC (rev 1227)
@@ -861,6 +861,263 @@
     cAddTestSuite t("cAnalyze_Brainstorm_CumulativeStemminess", test);
   }
 
+  /* cAnalyze_Brainstorm_EpochalVsContinuous {{{2 */
+  namespace Brainstorm_EpochalVsContinuous {
+    struct cAGLData {
+      cAnalyzeGenotype *genotype; //
+      int id; //
+      int pid; //
+      int depth; //
+      int birth; //
+      int ppos; // convenient but redundant.
+      int offspring_count; // convenient but redundant.
+      int branch_dist;
+      int branch_pos;
+
+      cAGLData()
+      : genotype(0)
+      , id(-1)
+      , pid(-1)
+      , depth(-1)
+      , birth(-1)
+      , ppos(-1)
+      , offspring_count(-1)
+      , branch_dist(-1)
+      , branch_pos(-1)
+      {}
+    };
+    void test(){
+      cout << "XXX This is a test stub. It needs filling-in. @kgn" << endl;
+
+      cString data_dir("/Users/kaben/Projects/Software/Avida/svk/avida-devel/work/data");
+
+      /*
+      Initialize
+      */
+      char * argv[] = {
+        "cAnalyze_Brainstorm_EpochalVsContinuous",
+        "-s",
+        "100",
+      };
+      int argc = sizeof(argv)/sizeof(char *);
+
+      cDriverManager::Initialize();
+      cWorld *world = new cWorld(
+        cAvidaConfig::LoadWithCmdLineArgs(argc, argv)
+      );
+      cAvidaDriver* driver = new cDefaultAnalyzeDriver(
+        world,
+        (world->GetConfig().ANALYZE_MODE.Get() == 2)
+      );
+
+      cAnalyze& a = world->GetAnalyze();
+
+      ERROR("kgn at FIXME: hard-coded path to data files - must make configurable -");
+
+      a.Send(cString("SET d ") + data_dir);
+      a.Send("SET_BATCH 0");
+
+      a.Send("PURGE_BATCH");
+      a.Send("LOAD $d/detail-5000.pop");
+      a.Send("LOAD $d/historic-5000.pop");
+
+      //a.Send("PRINT_TREE_STATS");
+      
+      if(true){
+        cAnalyzeGenotype * genotype = NULL;
+        tListIterator<cAnalyzeGenotype> batch_it(a.batch[a.cur_batch].List());
+        const int num_gens = a.batch[a.cur_batch].List().GetSize();
+        cout << "num_gens:" << num_gens << endl;
+
+        // Put all of the genotypes in an array for easy reference and collect
+        // other information on them as we process them.
+        tArray<cAnalyzeGenotype *> gen_array(num_gens);
+        tHashTable<int, int> id_hash;  // Store array pos for each id.
+        tArray<int> id_array(num_gens), pid_array(num_gens);
+        tArray<int> depth_array(num_gens), birth_array(num_gens);
+        int array_pos = 0;
+        while ((genotype = batch_it.Next()) != NULL) {
+          // Put the genotype in an array.
+          gen_array[array_pos] = genotype;
+          id_hash.Add(genotype->GetID(), array_pos);
+          id_array[array_pos] = genotype->GetID();
+          pid_array[array_pos] = genotype->GetParentID();
+          depth_array[array_pos] = genotype->GetDepth();
+          birth_array[array_pos] = genotype->GetUpdateBorn();
+          array_pos++;
+        }
+
+/**/tArray<cAGLData> agl(num_gens);  // Store agl data for each id.
+
+/**/array_pos = 0;
+/**/batch_it.Reset();
+/**/while ((genotype = batch_it.Next()) != NULL) {
+/**/  // Put the genotype in an array.
+/**/  //id_hash.Add(genotype->GetID(), array_pos);
+/**/  agl[array_pos].genotype = genotype;
+/**/  agl[array_pos].id = genotype->GetID();
+/**/  agl[array_pos].pid = genotype->GetParentID();
+/**/  agl[array_pos].depth = genotype->GetDepth();
+/**/  agl[array_pos].birth = genotype->GetUpdateBorn();
+/**/  array_pos++;
+/**/}
+
+/*
+XXX
+Test:
+Verify that each genotype has empty child list and null parent.
+*/
+/**/for (int pos = 0; pos < num_gens; pos++) {
+/* Sanity : non-null genotype. */
+/**/  TEST(agl[pos].genotype);
+/* Verify empty child list. */
+/**/  TEST(0 == agl[pos].genotype->GetChildList().GetSize());
+/* Sanity : non-null genotype. */
+/**/  TEST(0 == agl[pos].genotype->GetParent());
+/**/}
+
+        // Now collect information about the offspring of each individual.
+        tArray<int> ppos_array(num_gens), offspring_count(num_gens);
+        offspring_count.SetAll(0);
+        for (int pos = 0; pos < num_gens; pos++) {
+          int parent_id = gen_array[pos]->GetParentID();
+          if (parent_id == -1) {  // Organism has no parent (i.e., ancestor)
+            ppos_array[pos] = -1;
+            continue;
+          }
+          int parent_pos = -1;
+          id_hash.Find(parent_id, parent_pos);
+          ppos_array[pos] = parent_pos;
+          offspring_count[parent_pos]++;
+        }
+
+        // For each genotype, figure out how far back you need to go to get to a
+        // branch point.
+        tArray<int> branch_dist_array(num_gens);
+        tArray<int> branch_pos_array(num_gens);
+        branch_dist_array.SetAll(-1);
+        branch_pos_array.SetAll(-1);
+        bool found = true;
+        int loop_count = 0;
+        while (found == true) {
+          found = false;
+          for (int pos = 0; pos < num_gens; pos++) {
+            if (branch_dist_array[pos] > -1) continue; // continue if its set.
+            found = true;
+            int parent_pos = ppos_array[pos];
+            if (parent_pos == -1) branch_dist_array[pos] = 0;  // Org is root.
+            else if (offspring_count[parent_pos] > 1) {        // Parent is branch.
+              branch_dist_array[pos] = 1;
+              branch_pos_array[pos] = parent_pos;
+            }
+            else if (branch_dist_array[parent_pos] > -1) {     // Parent calculated.
+              branch_dist_array[pos] = branch_dist_array[parent_pos]+1;
+              branch_pos_array[pos] = branch_pos_array[parent_pos];
+            }
+            // Otherwise, we are not yet ready to calculate this entry.
+          }
+          loop_count++;
+        }
+
+/*
+Link each offspring to its parent.
+*/
+/**/for (int pos = 0; pos < num_gens; pos++) {
+/**/  cAnalyzeGenotype * genotype = gen_array[pos];
+/**/  int parent_id = genotype->GetParentID();
+/**/  if (-1 != parent_id){
+/**/    id_hash.Find(parent_id, agl[pos].ppos);
+/**/    cAnalyzeGenotype * parent_genotype = gen_array[agl[pos].ppos];
+/**/    genotype->LinkParent(parent_genotype);
+/**/  }
+/**/}
+
+/*
+Count offspring of each parent.
+*/
+/**/for (int pos = 0; pos < num_gens; pos++) {
+/**/  cAnalyzeGenotype * genotype = gen_array[pos];
+/**/  agl[pos].offspring_count = genotype->GetChildList().GetSize();
+/**/}
+
+/**/found = true;
+/**/loop_count = 0;
+/**/while (found == true) {
+/**/  found = false;
+/**/  for (int pos = 0; pos < num_gens; pos++) {
+/**/    if (agl[pos].branch_dist > -1) continue; // continue if its set.
+/**/    found = true;
+/**/    int parent_pos = agl[pos].ppos;
+/**/    if (parent_pos == -1)  agl[pos].branch_dist = 0;  // Org is root.
+/**/    else if (agl[parent_pos].offspring_count > 1) {        // Parent is branch.
+/**/      agl[pos].branch_dist = 1;
+/**/      agl[pos].branch_pos = parent_pos;
+/**/    }
+/**/    else if (agl[parent_pos].branch_dist > -1) {     // Parent calculated.
+/**/      agl[pos].branch_dist = agl[parent_pos].branch_dist + 1;
+/**/      agl[pos].branch_pos = agl[parent_pos].branch_pos;
+/**/    }
+/**/    // Otherwise, we are not yet ready to calculate this entry.
+/**/  }
+/**/  loop_count++;
+/**/}
+
+        // Cumulative Stemminess
+        for (int pos = 0; pos < num_gens; pos++) {
+          // We're only interested in internal n-furcating nodes.
+          if (pid_array[pos] == -1) continue;  // Don't want root.
+          if (offspring_count[pos] <= 1) continue; // No leaves or nonfurcating nodes
+
+          // @CAO Find distance to all children.
+          // @CAO Find distance to parent branch.
+          // @CAO DO math.
+        }
+
+
+        //cout << "LOOP COUNT:" << loop_count << endl;
+        //for (int i = 0; i < num_gens; i++) {
+        //  int branch_pos = branch_pos_array[i];
+        //  int branch_id = (branch_pos == -1) ? -1 : id_array[branch_pos];
+        //  cout
+        //    << "i:" << i << ", "
+        //    << "id:" << id_array[i] << ", "
+        //    << "offspring_ct:" << offspring_count[i] << ", "
+        //    << "branch_dist:" << branch_dist_array[i] << ", "
+        //    << "branch_id:" << branch_id << ", "
+        //    << endl;
+        //}
+
+/*
+XXX
+Test:
+Verify agl data matches @cao's reference data.
+*/
+/* Sanity : non-empty genotype array. */
+/**/for (int pos = 0; pos < num_gens; pos++) {
+/**/  TEST(gen_array[pos]->GetChildList().GetSize() == offspring_count[pos]);
+
+/**/  TEST(agl[pos].id == id_array[pos]);
+/**/  TEST(agl[pos].pid == pid_array[pos]);
+/**/  TEST(agl[pos].depth == depth_array[pos]);
+/**/  TEST(agl[pos].birth == birth_array[pos]);
+/**/  TEST(agl[pos].ppos == ppos_array[pos]);
+/**/  TEST(agl[pos].offspring_count == offspring_count[pos]);
+/**/  TEST(agl[pos].branch_dist == branch_dist_array[pos]);
+/**/  TEST(agl[pos].branch_pos == branch_pos_array[pos]);
+/**/}
+
+
+        
+      }
+      TEST(driver); delete driver; driver=0;
+
+      /* Make sure testing is working with successes and failures. @kgn */
+      TEST(true);
+      //TEST(false);
+    }
+    cAddTestSuite t("cAnalyze_Brainstorm_EpochalVsContinuous", test);
+  }
+
 /* Unit tests. {{{1 */
   /* cAnalyze_UnitTest_HelloWorld {{{2 */
   namespace UnitTest_HelloWorld {




More information about the Avida-cvs mailing list