[Avida-SVN] r1622 - in branches/collect: source/cpu source/main tests

blwalker at myxo.css.msu.edu blwalker at myxo.css.msu.edu
Tue May 29 10:52:27 PDT 2007


Author: blwalker
Date: 2007-05-29 13:52:26 -0400 (Tue, 29 May 2007)
New Revision: 1622

Added:
   branches/collect/tests/avida_GA_lim_res/
Modified:
   branches/collect/source/cpu/cHardwareCPU.cc
   branches/collect/source/cpu/cHardwareCPU.h
   branches/collect/source/cpu/cHardwareGX.cc
   branches/collect/source/cpu/cHardwareGX.h
   branches/collect/source/main/cAvidaConfig.h
   branches/collect/source/main/cPhenotype.cc
   branches/collect/source/main/cPhenotype.h
   branches/collect/source/main/cPopulation.cc
   branches/collect/source/main/cPopulation.h
Log:

Porting r1589:1593 from development to catch previously unported changes before r1594.


Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/cpu/cHardwareCPU.cc	2007-05-29 17:52:26 UTC (rev 1622)
@@ -206,6 +206,10 @@
     tInstLibEntry<tMethod>("donate-rnd", &cHardwareCPU::Inst_DonateRandom),
     tInstLibEntry<tMethod>("donate-kin", &cHardwareCPU::Inst_DonateKin),
     tInstLibEntry<tMethod>("donate-edt", &cHardwareCPU::Inst_DonateEditDist),
+    tInstLibEntry<tMethod>("donate-gbg",  &cHardwareCPU::Inst_DonateGreenBeardGene),
+    tInstLibEntry<tMethod>("donate-tgb",  &cHardwareCPU::Inst_DonateTrueGreenBeard),
+    tInstLibEntry<tMethod>("donate-threshgb",  &cHardwareCPU::Inst_DonateThreshGreenBeard),
+    tInstLibEntry<tMethod>("donate-quantagb",  &cHardwareCPU::Inst_DonateQuantaThreshGreenBeard),
     tInstLibEntry<tMethod>("donate-NUL", &cHardwareCPU::Inst_DonateNULL),
 
 	tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1),
