[Avida-SVN] r2979 - in branches/hjg-dev/source: cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Nov 26 17:11:58 PST 2008


Author: hjg
Date: 2008-11-26 20:11:58 -0500 (Wed, 26 Nov 2008)
New Revision: 2979

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cTestCPU.cc
   branches/hjg-dev/source/main/cPhenotype.cc
   branches/hjg-dev/source/main/cPhenotype.h
   branches/hjg-dev/source/main/cPopulation.cc
Log:
modified threshgb and shadedgb to use actual instruction counts obtained from the testcpu

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-26 21:06:15 UTC (rev 2978)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-27 01:11:58 UTC (rev 2979)
@@ -3654,8 +3654,25 @@
   }
 	
 	// Identify how many green beard donations the parent of this organism made
-	int shade_of_gb = phenotype.GetNumShadedGbDonationsLast();
+	//int shade_of_gb = phenotype.GetNumShadedGbDonationsLast();
 	
+	// Identify how many shaded green beard donations this organisms made
+	// First figure out what number instruction donate-shadedgb is
+	cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+	const int num_inst = m_world->GetNumInstructions();
+	int shade_of_gb = 0;
+	int neighbor_shade_of_gb = 0;
+	int inst_number = 0;
+	for (int i = 0; i < num_inst; i++) { 
+		if ((inst_set.GetName(i) == "donate-shadedgb") && 
+			(phenotype.GetTestCPUInstCount().GetSize() > 0)) {
+			shade_of_gb = phenotype.GetTestCPUInstCount()[i];
+			inst_number = i;
+		}
+	}
+		//df.Write(inst_counts[i], inst_set.GetName(i));
+
+	
 	// Update stats.
 	phenotype.IncDonates();
   phenotype.SetIsDonorShadedGb();
@@ -3682,18 +3699,29 @@
   while (neighbor_id < max_id) {
 		neighbor = organism->GetNeighbor();
 		//if neighbor exists, AND if their parent attempted to donate >= shaded of green beard,
-		if (neighbor != NULL && neighbor->GetPhenotype().GetNumShadedGbDonationsLast()>=  shade_of_gb) {
-			const cGenome & neighbor_genome = neighbor->GetGenome();
+		if (neighbor != NULL) {
 			
-			// for each instruction in the genome...
-			for(int i=0;i<neighbor_genome.GetSize();i++){
+			// Get the neighbor's shade
+			neighbor_shade_of_gb = 0; 
+			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) { 
+				neighbor_shade_of_gb = neighbor->GetPhenotype().GetTestCPUInstCount()[inst_number];
+			}
 				
-				// ...see if it is donate-shadedgb, if so, we found a target
-				if (neighbor_genome[i] == IP().GetInst()) {
-					found = true;
-					break;
+				
+			if (neighbor_shade_of_gb >=  shade_of_gb) {
+		//		const cGenome & neighbor_genome = neighbor->GetGenome();
+			
+/*				// for each instruction in the genome...
+				for(int i=0;i<neighbor_genome.GetSize();i++){
+				
+					// ...see if it is donate-shadedgb, if so, we found a target
+					if (neighbor_genome[i] == IP().GetInst()) {
+						found = true;
+						break;
+					}
+				
 				}
-				
+ */
 			}
 		}
 		
@@ -3759,8 +3787,9 @@
       neighbor = organism->GetNeighbor();
       //if neighbor exists, AND if their parent attempted to donate,
       if (neighbor != NULL && neighbor->GetPhenotype().IsDonorTrueGbLast()) {
-          const cGenome & neighbor_genome = neighbor->GetGenome();
+   //       const cGenome & neighbor_genome = neighbor->GetGenome();
 
+				/*
           // for each instruction in the genome...
           for(int i=0;i<neighbor_genome.GetSize();i++){
 
@@ -3771,6 +3800,7 @@
             }
 	    
           }
+				 */
       }
       
       // stop searching through the neighbors if we already found one
@@ -3815,6 +3845,20 @@
   phenotype.IncDonates();
   phenotype.SetIsDonorThreshGb();
   phenotype.IncNumThreshGbDonations();
+	
+	
+	// Identify how many thresh green beard donations this organisms made
+	// First figure out what number instruction donate-threshgb is	
+	cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+	const int num_inst = m_world->GetNumInstructions();
+	int neighbor_thresh_of_gb = 0;
+	int inst_number = 0;
+	for (int i = 0; i < num_inst; i++) { 
+		if ((inst_set.GetName(i) == "donate-threshgb") && 
+				(phenotype.GetTestCPUInstCount().GetSize() > 0)) {
+			inst_number = i;
+		}
+	}
 
   // Find the target as the first match found in the neighborhood.
 
@@ -3835,7 +3879,15 @@
   while (neighbor_id < max_id) {
       neighbor = organism->GetNeighbor();
       //if neighbor exists, AND if their parent attempted to donate >= threshhold,
-      if (neighbor != NULL && neighbor->GetPhenotype().GetNumThreshGbDonationsLast()>= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
+		if (neighbor != NULL) {
+			
+			// Get neighbor threshold
+			neighbor_thresh_of_gb = 0; 
+			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) { 
+				neighbor_thresh_of_gb = neighbor->GetPhenotype().GetTestCPUInstCount()[inst_number];
+			}
+			
+				if (neighbor_thresh_of_gb >= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
           const cGenome & neighbor_genome = neighbor->GetGenome();
 
           // for each instruction in the genome...
@@ -3848,6 +3900,7 @@
             }
 	    
           }
+				}
       }
       
       // stop searching through the neighbors if we already found one

Modified: branches/hjg-dev/source/cpu/cTestCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cTestCPU.cc	2008-11-26 21:06:15 UTC (rev 2978)
+++ branches/hjg-dev/source/cpu/cTestCPU.cc	2008-11-27 01:11:58 UTC (rev 2979)
@@ -257,11 +257,13 @@
       }
       *tracerStream << endl;
      }
