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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Sun Nov 16 10:11:58 PST 2008


Author: hjg
Date: 2008-11-16 13:11:58 -0500 (Sun, 16 Nov 2008)
New Revision: 2945

Modified:
   branches/hjg-dev/source/actions/PopulationActions.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
   branches/hjg-dev/source/main/cAvidaConfig.h
   branches/hjg-dev/source/main/cDeme.cc
   branches/hjg-dev/source/main/cDeme.h
   branches/hjg-dev/source/main/cOrganism.cc
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cPopulation.cc
   branches/hjg-dev/source/main/cStats.cc
   branches/hjg-dev/source/main/cStats.h
Log:
code for demes with two species.

Modified: branches/hjg-dev/source/actions/PopulationActions.cc
===================================================================
--- branches/hjg-dev/source/actions/PopulationActions.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/actions/PopulationActions.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -36,6 +36,7 @@
 #include "cWorld.h"
 #include "cOrganism.h"
 
+#include <map>
 
 /*
  Injects a single organism into the population.
@@ -544,14 +545,17 @@
   double m_merit;
   int m_lineage_label;
   double m_neutral_metric;
+	int m_cellid;
 public:
-    cActionInjectDemes(cWorld* world, const cString& args) : cAction(world, args), m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+    cActionInjectDemes(cWorld* world, const cString& args) : cAction(world, args), m_merit(-1), m_lineage_label(0), m_neutral_metric(0), m_cellid(0)
   {
       cString largs(args);
       if (!largs.GetSize()) m_filename = "START_CREATURE"; else m_filename = largs.PopWord();
       if (largs.GetSize()) m_merit = largs.PopWord().AsDouble();
       if (largs.GetSize()) m_lineage_label = largs.PopWord().AsInt();
-      if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+		if (largs.GetSize()) m_neutral_metric = largs.PopWord().AsDouble();
+		if (largs.GetSize()) m_cellid = largs.PopWord().AsInt();
+		
       if (m_filename == "START_CREATURE") m_filename = m_world->GetConfig().START_CREATURE.Get();
   }
   
@@ -563,7 +567,7 @@
     if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
       for(int i=1; i<m_world->GetPopulation().GetNumDemes(); ++i) {  // first org has already been injected
         m_world->GetPopulation().Inject(genome,
-                                        m_world->GetPopulation().GetDeme(i).GetCellID(0),
+                                        m_world->GetPopulation().GetDeme(i).GetCellID(m_cellid),
                                         m_merit, m_lineage_label, m_neutral_metric);
         m_world->GetPopulation().GetDeme(i).IncInjectedCount();
       }
@@ -572,7 +576,7 @@
         // WARNING: initial ancestor has already be injected into the population
         //           calling this will overwrite it.
         m_world->GetPopulation().Inject(genome,
-                                        m_world->GetPopulation().GetDeme(i).GetCellID(0),
+                                        m_world->GetPopulation().GetDeme(i).GetCellID(m_cellid),
                                         m_merit, m_lineage_label, m_neutral_metric);
         m_world->GetPopulation().GetDeme(i).IncInjectedCount();
         
@@ -1281,6 +1285,37 @@
     }
 };
 
+/* This compete demes function balances the number of organisms that 
+	are members of each species. Specifically, the fitness is computed
+	as the product of the number of organisms of each lineage. */
+
+class cAbstractCompeteDemes_BalanceSpecies : public cAbstractCompeteDemes {
+
+  public:
+    cAbstractCompeteDemes_BalanceSpecies(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
+
+    static const cString GetDescription() { return "No Arguments"; }
+  
+    double Fitness(const cDeme& deme) {   
+		 
+      double fitnessOfDeme = 1.0;
+			map <int, int> ln_tracker;
+			ln_tracker = deme.ComputeLineages();
+			
+			if(ln_tracker.size() >= m_world->GetConfig().DEME_NUMBER_OF_LINEAGES.Get()) {
+				for(map<int,int>::iterator i=ln_tracker.begin(); i!=ln_tracker.end(); ++i) {
+					fitnessOfDeme *= i->second;
+				}
+			} else {
+				fitnessOfDeme = 1.0;
+			}
+			
+      return fitnessOfDeme;
+    }
+};
+
+
+
 /* This Action will check if any demes have met the critera to be replicated
    and do so.  There are several bases this can be checked on:
 
@@ -1972,6 +2007,9 @@
 
 /****AbstractCompeteDemes sub-classes****/
   action_lib->Register<cAbstractCompeteDemes_AttackKillAndEnergyConserve>("CompeteDemes_AttackKillAndEnergyConserve");
+	action_lib->Register<cAbstractCompeteDemes_BalanceSpecies>("CompeteDemes_BalanceSpecies");
+
+	
   
   action_lib->Register<cActionNewTrial>("NewTrial");
   action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -456,7 +456,6 @@
 		tInstLibEntry<tMethod>("donate-mat", &cHardwareCPU::Inst_DonateFacingRawMaterialsOneType, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("donate-k", &cHardwareCPU::Inst_DonateFacingConditionalOnK, nInstFlag::STALL),
-  	tInstLibEntry<tMethod>("donate-pr", &cHardwareCPU::Inst_DonateProbReciprocate, nInstFlag::STALL),		
   	tInstLibEntry<tMethod>("donate-if-donor", &cHardwareCPU::Inst_DonateIfDonor, nInstFlag::STALL),		
     tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-reputation", &cHardwareCPU::Inst_GetReputation, nInstFlag::STALL),
@@ -465,8 +464,6 @@
     tInstLibEntry<tMethod>("pose", &cHardwareCPU::Inst_Pose, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("punish-neighbor", &cHardwareCPU::Inst_PunishNeighbor, nInstFlag::STALL),
     tInstLibEntry<tMethod>("praise-neighbor", &cHardwareCPU::Inst_PraiseNeighbor, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("inc-recip", &cHardwareCPU::Inst_IncRecipProb, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("dec-recip", &cHardwareCPU::Inst_DecRecipProb, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("inc-k", &cHardwareCPU::Inst_IncK, nInstFlag::STALL),
     tInstLibEntry<tMethod>("dec-k", &cHardwareCPU::Inst_DecK, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("rotate-to-rep", &cHardwareCPU::Inst_RotateToGreatestReputation, nInstFlag::STALL),
@@ -6789,37 +6786,8 @@
 		// track stats
 		organism->Donated();
 		
-		// update reputation to include this donation.
-		// get the current reputation; increment by 1.
-		// includes a concept of standing
-		if (m_world->GetConfig().AUTO_REPUTATION.Get() == 1) {
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			// if the organism has not yet donated, put it into bad standing
-			if (rep == 0) neighbor->SetReputation(-1);
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 2) {
-			// reputation is proportional to how much you have donated/received
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			neighbor->SetReputation(rep-1);
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 3)  {
-			// set rep to 1, since the organism donated
-			organism->SetReputation(1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			// if the organism has not yet donated, put it into bad standing
-			if (rep == 0) neighbor->SetReputation(-1);		
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 4) {
-			// Similar to 1, except does not include standing.
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
-		}
+		ComputeReputation();
 		
-		
 		}
   }
   return true;
@@ -6848,7 +6816,7 @@
 		return true; 
 	}
 
-	// Subtract raw materials from the organism (currently subtracts 1 resource...)
+	// Subtract raw materials from the organism (currently subtracts cost...)
 	// fails if the organism does not have any more resources
 	int cost = m_world->GetConfig().ALT_COST.Get(); 
 	int benefit = m_world->GetConfig().ALT_BENEFIT.Get();
@@ -6868,86 +6836,15 @@
 
 		// track stats
 		organism->Donated();
+		ComputeReputation();
 		
-		// update reputation to include this donation.
-		// get the current reputation; increment by 1.
-		// includes a concept of standing
-		if (m_world->GetConfig().AUTO_REPUTATION.Get() == 1) {
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			// if the organism has not yet donated, put it into bad standing
-			if (rep == 0) neighbor->SetReputation(-1);
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 2) {
-			// reputation is proportional to how much you have donated/received
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			neighbor->SetReputation(rep-1);
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 3)  {
-			// set rep to 1, since the organism donated
-			organism->SetReputation(1);
-			// get neighbor reputation
-			int rep = neighbor->GetReputation(); 
-			// if the organism has not yet donated, put it into bad standing
-			if (rep == 0) neighbor->SetReputation(-1);		
-		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 4) {
-			// Similar to 1, except does not include standing.
-			int my_rep = organism->GetReputation();
-			organism->SetReputation(my_rep +1);
 		}
-		
-		}
   }
   return true;
 }  
 
 
 
-/* Donate raw materials to the facing organism that with a given 
-probability (set as reputation) will reciprocate. */
-bool cHardwareCPU::Inst_DonateProbReciprocate(cAvidaContext& ctx)
-{
-  bool isSuccessful = false;
-  
-  // Get faced neighbor
-  cOrganism * neighbor = organism->GetNeighbor();
-  
-  // Donate only if we have found a neighbor.
-  if (neighbor != NULL) {
-    // Subtract raw materials from the organism (currently subtracts 1 resource...)
-	// fails if the organism does not have any more resources
-	if (organism->SubtractSelfRawMaterials(1)) {
-		neighbor->AddOtherRawMaterials(1, organism->GetID()); 
-		
-		// track stats
-		organism->Donated();
-		
-		// rotate recipient to face donor 
-		// by rotating until the recipient faces the donor
-		// adding a new comment.
-		while (neighbor->GetNeighbor() != organism) {
-			neighbor->Rotate(1);
-		}
-		
-	  // see if the neighbor reciprocates
-		unsigned int recip_prob = (unsigned int) neighbor->GetReciprocationProbability(); 
-		unsigned int rand_num = m_world->GetRandom().GetUInt(0, 10); 
-		// neighbor donates to organism.
-		if(rand_num < recip_prob) { 
-			if (neighbor->SubtractSelfRawMaterials(1)) {
-					organism->AddOtherRawMaterials(1, neighbor->GetID()); 
-					// track stats
-					neighbor->Reciprocated();
-			}
-		}
-	}
-	isSuccessful = true;
-  }
-  return isSuccessful;
-}  
 
 /* An organism artificially increases its reputation without donating. */
 bool cHardwareCPU::Inst_Pose(cAvidaContext& ctx)
@@ -7051,21 +6948,6 @@
 	return true;
 }
 
-/* Increase an organism's probability of reciprocating by 10% */
-bool cHardwareCPU::Inst_IncRecipProb(cAvidaContext& ctx) 
-{
-	organism->IncRecipProb();
-	return true;
-}
-
-
-/* Decrease an organism's probability of reciprocating by 10% */
-bool cHardwareCPU::Inst_DecRecipProb(cAvidaContext& ctx) 
-{
-	organism->DecRecipProb();
-	return true;
-}
-
 /* Rotate to face the organism with the highest reputation */
 bool cHardwareCPU::Inst_RotateToGreatestReputation(cAvidaContext& ctx) 
 {
@@ -7123,4 +7005,40 @@
 }
 
  
- 
\ No newline at end of file
+void cHardwareCPU::ComputeReputation() 
+{
+		cOrganism * neighbor = organism->GetNeighbor();
+
+		// update reputation to include this donation.
+		// get the current reputation; increment by 1.
+		// includes a concept of standing
+		if (m_world->GetConfig().AUTO_REPUTATION.Get() == 1) {
+			int my_rep = organism->GetReputation();
+			organism->SetReputation(my_rep +1);
+			// get neighbor reputation
+			int rep = neighbor->GetReputation(); 
+			// if the organism has not yet donated, put it into bad standing
+			if (rep == 0) neighbor->SetReputation(-1);
+		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 2) {
+			// reputation is proportional to how much you have donated/received
+			int my_rep = organism->GetReputation();
+			organism->SetReputation(my_rep +1);
+			// get neighbor reputation
+			int rep = neighbor->GetReputation(); 
+			neighbor->SetReputation(rep-1);
+		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 3)  {
+			// set rep to 1, since the organism donated
+			organism->SetReputation(1);
+			// get neighbor reputation
+			int rep = neighbor->GetReputation(); 
+			// if the organism has not yet donated, put it into bad standing
+			if (rep == 0) neighbor->SetReputation(-1);		
+		} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 4) {
+			// Similar to 1, except does not include standing.
+			int my_rep = organism->GetReputation();
+			organism->SetReputation(my_rep +1);
+		}
+
+}
+
+

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-11-16 18:11:58 UTC (rev 2945)
@@ -314,6 +314,10 @@
   bool GetMalActive() const   { return m_mal_active; }
 
   