@@ -3146,14 +3150,14 @@
 void cHardwareCPU::DoDonate(cOrganism* to_org)
 {
   assert(to_org != NULL);
-  
-  const double merit_given = m_world->GetConfig().DONATE_SIZE.Get();
-  const double merit_received =
-    merit_given * m_world->GetConfig().DONATE_MULT.Get();
-  
+
+  const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
+  const double merit_received = m_world->GetConfig().MERIT_RECEIVED.Get();
+
   double cur_merit = organism->GetPhenotype().GetMerit().GetDouble();
-  cur_merit -= merit_given; 
-  
+  cur_merit -= merit_given;
+  if(cur_merit < 0) cur_merit=0; 
+
   // Plug the current merit back into this organism and notify the scheduler.
   organism->UpdateMerit(cur_merit);
   
@@ -3165,11 +3169,14 @@
 
 bool cHardwareCPU::Inst_DonateRandom(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
+  
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-  
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorRand();
+
   // Turn to a random neighbor, get it, and turn back...
   int neighbor_id = ctx.GetRandom().GetInt(organism->GetNeighborhoodSize());
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
@@ -3177,19 +3184,35 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a neighbor.
-  if (neighbor != NULL) DoDonate(neighbor);
-  
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    
+    //print out how often random donations go to kin
+    /*
+    static ofstream kinDistanceFile("kinDistance.dat");
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=1) << " ";
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=2) << " ";
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=3) << " ";
+    kinDistanceFile << genotype->GetPhyloDistance(neighbor->GetGenotype());
+    kinDistanceFile << endl; 
+    */
+    neighbor->GetPhenotype().SetIsReceiverRand();
+  }
+
   return true;
 }
 
 
 bool cHardwareCPU::Inst_DonateKin(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
   
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorKin();
+
+
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = organism->GetNeighborhoodSize();
   
@@ -3221,17 +3244,21 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a close enough relative...
-  if (neighbor != NULL)  DoDonate(neighbor);
-  
+  if (neighbor != NULL){
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverKin();
+  }
   return true;
 }
 
 bool cHardwareCPU::Inst_DonateEditDist(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorEdit();
   
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = organism->GetNeighborhoodSize();
@@ -3267,23 +3294,350 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a close enough relative...
-  if (neighbor != NULL)  DoDonate(neighbor);
+  if (neighbor != NULL){
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverEdit();
+  }
+  return true;
+}
+
+bool cHardwareCPU::Inst_DonateGreenBeardGene(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome (see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorGbg();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      neighbor = organism->GetNeighbor();
+
+      //if neighbor exists, do they have the green beard gene?
+      if (neighbor != NULL) {
+          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-gbg
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
   
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverGbg();
+  }
+  
   return true;
+  
 }
 
+bool cHardwareCPU::Inst_DonateTrueGreenBeard(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome AND their parents excuted it
+  //(see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
 
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorTrueGb();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      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();
+
+          // for each instruction in the genome...
+          for(int i=0;i<neighbor_genome.GetSize();i++){
+
+            // ...see if it is donate-tgb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverTrueGb();
+  }
+
+  
+  return true;
+  
+}
+
+bool cHardwareCPU::Inst_DonateThreshGreenBeard(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome AND their parents excuted it >=THRESHOLD number of times
+  //(see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorThreshGb();
+  phenotype.IncNumThreshGbDonations();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  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() ) {
+          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-threshgb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverThreshGb();
+    // cout << "************ neighbor->GetPhenotype().GetNumThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumThreshGbDonationsLast() << endl;
+    
+  }
+
+  return true;
+  
+}
+
+
+bool cHardwareCPU::Inst_DonateQuantaThreshGreenBeard(cAvidaContext& ctx)
+{
+  // this donates to organisms that have this instruction anywhere
+  // in their genome AND their parents excuted it more than a
+  // THRESHOLD number of times where that threshold depend on the
+  // number of times the individual's parents attempted to donate
+  // using this instruction.  The threshold levels are multiples of
+  // the quanta value set in genesis, and the highest level that
+  // the donor qualifies for is the one used.
+
+  // (see Dawkins 1976, The Selfish Gene, for 
+  // the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (phenotype.GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorQuantaThreshGb();
+  phenotype.IncNumQuantaThreshGbDonations();
+  //cout << endl << "quanta_threshgb attempt.. " ;
+
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // Get the quanta (step size) between threshold levels.
+  const int donate_quanta = m_world->GetConfig().DONATE_THRESH_QUANTA.Get();
+  
+  // Calculate what quanta level we should be at for this individual.  We do a
+  // math trick to make sure its the next lowest event multiple of donate_quanta.
+  const int quanta_donate_thresh =
+    (phenotype.GetNumQuantaThreshGbDonationsLast() / donate_quanta) * donate_quanta;
+  //cout << " phenotype.GetNumQuantaThreshGbDonationsLast() is " << phenotype.GetNumQuantaThreshGbDonationsLast();
+  //cout << " quanta thresh=  " << quanta_donate_thresh;
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      neighbor = organism->GetNeighbor();
+      //if neighbor exists, AND if their parent attempted to donate >= threshhold,
+      if (neighbor != NULL &&
+	  neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() >= quanta_donate_thresh) {
+
+          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-quantagb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverQuantaThreshGb();
+    //cout << " ************ neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast();
+    
+  }
+
+  return true;
+  
+}
+
+
 bool cHardwareCPU::Inst_DonateNULL(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorNull();
   
   // This is a fake donate command that causes the organism to lose merit,
   // but no one else to gain any.
   
-  const double merit_given = m_world->GetConfig().DONATE_SIZE.Get();
+  const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
   double cur_merit = organism->GetPhenotype().GetMerit().GetDouble();
   cur_merit -= merit_given;
   

Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/cpu/cHardwareCPU.h	2007-05-29 17:52:26 UTC (rev 1622)
@@ -434,6 +434,10 @@
   bool Inst_DonateRandom(cAvidaContext& ctx);
   bool Inst_DonateKin(cAvidaContext& ctx);
   bool Inst_DonateEditDist(cAvidaContext& ctx);
+  bool Inst_DonateGreenBeardGene(cAvidaContext& ctx);
+  bool Inst_DonateTrueGreenBeard(cAvidaContext& ctx);
+  bool Inst_DonateThreshGreenBeard(cAvidaContext& ctx);
+  bool Inst_DonateQuantaThreshGreenBeard(cAvidaContext& ctx);
   bool Inst_DonateNULL(cAvidaContext& ctx);
 
   bool Inst_SearchF(cAvidaContext& ctx);

Modified: branches/collect/source/cpu/cHardwareGX.cc
===================================================================
--- branches/collect/source/cpu/cHardwareGX.cc	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/cpu/cHardwareGX.cc	2007-05-29 17:52:26 UTC (rev 1622)
@@ -197,6 +197,10 @@
     tInstLibEntry<tMethod>("donate-rnd", &cHardwareGX::Inst_DonateRandom),
     tInstLibEntry<tMethod>("donate-kin", &cHardwareGX::Inst_DonateKin),
     tInstLibEntry<tMethod>("donate-edt", &cHardwareGX::Inst_DonateEditDist),
+    tInstLibEntry<tMethod>("donate-gbg",  &cHardwareGX::Inst_DonateGreenBeardGene),
+    tInstLibEntry<tMethod>("donate-tgb",  &cHardwareGX::Inst_DonateTrueGreenBeard),
+    tInstLibEntry<tMethod>("donate-threshgb",  &cHardwareGX::Inst_DonateThreshGreenBeard),
+    tInstLibEntry<tMethod>("donate-quantagb",  &cHardwareGX::Inst_DonateQuantaThreshGreenBeard),
     tInstLibEntry<tMethod>("donate-NUL", &cHardwareGX::Inst_DonateNULL),
     
     tInstLibEntry<tMethod>("rotate-l", &cHardwareGX::Inst_RotateL),
@@ -2410,14 +2414,14 @@
 void cHardwareGX::DoDonate(cOrganism* to_org)
 {
   assert(to_org != NULL);
-  
-  const double merit_given = m_world->GetConfig().DONATE_SIZE.Get();
-  const double merit_received =
-    merit_given * m_world->GetConfig().DONATE_MULT.Get();
-  
+
+  const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
+  const double merit_received = m_world->GetConfig().MERIT_RECEIVED.Get();
+
   double cur_merit = organism->GetPhenotype().GetMerit().GetDouble();
-  cur_merit -= merit_given; 
-  
+  cur_merit -= merit_given;
+  if(cur_merit < 0) cur_merit=0; 
+
   // Plug the current merit back into this organism and notify the scheduler.
   organism->UpdateMerit(cur_merit);
   
@@ -2429,11 +2433,14 @@
 
 bool cHardwareGX::Inst_DonateRandom(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
+  
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-  
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorRand();
+
   // Turn to a random neighbor, get it, and turn back...
   int neighbor_id = ctx.GetRandom().GetInt(organism->GetNeighborhoodSize());
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
@@ -2441,19 +2448,35 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a neighbor.
-  if (neighbor != NULL) DoDonate(neighbor);
-  
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    
+    //print out how often random donations go to kin
+    /*
+    static ofstream kinDistanceFile("kinDistance.dat");
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=1) << " ";
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=2) << " ";
+    kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=3) << " ";
+    kinDistanceFile << genotype->GetPhyloDistance(neighbor->GetGenotype());
+    kinDistanceFile << endl; 
+    */
+    neighbor->GetPhenotype().SetIsReceiverRand();
+  }
+
   return true;
 }
 
 
 bool cHardwareGX::Inst_DonateKin(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
   
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorKin();
+
+
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = organism->GetNeighborhoodSize();
   
@@ -2485,17 +2508,21 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a close enough relative...
-  if (neighbor != NULL)  DoDonate(neighbor);
-  
+  if (neighbor != NULL){
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverKin();
+  }
   return true;
 }
 
 bool cHardwareGX::Inst_DonateEditDist(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorEdit();
   
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = organism->GetNeighborhoodSize();
@@ -2531,23 +2558,350 @@
   for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
   
   // Donate only if we have found a close enough relative...
-  if (neighbor != NULL)  DoDonate(neighbor);
+  if (neighbor != NULL){
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverEdit();
+  }
+  return true;
+}
+
+bool cHardwareGX::Inst_DonateGreenBeardGene(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome (see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorGbg();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      neighbor = organism->GetNeighbor();
+
+      //if neighbor exists, do they have the green beard gene?
+      if (neighbor != NULL) {
+          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-gbg
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
   
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverGbg();
+  }
+  
   return true;
+  
 }
 
+bool cHardwareGX::Inst_DonateTrueGreenBeard(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome AND their parents excuted it
+  //(see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
 
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorTrueGb();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      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();
+
+          // for each instruction in the genome...
+          for(int i=0;i<neighbor_genome.GetSize();i++){
+
+            // ...see if it is donate-tgb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverTrueGb();
+  }
+
+  
+  return true;
+  
+}
+
+bool cHardwareGX::Inst_DonateThreshGreenBeard(cAvidaContext& ctx)
+{
+  //this donates to organisms that have this instruction anywhere
+  //in their genome AND their parents excuted it >=THRESHOLD number of times
+  //(see Dawkins 1976, The Selfish Gene, for 
+  //the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorThreshGb();
+  phenotype.IncNumThreshGbDonations();
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // rotate through orgs in neighborhood  
+  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() ) {
+          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-threshgb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverThreshGb();
+    // cout << "************ neighbor->GetPhenotype().GetNumThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumThreshGbDonationsLast() << endl;
+    
+  }
+
+  return true;
+  
+}
+
+
+bool cHardwareGX::Inst_DonateQuantaThreshGreenBeard(cAvidaContext& ctx)
+{
+  // this donates to organisms that have this instruction anywhere
+  // in their genome AND their parents excuted it more than a
+  // THRESHOLD number of times where that threshold depend on the
+  // number of times the individual's parents attempted to donate
+  // using this instruction.  The threshold levels are multiples of
+  // the quanta value set in genesis, and the highest level that
+  // the donor qualifies for is the one used.
+
+  // (see Dawkins 1976, The Selfish Gene, for 
+  // the history of the theory and the name 'green beard'
+  //  cout << "i am about to donate to a green beard" << endl;
+  cPhenotype & phenotype = organism->GetPhenotype();
+
+  if (phenotype.GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
+    return false;
+  }
+
+  phenotype.IncDonates();
+  phenotype.SetIsDonorQuantaThreshGb();
+  phenotype.IncNumQuantaThreshGbDonations();
+  //cout << endl << "quanta_threshgb attempt.. " ;
+
+
+  // Find the target as the first match found in the neighborhood.
+
+  //get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+ 
+  //we have not found a match yet
+  bool found = false;
+
+  // Get the quanta (step size) between threshold levels.
+  const int donate_quanta = m_world->GetConfig().DONATE_THRESH_QUANTA.Get();
+  
+  // Calculate what quanta level we should be at for this individual.  We do a
+  // math trick to make sure its the next lowest event multiple of donate_quanta.
+  const int quanta_donate_thresh =
+    (phenotype.GetNumQuantaThreshGbDonationsLast() / donate_quanta) * donate_quanta;
+  //cout << " phenotype.GetNumQuantaThreshGbDonationsLast() is " << phenotype.GetNumQuantaThreshGbDonationsLast();
+  //cout << " quanta thresh=  " << quanta_donate_thresh;
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+      neighbor = organism->GetNeighbor();
+      //if neighbor exists, AND if their parent attempted to donate >= threshhold,
+      if (neighbor != NULL &&
+	  neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() >= quanta_donate_thresh) {
+
+          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-quantagb, if so, we found a target
+            if (neighbor_genome[i] == IP().GetInst()) {
+              found = true;
+              break;
+            }
+	    
+          }
+      }
+      
+      // stop searching through the neighbors if we already found one
+      if (found == true);{
+    	break;
+      }
+  
+      organism->Rotate(1);
+      neighbor_id++;
+  }
+
+    if (found == false) neighbor = NULL;
+
+  // Put the facing back where it was.
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(-1);
+
+  // Donate only if we have found a close enough relative...
+  if (neighbor != NULL) {
+    DoDonate(neighbor);
+    neighbor->GetPhenotype().SetIsReceiverQuantaThreshGb();
+    //cout << " ************ neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast();
+    
+  }
+
+  return true;
+  
+}
+
+
 bool cHardwareGX::Inst_DonateNULL(cAvidaContext& ctx)
 {
-  organism->GetPhenotype().IncDonates();
   if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
+
+  organism->GetPhenotype().IncDonates();
+  organism->GetPhenotype().SetIsDonorNull();
   
   // This is a fake donate command that causes the organism to lose merit,
   // but no one else to gain any.
   
-  const double merit_given = m_world->GetConfig().DONATE_SIZE.Get();
+  const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
   double cur_merit = organism->GetPhenotype().GetMerit().GetDouble();
   cur_merit -= merit_given;
   

Modified: branches/collect/source/cpu/cHardwareGX.h
===================================================================
--- branches/collect/source/cpu/cHardwareGX.h	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/cpu/cHardwareGX.h	2007-05-29 17:52:26 UTC (rev 1622)
@@ -494,6 +494,10 @@
   bool Inst_DonateRandom(cAvidaContext& ctx);
   bool Inst_DonateKin(cAvidaContext& ctx);
   bool Inst_DonateEditDist(cAvidaContext& ctx);
+  bool Inst_DonateGreenBeardGene(cAvidaContext& ctx);
+  bool Inst_DonateTrueGreenBeard(cAvidaContext& ctx);
+  bool Inst_DonateThreshGreenBeard(cAvidaContext& ctx);
+  bool Inst_DonateQuantaThreshGreenBeard(cAvidaContext& ctx);
   bool Inst_DonateNULL(cAvidaContext& ctx);
 
   bool Inst_SearchF(cAvidaContext& ctx);

Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/main/cAvidaConfig.h	2007-05-29 17:52:26 UTC (rev 1622)
@@ -295,10 +295,12 @@
   CONFIG_ADD_VAR(MAX_CPU_THREADS, int, 1, "Number of Threads a CPU can spawn");
   CONFIG_ADD_VAR(THREAD_SLICING_METHOD, int, 0, "Formula for and organism's thread slicing\n  (num_threads-1) * THREAD_SLICING_METHOD + 1\n0 = One thread executed per time slice.\n1 = All threads executed each time slice.\n");
   CONFIG_ADD_VAR(MAX_LABEL_EXE_SIZE, int, 1, "Max nops marked as executed when labels are used");
-  CONFIG_ADD_VAR(DONATE_SIZE, double, 5.0, "Amount of merit donated with 'donate' command");
-  CONFIG_ADD_VAR(DONATE_MULT, double, 10.0, "Multiple of merit given that the target receives.");
+  CONFIG_ADD_VAR(MERIT_GIVEN, double, 0.0, "Fraction of merit donated with 'donate' command");
+  CONFIG_ADD_VAR(MERIT_RECEIVED, double, 0.0, "Multiplier of merit given with 'donate' command"); 
   CONFIG_ADD_VAR(MAX_DONATE_KIN_DIST, int, -1, "Limit on distance of relation for donate; -1=no max");
-  CONFIG_ADD_VAR(MAX_DONATE_EDIT_DIST, int, -1, "Limit on edit distance for donate; -1=no max");
+  CONFIG_ADD_VAR(MAX_DONATE_EDIT_DIST, int, -1, "Limit on genetic (edit) distance for donate; -1=no max");
+  CONFIG_ADD_VAR(MIN_GB_DONATE_THRESHOLD, int, -1, "threshold green beard donates only to orgs above this donation attempt threshold; -1=no thresh");
+  CONFIG_ADD_VAR(DONATE_THRESH_QUANTA, int, 10, "The size of steps between quanta donate thresholds");
   CONFIG_ADD_VAR(MAX_DONATES, int, 1000000, "Limit on number of donates organisms are allowed.");
   
   CONFIG_ADD_GROUP(PROMOTER_GROUP, "Promoters");

Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/main/cPhenotype.cc	2007-05-29 17:52:26 UTC (rev 1622)
@@ -184,12 +184,46 @@
   neutral_metric  = parent_phenotype.neutral_metric + m_world->GetRandom().GetRandNormal();
   life_fitness    = fitness; 
 
+  num_thresh_gb_donations = 0;
+  num_thresh_gb_donations_last = parent_phenotype.num_thresh_gb_donations_last;
+  num_quanta_thresh_gb_donations = 0;
+  num_quanta_thresh_gb_donations_last = parent_phenotype.num_thresh_gb_donations_last;
+
   // Setup flags...
   is_injected   = false;
   is_parasite   = false;
   is_donor_cur  = false;
   is_donor_last = parent_phenotype.is_donor_last;
+  is_donor_rand = false;
+  is_donor_rand_last = parent_phenotype.is_donor_rand_last;
+  is_donor_null = false;
+  is_donor_null_last = parent_phenotype.is_donor_null_last;
+  is_donor_kin  = false;
+  is_donor_kin_last = parent_phenotype.is_donor_kin_last;
+  is_donor_edit  = false;
+  is_donor_edit_last = parent_phenotype.is_donor_edit_last;
+  is_donor_gbg  = false;
+  is_donor_gbg_last = parent_phenotype.is_donor_gbg_last;
+  is_donor_truegb  = false;
+  is_donor_truegb_last = parent_phenotype.is_donor_truegb_last;
+  is_donor_threshgb  = false;
+  is_donor_threshgb_last = parent_phenotype.is_donor_threshgb_last;
+  is_donor_quanta_threshgb  = false;
+  is_donor_quanta_threshgb_last = parent_phenotype.is_donor_quanta_threshgb_last;
   is_receiver   = false;
+  is_receiver_last = parent_phenotype.is_receiver_last;
+  is_receiver_rand   = false;
+  is_receiver_kin    = false;
+  is_receiver_kin_last    = parent_phenotype.is_receiver_kin_last;
+  is_receiver_edit   = false;
+  is_receiver_edit_last    = parent_phenotype.is_receiver_edit_last;
+  is_receiver_gbg    = false;
+  is_receiver_truegb = false;
+  is_receiver_truegb_last = parent_phenotype.is_receiver_truegb_last;
+  is_receiver_threshgb = false;
+  is_receiver_threshgb_last = parent_phenotype.is_receiver_threshgb_last;
+  is_receiver_quanta_threshgb = false;
+  is_receiver_quanta_threshgb_last = parent_phenotype.is_receiver_quanta_threshgb_last;
   is_modifier   = false;
   is_modified   = false;
   is_fertile    = parent_phenotype.last_child_fertile;
@@ -280,12 +314,46 @@
   neutral_metric  = 0;
   life_fitness    = 0; 
 
+  num_thresh_gb_donations = 0;
+  num_thresh_gb_donations_last = 0;
+  num_quanta_thresh_gb_donations = 0;
+  num_quanta_thresh_gb_donations_last = 0;
+
   // Setup flags...
   is_injected   = true;
   is_parasite   = false;
   is_donor_last = false;
   is_donor_cur  = false;
+  is_donor_rand = false;
+  is_donor_rand_last = false;
+  is_donor_null = false;
+  is_donor_null_last = false;
+  is_donor_kin = false;
+  is_donor_kin_last = false;
+  is_donor_edit = false;
+  is_donor_edit_last = false;
+  is_donor_gbg = false;
+  is_donor_gbg_last = false;
+  is_donor_truegb = false;
+  is_donor_truegb_last = false;
+  is_donor_threshgb = false;
+  is_donor_threshgb_last = false;
+  is_donor_quanta_threshgb = false;
+  is_donor_quanta_threshgb_last = false;
   is_receiver   = false;
+  is_receiver_last   = false;
+  is_receiver_rand   = false;
+  is_receiver_kin   = false;
+  is_receiver_kin_last   = false;
+  is_receiver_edit   = false;
+  is_receiver_edit_last   = false;
+  is_receiver_gbg   = false;
+  is_receiver_truegb   = false;
+  is_receiver_truegb_last   = false;
+  is_receiver_threshgb   = false;
+  is_receiver_threshgb_last   = false;
+  is_receiver_quanta_threshgb   = false;
+  is_receiver_quanta_threshgb_last   = false;
   is_modifier   = false;
   is_modified   = false;
   is_fertile    = true;
@@ -382,12 +450,46 @@
   (void) neutral_metric;
   life_fitness = fitness; 
 
+  num_thresh_gb_donations_last = num_thresh_gb_donations;
+  num_thresh_gb_donations = 0;
+  num_quanta_thresh_gb_donations_last = num_quanta_thresh_gb_donations;
+  num_quanta_thresh_gb_donations = 0;
+
   // Leave flags alone...
   (void) is_injected;
   (void) is_parasite;
   is_donor_last = is_donor_cur;
   is_donor_cur = false;
+  is_donor_rand_last = is_donor_rand;
+  is_donor_rand = false;
+  is_donor_null_last = is_donor_null;
+  is_donor_null = false;
+  is_donor_kin_last = is_donor_kin;
+  is_donor_kin = false;
+  is_donor_edit_last = is_donor_edit;
+  is_donor_edit = false;
+  is_donor_gbg_last = is_donor_gbg;
+  is_donor_gbg = false;
+  is_donor_truegb_last = is_donor_truegb;
+  is_donor_truegb = false;
+  is_donor_threshgb_last = is_donor_threshgb;
+  is_donor_threshgb = false;
+  is_donor_quanta_threshgb_last = is_donor_quanta_threshgb;
+  is_donor_quanta_threshgb = false;
+  is_receiver_last = is_receiver;
   is_receiver = false;
+  is_receiver_rand = false;
+  is_receiver_kin_last = is_receiver_kin;
+  is_receiver_kin = false;
+  is_receiver_edit_last = is_receiver_edit;
+  is_receiver_edit = false;
+  is_receiver_gbg = false;
+  is_receiver_truegb_last = is_receiver_truegb;
+  is_receiver_truegb = false;
+  is_receiver_threshgb_last = is_receiver_threshgb;
+  is_receiver_threshgb = false;
+  is_receiver_quanta_threshgb_last = is_receiver_quanta_threshgb;
+  is_receiver_quanta_threshgb = false;
   (void) is_modifier;
   (void) is_modified;
   (void) is_fertile;
@@ -494,12 +596,46 @@
   (void) neutral_metric;
   life_fitness = fitness; 
 
+  num_thresh_gb_donations_last = num_thresh_gb_donations;
+  num_thresh_gb_donations = 0;
+  num_quanta_thresh_gb_donations_last = num_quanta_thresh_gb_donations;
+  num_quanta_thresh_gb_donations = 0;
+
   // Leave flags alone...
   (void) is_injected;
   (void) is_parasite;
   is_donor_last = is_donor_cur;
   is_donor_cur = false;
+  is_donor_rand_last = is_donor_rand;
+  is_donor_rand = false;
+  is_donor_null_last = is_donor_null;
+  is_donor_null = false;
+  is_donor_kin_last = is_donor_kin;
+  is_donor_kin = false;
+  is_donor_edit_last = is_donor_edit;
+  is_donor_edit = false;
+  is_donor_gbg_last = is_donor_gbg;
+  is_donor_gbg = false;
+  is_donor_truegb_last = is_donor_truegb;
+  is_donor_truegb = false;
+  is_donor_threshgb_last = is_donor_threshgb;
+  is_donor_threshgb = false;
+  is_donor_quanta_threshgb_last = is_donor_quanta_threshgb;
+  is_donor_quanta_threshgb = false;
+  is_receiver_last = is_receiver;
   is_receiver = false;
+  is_receiver_rand = false;
+  is_receiver_kin_last = is_receiver_kin;
+  is_receiver_kin = false;
+  is_receiver_edit_last = is_receiver_edit;
+  is_receiver_edit = false;
+  is_receiver_gbg = false;
+  is_receiver_truegb_last = is_receiver_truegb;
+  is_receiver_truegb = false;
+  is_receiver_threshgb_last = is_receiver_threshgb;
+  is_receiver_threshgb = false;
+  is_receiver_quanta_threshgb_last = is_receiver_quanta_threshgb;
+  is_receiver_quanta_threshgb = false;
   (void) is_modifier;
   (void) is_modified;
   (void) is_fertile;
@@ -591,12 +727,47 @@
   neutral_metric  = clone_phenotype.neutral_metric + m_world->GetRandom().GetRandNormal();
   life_fitness    = fitness; 
 
+  num_thresh_gb_donations_last = clone_phenotype.num_thresh_gb_donations_last;
+  num_thresh_gb_donations  = clone_phenotype.num_thresh_gb_donations;
+  num_quanta_thresh_gb_donations_last = clone_phenotype.num_quanta_thresh_gb_donations_last;
+  num_quanta_thresh_gb_donations  = clone_phenotype.num_quanta_thresh_gb_donations;
+
   // Setup flags...
   is_injected   = false;
   is_parasite   = false;
   is_donor_last = clone_phenotype.is_donor_last;
   is_donor_cur  = clone_phenotype.is_donor_cur;
   is_receiver = false;
+  is_donor_rand_last = clone_phenotype.is_donor_rand_last;
+  is_donor_rand  = clone_phenotype.is_donor_rand;
+  is_donor_null_last = clone_phenotype.is_donor_null_last;
+  is_donor_null  = clone_phenotype.is_donor_null;
+  is_donor_kin_last = clone_phenotype.is_donor_kin_last;
+  is_donor_kin  = clone_phenotype.is_donor_kin;
+  is_donor_edit_last = clone_phenotype.is_donor_edit_last;
+  is_donor_edit  = clone_phenotype.is_donor_edit;
+  is_donor_gbg_last = clone_phenotype.is_donor_gbg_last;
+  is_donor_gbg  = clone_phenotype.is_donor_gbg;
+  is_donor_truegb_last = clone_phenotype.is_donor_truegb_last;
+  is_donor_truegb  = clone_phenotype.is_donor_truegb;
+  is_donor_threshgb_last = clone_phenotype.is_donor_threshgb_last;
+  is_donor_threshgb  = clone_phenotype.is_donor_threshgb;
+  is_donor_quanta_threshgb_last = clone_phenotype.is_donor_quanta_threshgb_last;
+  is_donor_quanta_threshgb  = clone_phenotype.is_donor_quanta_threshgb;
+  is_receiver = clone_phenotype.is_receiver;
+  is_receiver_last = clone_phenotype.is_receiver_last;
+  is_receiver_rand = clone_phenotype.is_receiver_rand;
+  is_receiver_kin = clone_phenotype.is_receiver_kin;
+  is_receiver_kin_last = clone_phenotype.is_receiver_kin_last;
+  is_receiver_edit = clone_phenotype.is_receiver_edit;
+  is_receiver_edit_last = clone_phenotype.is_receiver_edit_last;
+  is_receiver_gbg = clone_phenotype.is_receiver_gbg;
+  is_receiver_truegb = clone_phenotype.is_receiver_truegb;
+  is_receiver_truegb_last = clone_phenotype.is_receiver_truegb_last;
+  is_receiver_threshgb = clone_phenotype.is_receiver_threshgb;
+  is_receiver_threshgb_last = clone_phenotype.is_receiver_threshgb_last;
+  is_receiver_quanta_threshgb = clone_phenotype.is_receiver_quanta_threshgb;
+  is_receiver_quanta_threshgb_last = clone_phenotype.is_receiver_quanta_threshgb_last;
   is_modifier   = false;
   is_modified   = false;
   is_fertile    = clone_phenotype.last_child_fertile;
@@ -784,8 +955,41 @@
   fp << is_parasite         << " ";
   fp << is_donor_last       << " ";
   fp << is_donor_cur        << " ";
+  fp << is_donor_rand_last       << " ";
+  fp << is_donor_rand        << " ";
+  fp << is_donor_null_last       << " ";
+  fp << is_donor_null        << " ";
+  fp << is_donor_kin_last       << " ";
+  fp << is_donor_kin        << " ";
+  fp << is_donor_edit_last       << " ";
+  fp << is_donor_edit        << " ";
+  fp << is_donor_gbg_last       << " ";
+  fp << is_donor_gbg        << " ";
+  fp << is_donor_truegb_last       << " ";
+  fp << is_donor_truegb        << " ";
+  fp << is_donor_threshgb_last       << " ";
+  fp << is_donor_threshgb        << " ";
+  fp << is_donor_quanta_threshgb_last       << " ";
+  fp << is_donor_quanta_threshgb        << " ";
+  fp << num_thresh_gb_donations_last       << " ";
+  fp << num_thresh_gb_donations        << " ";
+  fp << num_quanta_thresh_gb_donations_last       << " ";
+  fp << num_quanta_thresh_gb_donations        << " ";
 
+  fp << is_receiver_last         << " ";
   fp << is_receiver         << " ";
+  fp << is_receiver_rand         << " ";
+  fp << is_receiver_kin         << " ";
+  fp << is_receiver_kin_last         << " ";
+  fp << is_receiver_edit         << " ";
+  fp << is_receiver_edit_last         << " ";
+  fp << is_receiver_gbg         << " ";
+  fp << is_receiver_truegb_last         << " ";
+  fp << is_receiver_truegb         << " ";
+  fp << is_receiver_threshgb_last         << " ";
+  fp << is_receiver_threshgb         << " ";
+  fp << is_receiver_quanta_threshgb_last         << " ";
+  fp << is_receiver_quanta_threshgb         << " ";
   fp << is_modifier         << " ";
   fp << is_modified         << " ";
   fp << is_fertile          << " ";
@@ -879,7 +1083,40 @@
   fp >> is_parasite;
   fp >> is_donor_last;
   fp >> is_donor_cur;
+  fp >> is_donor_rand_last;
+  fp >> is_donor_rand;
+  fp >> is_donor_null_last;
+  fp >> is_donor_null;
+  fp >> is_donor_kin_last;
+  fp >> is_donor_kin;
+  fp >> is_donor_edit_last;
+  fp >> is_donor_edit;
+  fp >> is_donor_gbg_last;
+  fp >> is_donor_gbg;
+  fp >> is_donor_truegb_last;
+  fp >> is_donor_truegb;
+  fp >> is_donor_threshgb_last;
+  fp >> is_donor_threshgb;
+  fp >> is_donor_quanta_threshgb_last;
+  fp >> is_donor_quanta_threshgb;
+  fp >> num_thresh_gb_donations_last;
+  fp >> num_thresh_gb_donations;
+  fp >> num_quanta_thresh_gb_donations_last;
+  fp >> num_quanta_thresh_gb_donations;
+  fp >> is_receiver_last;
   fp >> is_receiver;
+  fp >> is_receiver_rand;
+  fp >> is_receiver_kin;
+  fp >> is_receiver_kin_last;
+  fp >> is_receiver_edit;
+  fp >> is_receiver_edit_last;
+  fp >> is_receiver_gbg;
+  fp >> is_receiver_truegb_last;
+  fp >> is_receiver_truegb;
+  fp >> is_receiver_threshgb_last;
+  fp >> is_receiver_threshgb;
+  fp >> is_receiver_quanta_threshgb_last;
+  fp >> is_receiver_quanta_threshgb;
   fp >> is_modifier;
   fp >> is_modified;
   fp >> is_fertile;

Modified: branches/collect/source/main/cPhenotype.h
===================================================================
--- branches/collect/source/main/cPhenotype.h	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/main/cPhenotype.h	2007-05-29 17:52:26 UTC (rev 1622)
@@ -161,9 +161,42 @@
   bool to_delete;        // Should this organism be deleted when finished?
   bool is_injected;      // Was this organism injected into the population?
   bool is_parasite;      // Has this organism ever executed outside code?
-  bool is_donor_cur;     // Has this organism ever donated merit?  
-  bool is_donor_last;    // Did this organism's parent ever donate merit? 
+  bool is_donor_cur;     // Has this organism attempted to donate merit?  
+  bool is_donor_last;    // Did this organism's parent attempt to donate merit? 
+  bool is_donor_rand;    // Has this organism attempted a random donation?
+  bool is_donor_rand_last; // Did this org's parent attempt to donate randomly
+  bool is_donor_null;    // Has this organism attempted a null donation?
+  bool is_donor_null_last;// Did this org's parent attempt a null donation?
+  bool is_donor_kin;     // Has this organism kin_donated?
+  bool is_donor_kin_last;// Did this org's parent kin_donate?
+  bool is_donor_edit;    // Has this organism edit_donated?
+  bool is_donor_edit_last; // Did this org's parent edit_donate?
+  bool is_donor_gbg;     //  Has this organism gbg_donated (green beard gene)?
+  bool is_donor_gbg_last;// Did this org's parent gbg_donate?
+  bool is_donor_truegb;  // Has this organism truegb_donated (true green beard)? 
+  bool is_donor_truegb_last;// Did this org's parent truegb_donate? 
+  bool is_donor_threshgb;  // Has this organism threshgb_donated (true green beard)? 
+  bool is_donor_threshgb_last;// Did this org's parent threshgbg_donate? 
+  bool is_donor_quanta_threshgb;  // Has this organism quanta_threshgb_donated (true green beard)? 
+  bool is_donor_quanta_threshgb_last;// Did this org's parent quanta_threshgbg_donate? 
+  int num_thresh_gb_donations;  // Num times this organism threshgb_donated (thresh green beard)? 
+  int num_thresh_gb_donations_last; // Num times this org's parent thresh_donated? 
+  int num_quanta_thresh_gb_donations;  // Num times this organism threshgb_donated (thresh green beard)? 
+  int num_quanta_thresh_gb_donations_last; // Num times this org's parent thresh_donated? 
   bool is_receiver;      // Has this organism ever received merit donation?
+  bool is_receiver_last;      // Did this organism's parent receive a merit donation?
+  bool is_receiver_rand; // Has this organism ever received random merit donation?
+  bool is_receiver_kin;  // Has this organism ever received kin merit donation?
+  bool is_receiver_kin_last;  // Did this organism's parent receive a kin merit donation?
+  bool is_receiver_edit; // Has this organism ever received edit donation?
+  bool is_receiver_edit_last; // Did this organism's parent receive an edit donation?
+  bool is_receiver_gbg;  // Has this organism ever received gbg donation?
+  bool is_receiver_truegb;// Has this organism ever received truegb donation?
+  bool is_receiver_truegb_last;// Did this organism's parent receive a truegb donation?
+  bool is_receiver_threshgb;// Has this organism ever received a threshgb donation?
+  bool is_receiver_threshgb_last;// Did this organism's parent receive a threshgb donation?
+  bool is_receiver_quanta_threshgb;// Has this organism ever received a quanta_threshgb donation?
+  bool is_receiver_quanta_threshgb_last;// Did this organism's parent receive a quanta_threshgb donation?
   bool is_modifier;      // Has this organism modified another?
   bool is_modified;      // Has this organism been modified by another?
   bool is_fertile;       // Do we allow this organisms to produce offspring?
@@ -295,12 +328,44 @@
   const cString& GetFault() const { assert(initialized == true); return fault_desc; }
   double GetNeutralMetric() const { assert(initialized == true); return neutral_metric; }
   double GetLifeFitness() const { assert(initialized == true); return life_fitness; }
+  int  GetNumThreshGbDonations() const { assert(initialized == true); return num_thresh_gb_donations; }
+  int  GetNumThreshGbDonationsLast() const { assert(initialized == true); return num_thresh_gb_donations_last; }
+  int  GetNumQuantaThreshGbDonations() const { assert(initialized == true); return num_quanta_thresh_gb_donations; }
+  int  GetNumQuantaThreshGbDonationsLast() const { assert(initialized == true); return num_quanta_thresh_gb_donations_last; }
 
+
   bool IsInjected() const { assert(initialized == true); return is_injected; }
   bool IsParasite() const { assert(initialized == true); return is_parasite; }
   bool IsDonorCur() const { assert(initialized == true); return is_donor_cur; }
   bool IsDonorLast() const { assert(initialized == true); return is_donor_last; }
+  bool IsDonorRand() const { assert(initialized == true); return is_donor_rand; }
+  bool IsDonorRandLast() const { assert(initialized == true); return is_donor_rand_last; }
+  bool IsDonorKin() const { assert(initialized == true); return is_donor_kin; }
+  bool IsDonorKinLast() const { assert(initialized == true); return is_donor_kin_last; }
+  bool IsDonorEdit() const { assert(initialized == true); return is_donor_edit; }
+  bool IsDonorEditLast() const { assert(initialized == true); return is_donor_edit_last; }
+  bool IsDonorGbg() const { assert(initialized == true); return is_donor_gbg; }
+  bool IsDonorGbgLast() const { assert(initialized == true); return is_donor_gbg_last; }
+  bool IsDonorTrueGb() const { assert(initialized == true); return is_donor_truegb; }
+  bool IsDonorTrueGbLast() const { assert(initialized == true); return is_donor_truegb_last; }
+  bool IsDonorThreshGb() const { assert(initialized == true); return is_donor_threshgb; }
+  bool IsDonorThreshGbLast() const { assert(initialized == true); return is_donor_threshgb_last; }
+  bool IsDonorQuantaThreshGb() const { assert(initialized == true); return is_donor_quanta_threshgb; }
+  bool IsDonorQuantaThreshGbLast() const { assert(initialized == true); return is_donor_quanta_threshgb_last; }
   bool IsReceiver() const { assert(initialized == true); return is_receiver; }
+  bool IsReceiverLast() const { assert(initialized == true); return is_receiver_last; }
+  bool IsReceiverRand() const { assert(initialized == true); return is_receiver_rand; }
+  bool IsReceiverKin() const { assert(initialized == true); return is_receiver_kin; }
+  bool IsReceiverKinLast() const { assert(initialized == true); return is_receiver_kin_last; }
+  bool IsReceiverEdit() const { assert(initialized == true); return is_receiver_edit; }
+  bool IsReceiverEditLast() const { assert(initialized == true); return is_receiver_edit_last; }
+  bool IsReceiverGbg() const { assert(initialized == true); return is_receiver_gbg; }
+  bool IsReceiverTrueGb() const { assert(initialized == true); return is_receiver_truegb; }
+  bool IsReceiverTrueGbLast() const { assert(initialized == true); return is_receiver_truegb_last; }
+  bool IsReceiverThreshGb() const { assert(initialized == true); return is_receiver_threshgb; }
+  bool IsReceiverThreshGbLast() const { assert(initialized == true); return is_receiver_threshgb_last; }
+  bool IsReceiverQuantaThreshGb() const { assert(initialized == true); return is_receiver_quanta_threshgb; }
+  bool IsReceiverQuantaThreshGbLast() const { assert(initialized == true); return is_receiver_quanta_threshgb_last; }
   bool IsModifier() const { assert(initialized == true); return is_modifier; }
   bool IsModified() const { assert(initialized == true); return is_modified; }
   bool IsFertile() const  { assert(initialized == true); return is_fertile; }
@@ -342,7 +407,22 @@
   void AddToCurRBinTotal(int index, double val) { cur_rbins_total[index] += val; }
 
   void SetIsDonorCur() { is_donor_cur = true; } 
+  void SetIsDonorRand() { SetIsDonorCur(); is_donor_rand = true; }
+  void SetIsDonorKin() { SetIsDonorCur(); is_donor_kin = true; }
+  void SetIsDonorNull() { SetIsDonorCur(); is_donor_null = true; }
+  void SetIsDonorEdit() { SetIsDonorCur(); is_donor_edit = true; }
+  void SetIsDonorGbg() { SetIsDonorCur(); is_donor_gbg = true; }
+  void SetIsDonorTrueGb() { SetIsDonorCur(); is_donor_truegb = true; }
+  void SetIsDonorThreshGb() { SetIsDonorCur(); is_donor_threshgb = true; }
+  void SetIsDonorQuantaThreshGb() { SetIsDonorCur(); is_donor_quanta_threshgb = true; }
   void SetIsReceiver() { is_receiver = true; } 
+  void SetIsReceiverRand() { SetIsReceiver(); is_receiver_rand = true; } 
+  void SetIsReceiverKin() { SetIsReceiver(); is_receiver_kin = true; } 
+  void SetIsReceiverEdit() { SetIsReceiver(); is_receiver_edit = true; } 
+  void SetIsReceiverGbg() { SetIsReceiver(); is_receiver_gbg = true; } 
+  void SetIsReceiverTrueGb() { SetIsReceiver(); is_receiver_truegb = true; } 
+  void SetIsReceiverThreshGb() { SetIsReceiver(); is_receiver_threshgb = true; } 
+  void SetIsReceiverQuantaThreshGb() { SetIsReceiver(); is_receiver_quanta_threshgb = true; } 
   
   void SetCurBonus(double _bonus) { cur_bonus = _bonus; }
   void SetCurBonusInstCount(int _num_bonus_inst) {bonus_instruction_count = _num_bonus_inst;}
@@ -355,7 +435,10 @@
   void DecayAllPromoterRegulation();
   void RegulatePromoter(const int i, const bool up );
   void SetTerminated(bool _in) { promoter_last_inst_terminated = _in; }
-  
+
+  void IncNumThreshGbDonations() { assert(initialized == true); num_thresh_gb_donations++; }
+  void IncNumQuantaThreshGbDonations() { assert(initialized == true); num_quanta_thresh_gb_donations++; }
+
   void IncAge()      { assert(initialized == true); age++; }
   void IncCPUCyclesUsed() { assert(initialized == true); cpu_cycles_used++; }
   void IncTimeUsed(int i=1) { assert(initialized == true); time_used+=i; }

Modified: branches/collect/source/main/cPopulation.cc
===================================================================
--- branches/collect/source/main/cPopulation.cc	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/main/cPopulation.cc	2007-05-29 17:52:26 UTC (rev 1622)
@@ -1107,6 +1107,109 @@
 }
 
 
