[Avida-SVN] r2235 - / development/source/analyze extras/source/testsuites

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Wed Dec 19 12:54:40 PST 2007


Author: kaben
Date: 2007-12-19 15:54:40 -0500 (Wed, 19 Dec 2007)
New Revision: 2235

Modified:
   /
   development/source/analyze/cAnalyzeTreeStats_Gamma.cc
   development/source/analyze/cAnalyzeTreeStats_Gamma.h
   extras/source/testsuites/nTreeStats.cpp
Log:
 r2283 at vallista:  kaben | 2007-12-19 12:58:07 -0800
 Switched from heapsort to quicksort, because heapsort isn't in stdlib on alice or rodan. Weird.
 
 r2284 at vallista:  kaben | 2007-12-19 12:58:27 -0800
 Switched from heapsort to quicksort, because heapsort isn't in stdlib on alice or rodan. Weird.
 



Property changes on: 
___________________________________________________________________
Name: svk:merge
   - 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/xcode-test:1653
c457ea80-0a68-11dc-9323-a45eea2efad5:/private:2272
   + 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/xcode-test:1653
c457ea80-0a68-11dc-9323-a45eea2efad5:/private:2284

Modified: development/source/analyze/cAnalyzeTreeStats_Gamma.cc
===================================================================
--- development/source/analyze/cAnalyzeTreeStats_Gamma.cc	2007-12-19 20:29:24 UTC (rev 2234)
+++ development/source/analyze/cAnalyzeTreeStats_Gamma.cc	2007-12-19 20:54:40 UTC (rev 2235)
@@ -53,8 +53,8 @@
     array_pos++;
   }
 }
-int cAnalyzeTreeStats_Gamma::HeapSortGenotypes(void){
-  return HeapSortAGPhyloDepth(m_gen_array);
+void cAnalyzeTreeStats_Gamma::QSortGenotypes(void){
+  QSortAGPhyloDepth(m_gen_array);
 }
 void cAnalyzeTreeStats_Gamma::CalculateInternodeDistances(void){
   m_g.Resize(1 + m_gen_array.GetSize());
@@ -118,14 +118,14 @@
 
 void cAnalyzeTreeStats_Gamma::AnalyzeBatch(tList<cAnalyzeGenotype> &genotype_list){
   LoadGenotypes(genotype_list);
-  HeapSortGenotypes();
+  QSortGenotypes();
   CalculateInternodeDistances();
   CalculateGamma();
 }
 
 
 
-// Comparison functions for heapsort.
+// Comparison functions for qsort.
 int CompareAGPhyloDepth(const void * _a, const void * _b){
   cAnalyzeGenotype a(**((cAnalyzeGenotype**)_a));
   cAnalyzeGenotype b(**((cAnalyzeGenotype**)_b));
@@ -141,8 +141,8 @@
   return 0;
 }
 
-// Heapsort functions.
-int HeapSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array){
+// Quicksort functions.
+void QSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array){
   const int size = gen_array.GetSize();
   cAnalyzeGenotype *c_gen_array[size];
   
@@ -151,18 +151,15 @@
     c_gen_array[i] = (gen_array[i]);
   }
   
-  /* Heapsort c_gen_array. */
-  int result = heapsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGPhyloDepth);
+  /* Quicksort c_gen_array. */
+  qsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGPhyloDepth);
   
-  /* If heapsort returned successfully, copy sorted array from c_gen_array into gen_array. */
-  if(result == 0){
-    for(int i = 0; i < size; i++){
-      gen_array[i] = (c_gen_array[i]);
-    }
+  /* If qsort returned successfully, copy sorted array from c_gen_array into gen_array. */
+  for(int i = 0; i < size; i++){
+    gen_array[i] = (c_gen_array[i]);
   }
-  return result;
 }  