+	// Reputation
+	void ComputeReputation();
+	double ComputeDonateBenefit();
+	
 private:
   // ---------- Instruction Library -----------
 
@@ -697,10 +701,6 @@
 	// Execute the following instruction if the facing neighbor was a donor
 	bool Inst_IfDonor(cAvidaContext& ctx);
 
-	
-	
-	// Donation to facing neighbor with a probability that it is reciprocated
-  bool Inst_DonateProbReciprocate(cAvidaContext& ctx);	
   // Get the organism's raw material level
   bool Inst_GetAmountOfRawMaterials(cAvidaContext& ctx);
   // Get the number of raw materials the organism 
@@ -712,10 +712,6 @@
   bool Inst_PunishNeighbor(cAvidaContext& ctx);	
 	// Praise Neighbor - decrease reputation of neighbor
 	bool Inst_PraiseNeighbor(cAvidaContext& ctx);
-	// Increase the reciprocation probability
-	bool Inst_IncRecipProb(cAvidaContext& ctx);
-	// Decrease the reciprocation probability
-	bool Inst_DecRecipProb(cAvidaContext& ctx);
 	// Decrease k (lowest reputation bar)
 	bool Inst_DecK(cAvidaContext& ctx);
 	// Increase k (lowest reputation bar)

Modified: branches/hjg-dev/source/main/cAvidaConfig.h
===================================================================
--- branches/hjg-dev/source/main/cAvidaConfig.h	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cAvidaConfig.h	2008-11-16 18:11:58 UTC (rev 2945)
@@ -327,6 +327,9 @@
   CONFIG_ADD_VAR(DEMES_DEFAULT_GERMLINE_PROPENSITY, double, 0.0, "Default germline propensity of organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.");
   CONFIG_ADD_VAR(DEMES_FOUNDER_GERMLINE_PROPENSITY, double, -1.0, "Default germline propensity of founder organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.\n <0 = OFF");
   CONFIG_ADD_VAR(DEMES_PREFER_EMPTY, int, 0, "Give empty demes preference as targets of deme replication?");