-     
+		
+		
      organism.GetHardware().SingleProcess(ctx);
+
   }
   
-  
+
   // Output final resource information @JEB
   if ( (m_res_method >= RES_UPDATED_DEPLETABLE) && (tracerStream != NULL) ) 
   {
@@ -276,12 +278,12 @@
     *tracerStream << endl;
    }
 
-  
+	  
   organism.GetHardware().SetTrace(NULL);
 
   // Print out some final info in trace...
   if (tracer != NULL) tracer->TraceTestCPU(time_used, time_allocated, organism);
-
+	
   // For now, always return true.
   return true;
 }
@@ -381,7 +383,7 @@
 
   // Case 1:  ////////////////////////////////////
   if (organism->GetPhenotype().GetNumDivides() == 0)  return false;
-
+	
   // Case 2:  ////////////////////////////////////
   if (organism->GetPhenotype().CopyTrue() == true) {
     test_info.depth_found = cur_depth;

Modified: branches/hjg-dev/source/main/cPhenotype.cc
===================================================================
--- branches/hjg-dev/source/main/cPhenotype.cc	2008-11-26 21:06:15 UTC (rev 2978)
+++ branches/hjg-dev/source/main/cPhenotype.cc	2008-11-27 01:11:58 UTC (rev 2979)
@@ -109,7 +109,7 @@
   cur_task_value           = in_phen.cur_task_value;			 
   cur_reaction_count       = in_phen.cur_reaction_count;            
   cur_reaction_add_reward  = in_phen.cur_reaction_add_reward;     
-  cur_inst_count           = in_phen.cur_inst_count;                 
+  cur_inst_count           = in_phen.cur_inst_count;                 	
   cur_sense_count          = in_phen.cur_sense_count;                 
   sensed_resources         = in_phen.sensed_resources;            
   cur_task_time            = in_phen.cur_task_time;   
@@ -152,6 +152,7 @@
   fault_desc               = in_phen.fault_desc;    
   neutral_metric           = in_phen.neutral_metric; 
   life_fitness             = in_phen.life_fitness; 	
+	testCPU_inst_count       = in_phen.testCPU_inst_count;
                         
   
   // 5. Status Flags...  (updated at each divide)

Modified: branches/hjg-dev/source/main/cPhenotype.h
===================================================================
--- branches/hjg-dev/source/main/cPhenotype.h	2008-11-26 21:06:15 UTC (rev 2978)
+++ branches/hjg-dev/source/main/cPhenotype.h	2008-11-27 01:11:58 UTC (rev 2979)
@@ -156,8 +156,10 @@
   cString fault_desc;    // A description of the most recent error.
   double neutral_metric; // Undergoes drift (gausian 0,1) per generation
   double life_fitness; 	 // Organism fitness during its lifetime, 
-		         // calculated based on merit just before the divide
+		         // calculated based on merit just before the divide	
+	tArray<int> testCPU_inst_count;	  // Instruction exection counter as calculated by Test CPU
 
+
   // 5. Status Flags...  (updated at each divide)
   bool to_die;		 // Has organism has triggered something fatal?
   bool to_delete;        // Should this organism be deleted when finished?
@@ -314,6 +316,8 @@
   const tArray<int>& GetCurInstCount() const { assert(initialized == true); return cur_inst_count; }
   const tArray<int>& GetCurSenseCount() const { assert(initialized == true); return cur_sense_count; }
   double GetSensedResource(int _in) { assert(initialized == true); return sensed_resources[_in]; }
+	const tArray<int>& GetTestCPUInstCount() const { assert(initialized == true); return testCPU_inst_count; }
+
   
   void  NewTrial(); //Save the current fitness, and reset the bonus. @JEB
   void  TrialDivideReset(const cGenome & _genome); //Subset of resets specific to division not done by NewTrial. @JEB
@@ -428,6 +432,7 @@
   void SetToDie() { to_die = true; }
   void SetToDelete() { to_delete = true; }
   void SetLastInstCount(const tArray<int>& in_counts) { last_inst_count = in_counts; }
+  void SetTestCPUInstCount(const tArray<int>& in_counts) { testCPU_inst_count = in_counts; }
 
   void SetIsDonorCur() { is_donor_cur = true; } 
   void SetIsDonorRand() { SetIsDonorCur(); is_donor_rand = true; }

Modified: branches/hjg-dev/source/main/cPopulation.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulation.cc	2008-11-26 21:06:15 UTC (rev 2978)
+++ branches/hjg-dev/source/main/cPopulation.cc	2008-11-27 01:11:58 UTC (rev 2979)
@@ -375,7 +375,7 @@
           parent_phenotype.SetGestationTime(test_info.GetTestPhenotype().GetGestationTime());
         }
         if (pc_phenotype & 4) {   // If we must update the last instruction counts
-          parent_phenotype.SetLastInstCount(test_info.GetTestPhenotype().GetLastInstCount());
+          parent_phenotype.SetTestCPUInstCount(test_info.GetTestPhenotype().GetCurInstCount());
         }
         parent_phenotype.SetFitness(parent_phenotype.GetMerit().CalcFitness(parent_phenotype.GetGestationTime())); //Update fitness
         delete test_cpu;
@@ -508,7 +508,7 @@
     if (pc_phenotype & 2)
       in_organism->GetPhenotype().SetGestationTime(test_info.GetTestPhenotype().GetGestationTime());
     if (pc_phenotype & 4) {   // If we must update the last instruction counts
-      in_organism->GetPhenotype().SetLastInstCount(test_info.GetTestPhenotype().GetLastInstCount());
+      in_organism->GetPhenotype().SetTestCPUInstCount(test_info.GetTestPhenotype().GetLastInstCount());
     }
     in_organism->GetPhenotype().SetFitness(in_organism->GetPhenotype().GetMerit().CalcFitness(in_organism->GetPhenotype().GetGestationTime()));
     delete test_cpu;




More information about the Avida-cvs mailing list