[Avida-SVN] r2172 - in branches/matt/RandomSearch/source: analyze main

matt at myxo.css.msu.edu matt at myxo.css.msu.edu
Thu Nov 1 17:27:17 PDT 2007


Author: matt
Date: 2007-11-01 20:27:17 -0400 (Thu, 01 Nov 2007)
New Revision: 2172

Modified:
   branches/matt/RandomSearch/source/analyze/cAnalyze.cc
   branches/matt/RandomSearch/source/main/cPhenPlastGenotype.cc
   branches/matt/RandomSearch/source/main/cPhenPlastGenotype.h
Log:
Fixed memory leak in cPhenPlastGenotype.

Modified: branches/matt/RandomSearch/source/analyze/cAnalyze.cc
===================================================================
--- branches/matt/RandomSearch/source/analyze/cAnalyze.cc	2007-11-02 00:17:39 UTC (rev 2171)
+++ branches/matt/RandomSearch/source/analyze/cAnalyze.cc	2007-11-02 00:27:17 UTC (rev 2172)
@@ -3739,7 +3739,7 @@
   //Length 100
   //const cString base_genome = "rucavccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccutycasvab";
 
-  int num_trials = 10000000;  // 10 million trials
+  int num_trials = 100000;  // 10 million trials
   int num_tests  = 100;        // Number of random numbers to test
   
   //Stochasticity
@@ -3765,16 +3765,15 @@
   if (!fot2.is_open())
     m_world->GetDriver().RaiseFatalException(2, "Cannot open equ_genomes.dat.");
   
-  
-  cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
-  cCPUTestInfo* test_info = new cCPUTestInfo();
+  cCPUTestInfo* test_info = new cCPUTestInfo;
   for (int n = 0; n < num_trials; n++){
+    
     cString new_genome = base_genome;
     for (int pos = 6; pos < 41; pos++)
       new_genome[pos] = inst_set.GetRandomInst(m_ctx).GetSymbol();
     
     cPhenPlastGenotype ppgenotype(new_genome, num_tests, *test_info, m_world, m_ctx);
-
+    
     //Process our individual phenotypes
     tArray<double> gen_tasks(512,0.0);
     int    num_phens = ppgenotype.GetNumPhenotypes();
@@ -3795,6 +3794,7 @@
       }
     }
     
+    
     //Process our genotype
     if (print_equ_genome)
       fot2 << new_genome << endl;
@@ -3806,6 +3806,7 @@
         int s = static_cast<int>(gen_tasks[t] * 100) / 10;
         num_tasks.ElementAt(t,s)++;
       }
+      
     }
     
     //How many phenotypes were there and how often are they viable?
@@ -3813,9 +3814,8 @@
     int np = (num_phens <= 10) ? num_phens-1 : 10;
     viability.ElementAt(np,s)++;
   }
-  delete test_cpu;
   delete test_info;
-
+  
   //We're done with our EQU genotype file
   fot2.close();
   

Modified: branches/matt/RandomSearch/source/main/cPhenPlastGenotype.cc
===================================================================
--- branches/matt/RandomSearch/source/main/cPhenPlastGenotype.cc	2007-11-02 00:17:39 UTC (rev 2171)
+++ branches/matt/RandomSearch/source/main/cPhenPlastGenotype.cc	2007-11-02 00:27:17 UTC (rev 2172)
@@ -45,10 +45,10 @@
 
 cPhenPlastGenotype::~cPhenPlastGenotype()
 {
-  UniquePhenotypes::iterator it = m_unique.begin();
-  while (it != m_unique.end()){
-    delete static_cast<cPlasticPhenotype*>(*it);
-    ++it;
+  tListIterator<cPlasticPhenotype> ppit(phenplast_pointers);
+  while (ppit.Next()){
+    cPlasticPhenotype* pp = ppit.Get();
+    delete pp;
   }
 }
 
@@ -63,7 +63,8 @@
     UniquePhenotypes::iterator uit = m_unique.find(&test_info.GetTestPhenotype());
     if (uit == m_unique.end()){  // Yes, make a new entry for it
       cPlasticPhenotype* new_phen = new cPlasticPhenotype(test_info, m_num_trials);
-      m_unique.insert( static_cast<cPhenotype*>(new_phen) );
+      phenplast_pointers.Push( new_phen );
+      m_unique.insert( static_cast<cPhenotype*>(new_phen) ); 
     } else{   // No, add an observation to existing entry, make sure it is equivalent
       if (!static_cast<cPlasticPhenotype*>((*uit))->AddObservation(test_info)){
         cerr << "Error with this plastic phenotype. Abort." << endl;

Modified: branches/matt/RandomSearch/source/main/cPhenPlastGenotype.h
===================================================================
--- branches/matt/RandomSearch/source/main/cPhenPlastGenotype.h	2007-11-02 00:17:39 UTC (rev 2171)
+++ branches/matt/RandomSearch/source/main/cPhenPlastGenotype.h	2007-11-02 00:27:17 UTC (rev 2172)
@@ -62,7 +62,8 @@
 {
   private:
 
-  typedef set<cPhenotype*, cPhenotype::lt_phenotype  > UniquePhenotypes;  //Actually, these are cPlatsicPhenotypes*
+    typedef set<cPhenotype*, cPhenotype::lt_phenotype  > UniquePhenotypes;  //Actually, these are cPlatsicPhenotypes*
+    tList<cPlasticPhenotype> phenplast_pointers;
     cGenome m_genome;
     int m_num_trials;  
     UniquePhenotypes m_unique;
@@ -80,7 +81,7 @@
     void Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
 
   public:
-      cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
+    cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
     cPhenPlastGenotype(const cGenome& in_genome, int num_trails, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
     ~cPhenPlastGenotype();
     




More information about the Avida-cvs mailing list