+// Print out statistics about donations
+                  
+void cPopulation::PrintDonationStats()
+{
+  cDoubleSum donation_makers;
+  cDoubleSum donation_receivers;
+  cDoubleSum donation_cheaters;
+
+  cDoubleSum edit_donation_makers;
+  cDoubleSum edit_donation_receivers;
+  cDoubleSum edit_donation_cheaters;
+
+  cDoubleSum kin_donation_makers;
+  cDoubleSum kin_donation_receivers;
+  cDoubleSum kin_donation_cheaters;
+
+  cDoubleSum threshgb_donation_makers;
+  cDoubleSum threshgb_donation_receivers;
+  cDoubleSum threshgb_donation_cheaters;
+
+  cDoubleSum quanta_threshgb_donation_makers;
+  cDoubleSum quanta_threshgb_donation_receivers;
+  cDoubleSum quanta_threshgb_donation_cheaters;
+
+  cStats& stats = m_world->GetStats();
+
+  cDataFile & dn_donors = m_world->GetDataFile("donations.dat");
+  dn_donors.WriteComment("Info about organisms giving donations in the population");
+  dn_donors.WriteTimeStamp();
+  dn_donors.Write(stats.GetUpdate(), "update");
+
+
+  for (int i = 0; i < cell_array.GetSize(); i++)
+    {
+      // Only look at cells with organisms in them.
+      if (cell_array[i].IsOccupied() == false) continue;
+      cOrganism * organism = cell_array[i].GetOrganism();
+      const cPhenotype & phenotype = organism->GetPhenotype();
+   
+      // donors & receivers in general
+      if (phenotype.IsDonorLast()) donation_makers.Add(1);       //found a donor
+      if (phenotype.IsReceiverLast()){
+        donation_receivers.Add(1);                              //found a receiver
+        if (phenotype.IsDonorLast()==0){
+          donation_cheaters.Add(1);                             //found a receiver whose parent did not give
+        }
+      }
+      // edit donors & receivers
+      if (phenotype.IsDonorEditLast()) edit_donation_makers.Add(1);       //found a edit donor
+      if (phenotype.IsReceiverEditLast()){
+        edit_donation_receivers.Add(1);                              //found a edit receiver
+        if (phenotype.IsDonorEditLast()==0){
+          edit_donation_cheaters.Add(1);                             //found a edit receiver whose parent did...
+        }                                                              //...not make a edit donation
+      }
+
+      // kin donors & receivers
+      if (phenotype.IsDonorKinLast()) kin_donation_makers.Add(1);       //found a kin donor
+      if (phenotype.IsReceiverKinLast()){
+        kin_donation_receivers.Add(1);                              //found a kin receiver
+        if (phenotype.IsDonorKinLast()==0){
+          kin_donation_cheaters.Add(1);                             //found a kin receiver whose parent did...
+        }                                                              //...not make a kin donation
+      }
+
+      // threshgb donors & receivers
+      if (phenotype.IsDonorThreshGbLast()) threshgb_donation_makers.Add(1); //found a threshgb donor
+      if (phenotype.IsReceiverThreshGbLast()){
+        threshgb_donation_receivers.Add(1);                              //found a threshgb receiver
+        if (phenotype.IsDonorThreshGbLast()==0){
+          threshgb_donation_cheaters.Add(1);                             //found a threshgb receiver whose parent did...
+        }                                                              //...not make a threshgb donation
+      }
+
+      // quanta_threshgb donors & receivers
+      if (phenotype.IsDonorQuantaThreshGbLast()) quanta_threshgb_donation_makers.Add(1); //found a quanta threshgb donor
+      if (phenotype.IsReceiverQuantaThreshGbLast()){
+        quanta_threshgb_donation_receivers.Add(1);                              //found a quanta threshgb receiver
+        if (phenotype.IsDonorQuantaThreshGbLast()==0){
+          quanta_threshgb_donation_cheaters.Add(1);                             //found a quanta threshgb receiver whose parent did...
+        }                                                              //...not make a quanta threshgb donation
+      }
+
+    }
+
+  dn_donors.Write(donation_makers.Sum(), "parent made at least one donation");
+  dn_donors.Write(donation_receivers.Sum(), "parent received at least one donation");
+  dn_donors.Write(donation_cheaters.Sum(),  "parent received at least one donation but did not make one");
+  dn_donors.Write(edit_donation_makers.Sum(), "parent made at least one edit_donation");
+  dn_donors.Write(edit_donation_receivers.Sum(), "parent received at least one edit_donation");
+  dn_donors.Write(edit_donation_cheaters.Sum(),  "parent received at least one edit_donation but did not make one");
+  dn_donors.Write(kin_donation_makers.Sum(), "parent made at least one kin_donation");
+  dn_donors.Write(kin_donation_receivers.Sum(), "parent received at least one kin_donation");
+  dn_donors.Write(kin_donation_cheaters.Sum(),  "parent received at least one kin_donation but did not make one");
+  dn_donors.Write(threshgb_donation_makers.Sum(), "parent made at least one threshgb_donation");
+  dn_donors.Write(threshgb_donation_receivers.Sum(), "parent received at least one threshgb_donation");
+  dn_donors.Write(threshgb_donation_cheaters.Sum(),  "parent received at least one threshgb_donation but did not make one");
+  dn_donors.Write(quanta_threshgb_donation_makers.Sum(), "parent made at least one quanta_threshgb_donation");
+  dn_donors.Write(quanta_threshgb_donation_receivers.Sum(), "parent received at least one quanta_threshgb_donation");
+  dn_donors.Write(quanta_threshgb_donation_cheaters.Sum(),  "parent received at least one quanta_threshgb_donation but did not make one");
+
+  dn_donors.Endl();
+}
 // Copy a single indvidual out of a deme into a new one (which is first purged
 // of existing organisms.)
 

Modified: branches/collect/source/main/cPopulation.h
===================================================================
--- branches/collect/source/main/cPopulation.h	2007-05-28 00:46:50 UTC (rev 1621)
+++ branches/collect/source/main/cPopulation.h	2007-05-29 17:52:26 UTC (rev 1622)
@@ -168,6 +168,10 @@
   void SpawnDeme(int deme1_id, int deme2_id=-1);
   void PrintDemeStats();
 
+  // Print donation stats
+  void PrintDonationStats();
+
+
   // Process a single organism one instruction...
   int ScheduleOrganism();          // Determine next organism to be processed.
   void ProcessStep(cAvidaContext& ctx, double step_size, int cell_id);

Copied: branches/collect/tests/avida_GA_lim_res (from rev 1593, development/tests/avida_GA_lim_res)




More information about the Avida-cvs mailing list