+  CONFIG_ADD_VAR(DEME_NUMBER_OF_LINEAGES, int, 0, "The number of lineages to be preserved in a deme using the DEME_ORGANISM_SELECTION 2");
+	
+	//DEME_NUMBER_OF_LINEAGES
 
   CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
   CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9 = Largest energy used in entire population\n10 = Largest energy used in neighborhood");
@@ -565,7 +568,6 @@
   CONFIG_ADD_VAR(REPUTATION_REWARD, int, 0, "Reward an organism for having a good reputation");
   CONFIG_ADD_VAR(DONATION_FAILURE_PERCENT, int, 0, "Percentage of times that a donation fails");
   CONFIG_ADD_VAR(RANDOMIZE_RAW_MATERIAL_AMOUNT, int, 0, "Should all the organisms receive the same amount 0/1 (off/on)");
-
   
 #endif
   

Modified: branches/hjg-dev/source/main/cDeme.cc
===================================================================
--- branches/hjg-dev/source/main/cDeme.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cDeme.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -795,3 +795,49 @@
 //  assert(false); // slots must be of equal size and fit perfectally in deme lifetime
   return 0;
 }
+
+/* This method computes the number of lineages in a deme. Additionally, 
+ it figures out the number of organisms in each lineage, and also puts one 
+ random one from each lineage into a set. */
+map <int, int> cDeme::ComputeLineages()  const
+{
+	map <int, int> lineage_tracker;
+	
+	for (int i=0; i<GetSize(); i++) {
+		int cellid = GetCellID(i);
+		cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+		if(cell.IsOccupied()) {
+			cOrganism* organism = cell.GetOrganism();
+			
+			int org_lineage = organism->GetLineageLabel(); 
+			lineage_tracker[org_lineage]++;
+			
+		}
+	}
+	return lineage_tracker;
+}
+
+
+std::vector<std::pair<cGenome,int> > cDeme::GetRepresentativeOrganismsFromLineages()
+{
+	map <int, vector<int> > lineages;
+	std::vector<std::pair<cGenome,int> > rep_orgs;
+	
+	for (int i=0; i<GetSize(); i++) {
+		cPopulationCell& cell = GetCell(i);
+		if(cell.IsOccupied()) {
+			cOrganism* organism = cell.GetOrganism();			
+			int org_lineage = organism->GetLineageLabel(); 
+			lineages[org_lineage].push_back(GetCellID(i));
+		}
+	}
+	
+	for(map<int, vector<int> >::iterator i=lineages.begin(); i!=lineages.end(); ++i) {
+		int rand_vector_element = m_world->GetRandom().GetUInt(0, i->second.size());
+		int rand_org_id = i->second[rand_vector_element];
+		cOrganism* org = m_world->GetPopulation().GetCell(rand_org_id).GetOrganism();
+		rep_orgs.push_back(std::make_pair(org->GetGenome(), org->GetLineageLabel()));
+	}
+	
+	return rep_orgs;
+}