-int HeapSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array){
+void QSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array){
   const int size = gen_array.GetSize();
   cAnalyzeGenotype *c_gen_array[size];
   
@@ -171,14 +168,11 @@
     c_gen_array[i] = (gen_array[i]);
   }
   
-  /* Heapsort c_gen_array. */
-  int result = heapsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGUpdateBorn);
+  /* Quicksort c_gen_array. */
+  qsort(c_gen_array, size, sizeof(cAnalyzeGenotype*), CompareAGUpdateBorn);
   
-  /* If heapsort returned successfully, copy sorted array from c_gen_array into gen_array. */
-  if(result == 0){
-    for(int i = 0; i < size; i++){
-      gen_array[i] = (c_gen_array[i]);
-    }
+  /* If qsort returned successfully, copy sorted array from c_gen_array into gen_array. */
+  for(int i = 0; i < size; i++){
+    gen_array[i] = (c_gen_array[i]);
   }
-  return result;
 }  

Modified: development/source/analyze/cAnalyzeTreeStats_Gamma.h
===================================================================
--- development/source/analyze/cAnalyzeTreeStats_Gamma.h	2007-12-19 20:29:24 UTC (rev 2234)
+++ development/source/analyze/cAnalyzeTreeStats_Gamma.h	2007-12-19 20:54:40 UTC (rev 2235)
@@ -44,7 +44,7 @@
   cAnalyzeTreeStats_Gamma(cWorld* world);
   
   void LoadGenotypes(tList<cAnalyzeGenotype> &genotype_list);
-  int HeapSortGenotypes(void);
+  void QSortGenotypes(void);
   void CalculateInternodeDistances(void);
   void FixupInternodeDistances(void);
   void CalculateGamma(void);
@@ -55,11 +55,11 @@
   void AnalyzeBatch(tList<cAnalyzeGenotype> &genotype_list);
 };
 
-// Comparison functions for heapsort.
+// Comparison functions for qsort.
 int CompareAGPhyloDepth(const void * _a, const void * _b);
 int CompareAGUpdateBorn(const void * _a, const void * _b);
-// Heapsort functions.
-int HeapSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array);
-int HeapSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array);
+// Quicksort functions.
+void QSortAGPhyloDepth(tArray<cAnalyzeGenotype *> &gen_array);
+void QSortAGUpdateBorn(tArray<cAnalyzeGenotype *> &gen_array);
 
 #endif

Modified: extras/source/testsuites/nTreeStats.cpp
===================================================================
--- extras/source/testsuites/nTreeStats.cpp	2007-12-19 20:29:24 UTC (rev 2234)
+++ extras/source/testsuites/nTreeStats.cpp	2007-12-19 20:54:40 UTC (rev 2235)
@@ -417,7 +417,7 @@
     analyze_cfg_file.close();
   }
   /* Generate fake data files containing hand-crafted tree. */
-  void GenerateGammaDetail(const cString &detail_fake_filename) {
+  void GenerateGammaDetail_PhyloDepth(const cString &detail_fake_filename) {
     std::ofstream detail_file(detail_fake_filename);
     detail_file << "#filetype genotype_data" << endl;
     detail_file << "#format id parent_id depth" << endl;
@@ -439,6 +439,28 @@
     detail_file << "# Tests for GabeYedidGammaStatistic." << endl;
     detail_file.close();
   }  
+  void GenerateGammaDetail_UpdateBorn(const cString &detail_fake_filename) {
+    std::ofstream detail_file(detail_fake_filename);
+    detail_file << "#filetype genotype_data" << endl;
+    detail_file << "#format id parent_id update_born" << endl;
+    detail_file << "" << endl;
+    detail_file << "#  1: ID" << endl;
+    detail_file << "#  2: parent ID" << endl;
+    detail_file << "#  3: update born" << endl;
+    detail_file << "" << endl;
+    detail_file << "100 -1 32 #" << endl;
+    detail_file << "150 -1 32 #" << endl;
+    detail_file << "600 500 600 #" << endl;
+    detail_file << "200 100 300 #" << endl;
+    detail_file << "500 300 585 #" << endl;
+    detail_file << "700 500 600 #" << endl;
+    detail_file << "300 100 471 #" << endl;
+    detail_file << "400 100 520 #" << endl;
+    detail_file << "450 200 520 #" << endl;
+    detail_file << "# This file was autogenerated to test Avida." << endl;
+    detail_file << "# Tests for GabeYedidGammaStatistic." << endl;
+    detail_file.close();
+  }  
 }
 
 /* Unit tests. */
