[Avida-SVN] r3120 - in development/source: actions cpu main

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Fri Jan 16 08:22:13 PST 2009


Author: connel42
Date: 2009-01-16 11:22:13 -0500 (Fri, 16 Jan 2009)
New Revision: 3120

Modified:
   development/source/actions/PopulationActions.cc
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cAvidaConfig.h
Log:
Some energy and energy sharing updates

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-01-15 17:28:05 UTC (rev 3119)
+++ development/source/actions/PopulationActions.cc	2009-01-16 16:22:13 UTC (rev 3120)
@@ -1708,6 +1708,58 @@
 };
 
 
+class cActionCompeteDemesByEnergyDistribution : public cAbstractCompeteDemes {
+private:
+
+public:
+	cActionCompeteDemesByEnergyDistribution(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) {}
+	~cActionCompeteDemesByEnergyDistribution() {}
+	
+	static const cString GetDescription() { 
+		return "Competes demes according to the distribution of energy among the organisms"; 
+	}
+	
+	virtual double Fitness(const cDeme& deme) {
+		const int numcells = deme.GetSize();
+		
+		double min_energy = -1;
+		double max_energy = -1;
+		double current_energy;
+		double fitness;
+		
+		cOrganism *org;
+		
+		for(int cellid = 0; cellid < numcells; cellid++) {
+			org = deme.GetOrganism(cellid);
+			fitness = 0.0001;
+			
+			if (org != 0) {
+				current_energy = org->GetPhenotype().GetStoredEnergy();
+				
+				if((min_energy == -1) || (current_energy < min_energy)) {
+					min_energy = current_energy;
+				}
+				
+				if((max_energy == -1) || (current_energy > max_energy)) {
+					max_energy = current_energy;
+				}
+			}
+		}
+		
+		if((min_energy == -1) || (max_energy == -1)) {
+			fitness = 0.0001;
+		} else if (min_energy == max_energy) {
+			fitness = 100 * max_energy;
+		} else {
+			fitness = 100 * (max_energy/pow((max_energy - min_energy),2));
+		}
+				
+		return fitness;
+	}
+};
+
+
+
 /*! Send an artificial flash to a single organism in each deme in the population
  at a specified period.
  
@@ -2623,6 +2675,7 @@
 
   action_lib->Register<cActionCompeteDemesByTaskCount>("CompeteDemesByTaskCount");
   action_lib->Register<cActionCompeteDemesByTaskCountAndEfficiency>("CompeteDemesByTaskCountAndEfficiency");
+  action_lib->Register<cActionCompeteDemesByEnergyDistribution>("CompeteDemesByEnergyDistribution");	
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-01-15 17:28:05 UTC (rev 3119)
+++ development/source/cpu/cHardwareCPU.cc	2009-01-16 16:22:13 UTC (rev 3120)
@@ -392,16 +392,18 @@
     tInstLibEntry<tMethod>("relinquishEnergyToOrganismsInDeme", &cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme, nInstFlag::STALL),
 
     // Energy level detection
-	  tInstLibEntry<tMethod>("if-energy-low", &cHardwareCPU::Inst_IfEnergyLow, nInstFlag::STALL),
-	  tInstLibEntry<tMethod>("if-energy-not-low", &cHardwareCPU::Inst_IfEnergyNotLow, nInstFlag::STALL),
-	  tInstLibEntry<tMethod>("if-faced-energy-low", &cHardwareCPU::Inst_IfFacedEnergyLow, nInstFlag::STALL),
-	  tInstLibEntry<tMethod>("if-faced-energy-not-low", &cHardwareCPU::Inst_IfFacedEnergyNotLow, nInstFlag::STALL),
-  	tInstLibEntry<tMethod>("if-energy-high", &cHardwareCPU::Inst_IfEnergyHigh, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-energy-low", &cHardwareCPU::Inst_IfEnergyLow, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-energy-not-low", &cHardwareCPU::Inst_IfEnergyNotLow, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-faced-energy-low", &cHardwareCPU::Inst_IfFacedEnergyLow, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-faced-energy-not-low", &cHardwareCPU::Inst_IfFacedEnergyNotLow, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("if-energy-high", &cHardwareCPU::Inst_IfEnergyHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-energy-not-high", &cHardwareCPU::Inst_IfEnergyNotHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-faced-energy-high", &cHardwareCPU::Inst_IfFacedEnergyHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-faced-energy-not-high", &cHardwareCPU::Inst_IfFacedEnergyNotHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-energy-med", &cHardwareCPU::Inst_IfEnergyMed, nInstFlag::STALL),	 
-  	tInstLibEntry<tMethod>("if-faced-energy-med", &cHardwareCPU::Inst_IfFacedEnergyMed, nInstFlag::STALL),	  
+  	tInstLibEntry<tMethod>("if-faced-energy-med", &cHardwareCPU::Inst_IfFacedEnergyMed, nInstFlag::STALL),	
+  	tInstLibEntry<tMethod>("if-faced-energy-less", &cHardwareCPU::Inst_IfFacedEnergyLess, nInstFlag::STALL),	
+  	tInstLibEntry<tMethod>("if-faced-energy-more", &cHardwareCPU::Inst_IfFacedEnergyMore, nInstFlag::STALL),	    
 	  tInstLibEntry<tMethod>("if-energy-in-buffer", &cHardwareCPU::Inst_IfEnergyInBuffer, nInstFlag::STALL),
 	  tInstLibEntry<tMethod>("if-energy-not-in-buffer", &cHardwareCPU::Inst_IfEnergyNotInBuffer, nInstFlag::STALL),
 	  
@@ -3548,14 +3550,18 @@
   assert(losspct <= 1);
     
   double cur_energy = m_organism->GetPhenotype().GetStoredEnergy();
+  const int update_metabolic = m_world->GetConfig().ENERGY_SHARING_UPDATE_METABOLIC.Get();
   double energy_given = cur_energy * frac_energy_given;
   
   //update energy store and merit of donor
   m_organism->GetPhenotype().ReduceEnergy(energy_given);
   m_organism->GetPhenotype().IncreaseEnergyDonated(energy_given);
-  double senderMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy()  * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
-  m_organism->UpdateMerit(senderMerit);
-  
+	
+  if(update_metabolic == 1) {
+    double senderMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy()  * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+    m_organism->UpdateMerit(senderMerit);
+  }
+	  
   //apply loss in transfer
   energy_given *= (1 - losspct);
   
@@ -3567,8 +3573,11 @@
   //if we are using the push energy method, pass the new energy into the receiver's energy store and recalculate merit
   if(m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) {
     to_org->GetPhenotype().ApplyDonatedEnergy();
-    double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio(), m_world);
-    to_org->UpdateMerit(receiverMerit);
+	  
+	  if(update_metabolic == 1) {
+        double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio(), m_world);
+        to_org->UpdateMerit(receiverMerit);
+	  }
   }
   
 } //End DoEnergyDonatePercent()
@@ -4076,8 +4085,11 @@
   if(m_organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
     m_organism->GetPhenotype().ApplyDonatedEnergy();
     m_organism->GetPhenotype().SetHasUsedDonatedEnergy();
-    double receiverMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
-    m_organism->UpdateMerit(receiverMerit);
+	 
+	  if(m_world->GetConfig().ENERGY_SHARING_UPDATE_METABOLIC.Get() == 1) {
+        double receiverMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+        m_organism->UpdateMerit(receiverMerit);
+  	}
   }
   
   return true;
@@ -5339,6 +5351,56 @@
 } //End Inst_IfFacedEnergyMed()
 
 
+/* Execute the next instruction if the faced organism has less energy */
+bool cHardwareCPU::Inst_IfFacedEnergyLess(cAvidaContext& ctx) {
+  
+  if(m_organism->GetCellID() < 0) {
+    return false;
+  }	
+	
+  // Get faced neighbor
+  cOrganism * neighbor = m_organism->GetNeighbor();
+  
+  if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
+    const double neighbor_energy = neighbor->GetPhenotype().GetStoredEnergy();
+    const double my_energy = m_organism->GetPhenotype().GetStoredEnergy();
+    const double epsilon = m_world->GetConfig().ENERGY_COMPARISON_EPSILON.Get();
+    
+    if(neighbor_energy >= (my_energy * (1 - epsilon))) {
+      IP().Advance();
+    }    
+  }  
+	
+  return true;
+	
+} //End Inst_IfFacedEnergyLess()
+
+
+/* Execute the next instruction if the faced organism has more energy */
+bool cHardwareCPU::Inst_IfFacedEnergyMore(cAvidaContext& ctx) {
+  
+  if(m_organism->GetCellID() < 0) {
+    return false;
+  }	
+	
+  // Get faced neighbor
+  cOrganism * neighbor = m_organism->GetNeighbor();
+  
+  if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
+    const double neighbor_energy = neighbor->GetPhenotype().GetStoredEnergy();
+    const double my_energy = m_organism->GetPhenotype().GetStoredEnergy();
+    const double epsilon = m_world->GetConfig().ENERGY_COMPARISON_EPSILON.Get();
+
+    if(neighbor_energy <= (my_energy * (1 + epsilon))) {
+      IP().Advance();
+    }    
+  }  
+	
+  return true;
+	
+} //End Inst_IfFacedEnergyMore()
+
+
 /* Execute the next instruction if the organism has received energy */
 bool cHardwareCPU::Inst_IfEnergyInBuffer(cAvidaContext& ctx) {
   

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-01-15 17:28:05 UTC (rev 3119)
+++ development/source/cpu/cHardwareCPU.h	2009-01-16 16:22:13 UTC (rev 3120)
@@ -616,6 +616,8 @@
   bool Inst_IfFacedEnergyNotHigh(cAvidaContext& ctx);
   bool Inst_IfEnergyMed(cAvidaContext& ctx);
   bool Inst_IfFacedEnergyMed(cAvidaContext& ctx);
+  bool Inst_IfFacedEnergyMore(cAvidaContext& ctx);
+  bool Inst_IfFacedEnergyLess(cAvidaContext& ctx);
   bool Inst_IfEnergyInBuffer(cAvidaContext& ctx);
   bool Inst_IfEnergyNotInBuffer(cAvidaContext& ctx);
 	

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2009-01-15 17:28:05 UTC (rev 3119)
+++ development/source/main/cAvidaConfig.h	2009-01-16 16:22:13 UTC (rev 3120)
@@ -528,12 +528,14 @@
   CONFIG_ADD_VAR(ATTACK_DECAY_RATE, double, 0.0, "Percent of cell's energy decayed by attack");
   CONFIG_ADD_VAR(ENERGY_THRESH_LOW, double, .33, "Threshold percent below which energy level is considered low.  Requires ENERGY_CAP.");
   CONFIG_ADD_VAR(ENERGY_THRESH_HIGH, double, .75, "Threshold percent above which energy level is considered high.  Requires ENERGY_CAP.");
+  CONFIG_ADD_VAR(ENERGY_COMPARISON_EPSILON, double, 0.0, "Percent difference (relative to executing organism) required in energy level comparisons");
   
   CONFIG_ADD_GROUP(ENERGY_SHARING_GROUP, "Energy Sharing Settings");
   CONFIG_ADD_VAR(ENERGY_SHARING_METHOD, int, 0, "Method for sharing energy.  0=receiver must actively receive/request, 1=energy pushed on receiver");
   CONFIG_ADD_VAR(ENERGY_SHARING_PCT, double, 0.0, "Percent of energy to share");
   CONFIG_ADD_VAR(ENERGY_SHARING_INCREMENT, double, 0.01, "Amount to change percent energy shared");
   CONFIG_ADD_VAR(ENERGY_SHARING_LOSS, double, 0.0, "Percent of shared energy lost in transfer");
+  CONFIG_ADD_VAR(ENERGY_SHARING_UPDATE_METABOLIC, bool, 0, "0/1 (off/on) - Whether to update an organism's metabolic rate on donate or reception/application of energy");
   
   CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
   CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");




More information about the Avida-cvs mailing list