Modified: branches/hjg-dev/source/main/cDeme.h
===================================================================
--- branches/hjg-dev/source/main/cDeme.h	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cDeme.h	2008-11-16 18:11:58 UTC (rev 2945)
@@ -25,6 +25,7 @@
 #define cDeme_h
 
 #include <vector>
+#include <map>
 
 #include "cDemeCellEvent.h"
 #include "cGermline.h"
@@ -286,6 +287,17 @@
 
   // --- Pheromones --- //
   void AddPheromone(int absolute_cell_id, double value);
+	
+	
+	//---Reciprocity---//
+	private:
+//	map <int, int> lineage_tracker;
+	
+	public: 
+	map <int, int> ComputeLineages() const; 
+	std::vector<std::pair<cGenome,int> > GetRepresentativeOrganismsFromLineages(); 
+
+	
 };
 
 #endif

Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cOrganism.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -78,11 +78,8 @@
   , m_opinion(0)
   , m_self_raw_materials(world->GetConfig().RAW_MATERIAL_AMOUNT.Get())
   , m_other_raw_materials(0)
-	, m_recip_prob(5)	
 	, m_num_donate(0)
 	, m_num_reciprocate(0)
-	, m_max_recip_prob(5)
-	, m_min_recip_prob(5)
 	, m_num_donate_received(0)
 	, m_amount_donate_received(0)
 	, m_k(0)