@@ -448,7 +470,7 @@
     cString analyze_cfg_filename("./cAnalyze_Brainstorm_GabeYedidGammaStatistic_analyze.cfg");    
     cString detail_fake_filename("./detail-fake.pop");
     nTreeStats::GenerateStandardCfgs(avida_cfg_filename, analyze_cfg_filename);
-    nTreeStats::GenerateGammaDetail(detail_fake_filename);
+    nTreeStats::GenerateGammaDetail_PhyloDepth(detail_fake_filename);
     
     cAnalyzeTestFixture atf;
     /* Set Avida command-line args. */
@@ -521,12 +543,7 @@
     }
     
     /* Sort gen_array by phylogenetic depth. */
-    {
-      int result = agts.HeapSortGenotypes();
-      if(true) {
-        TEST(result == 0);
-      }
-    }
+    agts.QSortGenotypes();
     /* TESTS: Verify final order of loaded genotypes. */
     if(true) {
       TEST(agts.m_gen_array[0]->GetDepth() == 32);
@@ -609,7 +626,7 @@
 /* Functional tests. */
 namespace cAnalyze_FunctionalTest_GabeYedidGammaStatistic_Demo1 {
   /* Generate fake data files containing hand-crafted tree. */
-  void GenerateGammaDetail_Demo1(const cString &detail_fake_filename) {
+  void GenerateGammaDetail_PhyloDepth_Demo1(const cString &detail_fake_filename) {
     std::ofstream detail_file(detail_fake_filename);
     detail_file << "#filetype genotype_data" << endl;
     detail_file << "#format id parent_id depth" << endl;
@@ -633,7 +650,7 @@
     cString analyze_cfg_filename("./cAnalyze_Brainstorm_GabeYedidGammaStatistic_analyze.cfg");    
     cString detail_fake_filename("./detail-fake.pop");
     nTreeStats::GenerateStandardCfgs(avida_cfg_filename, analyze_cfg_filename);
-    GenerateGammaDetail_Demo1(detail_fake_filename);
+    GenerateGammaDetail_PhyloDepth_Demo1(detail_fake_filename);
     
     cAnalyzeTestFixture atf;
     /* Set Avida command-line args. */
@@ -699,7 +716,7 @@
 }
 namespace cAnalyze_FunctionalTest_GabeYedidGammaStatistic_Demo2 {
   /* Generate fake data files containing hand-crafted tree. */
-  void GenerateGammaDetail_Demo1(const cString &detail_fake_filename) {
+  void GenerateGammaDetail_PhyloDepth_Demo1(const cString &detail_fake_filename) {
     std::ofstream detail_file(detail_fake_filename);
     detail_file << "#filetype genotype_data" << endl;
     detail_file << "#format id parent_id depth" << endl;
@@ -723,7 +740,7 @@
     cString analyze_cfg_filename("./cAnalyze_Brainstorm_GabeYedidGammaStatistic_analyze.cfg");    
     cString detail_fake_filename("./detail-fake.pop");
     nTreeStats::GenerateStandardCfgs(avida_cfg_filename, analyze_cfg_filename);
-    GenerateGammaDetail_Demo1(detail_fake_filename);
+    GenerateGammaDetail_PhyloDepth_Demo1(detail_fake_filename);
     
     cAnalyzeTestFixture atf;
     /* Set Avida command-line args. */




More information about the Avida-cvs mailing list