@@ -117,7 +114,6 @@
   , m_net(NULL)
   , m_msg(0)
   , m_opinion(0)
-	, m_recip_prob(5)
 {
   m_hardware = m_world->GetHardwareManager().Create(this, inst_set);
   
@@ -842,42 +838,7 @@
 	return;
 }
 
-/* Increase an organism's probability of donating by 10% 
-	Essentially, the reputation can vary from 0-10, where 0
-	indicates the organism never reciprocates and 10 indicates
-	the organism always reciprocates.  */
-void cOrganism::IncRecipProb() {
-//	if (m_recip_prob < 10) { 
-		m_recip_prob++;
-		
-		if (m_recip_prob > m_max_recip_prob) m_max_recip_prob = m_recip_prob;
-		
-		// If reputation is automatic and should be tied to the
-		// reciprocity probability, then update the organism's opinion.
-		if (m_world->GetConfig().AUTO_REPUTATION.Get()) {
-			SetOpinion(m_recip_prob);
-		}
-//	}
-}
 
-/* Decrease an organism's probability of donating by 10% 
-	Essentially, the reputation can vary from 0-10, where 0
-	indicates the organism never reciprocates and 10 indicates
-	the organism always reciprocates.  */
-void cOrganism::DecRecipProb() { 
-//	if (m_recip_prob > 0) { 
-		m_recip_prob--;
-		
-		if (m_recip_prob < m_min_recip_prob) m_min_recip_prob = m_recip_prob;
-
-		// If reputation is automatic and should be tied to the
-		// reciprocity probability, then update the organism's opinion.
-		if (m_world->GetConfig().AUTO_REPUTATION.Get()) {
-			SetOpinion(m_recip_prob);
-//		}
-	}
-}
-
 /* Check if an organism has previously donated to this organism */
 bool cOrganism::IsDonor(int neighbor_id) 
 {

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-11-16 18:11:58 UTC (rev 2945)
@@ -462,12 +462,6 @@
 	void SetReputation(int rep);
 	// get number of donors
 	int GetNumberOfDonors() { return donor_list.size(); }
-	// increase reciprocation probability
-	void IncRecipProb();
-	// decrease reciprocation probability
-	void DecRecipProb();
-	// get reciprocation probability
-	int GetReciprocationProbability() { return m_recip_prob; }
 	// organism donated
 	void Donated(){m_num_donate++;}
 	// get number of donations
@@ -480,8 +474,6 @@
 	void Reciprocated() {m_num_reciprocate++;}
 	// get number of reciprocations
 	int GetNumberOfReciprocations() { return m_num_reciprocate; }
-	// get the change in reciprocal probability
-	int GetChangeInRecipProb() { return m_max_recip_prob - m_min_recip_prob; }
 	// get k
 	int GetK() { return m_k; }
 	// increase k
@@ -500,8 +492,6 @@
 	int m_other_raw_materials;
   // Organisms that have donated to this organism
 	set<int> donor_list;
-	// the probability that an organism will reciprocate
-	int m_recip_prob;
 	// number of donations
 	int m_num_donate;
 	// number of donations received
@@ -510,10 +500,6 @@
 	int m_amount_donate_received;
 	// number of reciprocations
 	int m_num_reciprocate;
-	// max-reciprocation probability
-	int m_max_recip_prob;
-	// min-reciprocation probability
-	int m_min_recip_prob;
 	// reputation minimum for donation/rotation 
 	// based on Nowak89
 	int m_k;

Modified: branches/hjg-dev/source/main/cPopulation.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulation.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cPopulation.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -1589,6 +1589,11 @@
           }
           break;
         }
+				case 2: { // Selection of one organism from each lineage. 
+					// Get the genomes and lineage labels
+					xfer = source_deme.GetRepresentativeOrganismsFromLineages();
+					break;
+				}
         default: {
           cout << "Undefined value (" << m_world->GetConfig().DEMES_ORGANISM_SELECTION.Get()
           << ") for DEMES_ORGANISM_SELECTION." << endl;
@@ -4458,6 +4463,9 @@
 
   // The rest is done by InjectGenotype();
   InjectGenotype( cell_id, new_genotype );
+	
+	// cheap hack?
+	cell_array[cell_id].GetOrganism()->SetLineageLabel(lineage_label);
 }
 
 

Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cStats.cc	2008-11-16 18:11:58 UTC (rev 2945)
@@ -1718,6 +1718,23 @@
   m_deme_fitness.clear();
 }
 
+
+/* This method prints the number of organisms of each lineage in a deme. */
+void cStats::PrintDemeLineageData(const cString& filename){
+  cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment("Avida deme lineage data");
+	df.WriteTimeStamp();
+	df.WriteComment("First column gives the current update, next columns give the number");
+	df.WriteComment("of organisms per deme of each lineage.");
+
+	vector <int> deme_lineages; 
+//  tArray<int> deme_lineages;
+//  deme_tasks.ResizeClear(num_tasks);
+//  deme_tasks.SetAll(num_tasks);
+	
+// built in assumption that there are 2 lineages. 
+	}
+
 /* Print information about the reputation... */
 void cStats::PrintReputationData(const cString& filename){
 	cDataFile& df = m_world->GetDataFile(filename);
@@ -1726,7 +1743,6 @@
 	cDoubleSum donations;
 	cDoubleSum reciprocations; 
 	cDoubleSum donors;
-	cDoubleSum recip_prob_change;
 	cDoubleSum k;
 	cDoubleSum num_donations_received; 
 	cDoubleSum amount_donations_received;
@@ -1763,7 +1779,6 @@
 		amount_donations_received.Add(org->GetAmountOfDonationsReceived());
 		reciprocations.Add(org->GetNumberOfReciprocations());
 		donors.Add(org->GetNumberOfDonors());
-		recip_prob_change.Add(org->GetChangeInRecipProb());
 		k.Add(org->GetK());
 //		pop_size++;
 		

Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h	2008-11-16 01:24:25 UTC (rev 2944)
+++ branches/hjg-dev/source/main/cStats.h	2008-11-16 18:11:58 UTC (rev 2945)
@@ -740,6 +740,8 @@
   void PrintCompetitionData(const cString& filename);
   // @WRE: Added event for printing visit counts
   void PrintCellVisitsData(const cString& filename);
+	void PrintDemeLineageData(const cString& filename);
+	
 
   // deme predicate stats
   void IncEventCount(int x, int y);




More information about the Avida-cvs mailing list