[Avida-SVN] r3189 - in branches/interrupt/source: actions cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Mar 13 07:43:56 PDT 2009


Author: beckma24
Date: 2009-03-13 10:43:55 -0400 (Fri, 13 Mar 2009)
New Revision: 3189

Modified:
   branches/interrupt/source/actions/PopulationActions.cc
   branches/interrupt/source/cpu/cHardwareCPU.cc
   branches/interrupt/source/main/cPhenotype.cc
   branches/interrupt/source/main/cPhenotype.h
   branches/interrupt/source/main/cPopulation.cc
   branches/interrupt/source/main/cPopulation.h
   branches/interrupt/source/main/cPopulationInterface.cc
Log:
Added population actions SetFracOrgsCantSendMSG and SetFracOrgsCantReceiveMSG

Modified: branches/interrupt/source/actions/PopulationActions.cc
===================================================================
--- branches/interrupt/source/actions/PopulationActions.cc	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/actions/PopulationActions.cc	2009-03-13 14:43:55 UTC (rev 3189)
@@ -2630,7 +2630,41 @@
   }
 };
 
+class cActionSetFracOrgsCantSendMSG : public cAction {
+	private:
+		double m_frac;
+	public:
+		cActionSetFracOrgsCantSendMSG(cWorld* world, const cString& args) : cAction(world, args), m_frac(0.0)
+		{
+			cString largs(args);
+			if (largs.GetSize()) m_frac = largs.PopWord().AsDouble();
+		}
+		
+		static const cString GetDescription() { return "Arguments: [int frac=0.0]"; }
+		
+		void Process(cAvidaContext& ctx)
+		{
+			m_world->GetPopulation().setFracOrgsCantSendMSG(m_frac);
+		}
+};
 
+class cActionSetFracOrgsCantReceiveMSG : public cAction {
+	private:
+		double m_frac;
+	public:
+		cActionSetFracOrgsCantReceiveMSG(cWorld* world, const cString& args) : cAction(world, args), m_frac(0.0)
+		{
+			cString largs(args);
+			if (largs.GetSize()) m_frac = largs.PopWord().AsDouble();
+		}
+		
+		static const cString GetDescription() { return "Arguments: [int frac=0.0]"; }
+		
+		void Process(cAvidaContext& ctx)
+		{
+			m_world->GetPopulation().setFracOrgsCantReceiveMSG(m_frac);
+		}
+};
 
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
@@ -2697,6 +2731,9 @@
   action_lib->Register<cActionCompeteDemesByTaskCount>("CompeteDemesByTaskCount");
   action_lib->Register<cActionCompeteDemesByTaskCountAndEfficiency>("CompeteDemesByTaskCountAndEfficiency");
   action_lib->Register<cActionCompeteDemesByEnergyDistribution>("CompeteDemesByEnergyDistribution");	
+	
+	action_lib->Register<cActionSetFracOrgsCantSendMSG>("SetFracOrgsCantSendMSG");
+	action_lib->Register<cActionSetFracOrgsCantReceiveMSG>("SetFracOrgsCantReceiveMSG");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");

Modified: branches/interrupt/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/interrupt/source/cpu/cHardwareCPU.cc	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/cpu/cHardwareCPU.cc	2009-03-13 14:43:55 UTC (rev 3189)
@@ -6112,6 +6112,10 @@
 //     and call Inst_RetrieveMessage which eats a NOP if one exists
 /* basic message sending functionallity  */
 bool cHardwareCPU::Inst_SendMessageBase(cAvidaContext& ctx, int messageType) {
+	if(!m_organism->GetPhenotype().canSendMSG()) { // this can be removed once instruction sets can be inherited
+		return true;  // should this be false?
+	}
+	
 	const int label_reg = FindModifiedRegister(REG_BX);
   const int data_reg = FindNextRegister(label_reg);
   

Modified: branches/interrupt/source/main/cPhenotype.cc
===================================================================
--- branches/interrupt/source/main/cPhenotype.cc	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/main/cPhenotype.cc	2009-03-13 14:43:55 UTC (rev 3189)
@@ -66,6 +66,8 @@
   , last_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
   , last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())  
   , last_sense_count(m_world->GetStats().GetSenseSize())
+	, canSendMessage(true)
+	, canReceiveMessage(true)
 {
 }
 
@@ -245,6 +247,9 @@
 
   // 7. Permanent information...
   permanent_germline_propensity = in_phen.permanent_germline_propensity;
+	
+	canSendMessage     = in_phen.canSendMessage;
+	canReceiveMessage  = in_phen.canReceiveMessage;
          
   return *this;
 }
@@ -445,6 +450,9 @@
   // permanently set germline propensity of org (since DivideReset is called first, it is now in the "last" slot...)
   permanent_germline_propensity  = parent_phenotype.last_child_germline_propensity;
 
+	canSendMessage = parent_phenotype.canSendMessage;
+	canReceiveMessage = parent_phenotype.canReceiveMessage;
+	
   initialized = true;
 }
 

Modified: branches/interrupt/source/main/cPhenotype.h
===================================================================
--- branches/interrupt/source/main/cPhenotype.h	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/main/cPhenotype.h	2009-03-13 14:43:55 UTC (rev 3189)
@@ -239,7 +239,10 @@
   // 7. Information that is set once (when organism was born)
   double permanent_germline_propensity;
   
-
+	// messaging abality
+	bool canSendMessage;
+	bool canReceiveMessage;
+	
   inline void SetInstSetSize(int inst_set_size);
 
   
@@ -539,6 +542,11 @@
   void ApplyDonatedEnergy();
   void ReceiveDonatedEnergy(const double value);
   double ExtractParentEnergy();
+	
+	void disableMsgSending() { canSendMessage = false; }
+	void disableMsgReceiving() { canReceiveMessage = false; }
+	bool canSendMSG() { return canSendMessage; }
+	bool canReceiveMSG() { return canReceiveMessage; }
   
   bool operator<(const cPhenotype& rhs) const;
   bool operator>(const cPhenotype& rhs) const;

Modified: branches/interrupt/source/main/cPopulation.cc
===================================================================
--- branches/interrupt/source/main/cPopulation.cc	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/main/cPopulation.cc	2009-03-13 14:43:55 UTC (rev 3189)
@@ -85,6 +85,8 @@
 , environment(world->GetEnvironment())
 , num_organisms(0)
 , sync_events(false)
+, fracOrgsCantSendMSG(0.0)
+, fracOrgsCantReceiveMSG(0.0)
 {
   // Avida specific information.
   world_x = world->GetConfig().WORLD_X.Get();
@@ -361,6 +363,16 @@
     // Update the phenotypes of each child....
     const cGenome & child_genome = child_array[i]->GetGenome();
     child_array[i]->GetPhenotype().SetupOffspring(parent_phenotype,child_genome);
+		
+		// can be removed after instruction set can be inherited
+		if(fracOrgsCantSendMSG > 0.0 && m_world->GetRandom().P(fracOrgsCantSendMSG)) {
+			child_array[i]->GetPhenotype().disableMsgSending();
+		}
+
+		if(fracOrgsCantReceiveMSG > 0.0 && m_world->GetRandom().P(fracOrgsCantReceiveMSG)) {
+			child_array[i]->GetPhenotype().disableMsgReceiving();
+		}
+		
     child_array[i]->GetPhenotype().SetMerit(merit_array[i]);
     
     // Do lineage tracking for the new organisms.

Modified: branches/interrupt/source/main/cPopulation.h
===================================================================
--- branches/interrupt/source/main/cPopulation.h	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/main/cPopulation.h	2009-03-13 14:43:55 UTC (rev 3189)
@@ -112,7 +112,10 @@
  
   // Outside interactions...
   bool sync_events;   // Do we need to sync up the event list with population?
-
+	
+	double fracOrgsCantSendMSG;
+	double fracOrgsCantReceiveMSG;
+	
   ///////////////// Private Methods ////////////////////
   void BuildTimeSlicer(cChangeList* change_list); // Build the schedule object
 
@@ -322,6 +325,11 @@
   
   // Let users change environmental variables durning the run @BDB 22-Feb-2008
   void UpdateResourceCount(const int Verbosity);
+	
+	double getFracOrgsCantSendMSG() const { return fracOrgsCantSendMSG; }
+	double getFracOrgsCantReceiveMSG() const { return fracOrgsCantReceiveMSG; }
+	void setFracOrgsCantSendMSG(double frac) { assert(1.0 >= frac && frac >= 0.0); fracOrgsCantSendMSG = frac; }
+	void setFracOrgsCantReceiveMSG(double frac) { assert(1.0 >= frac && frac >= 0.0); fracOrgsCantReceiveMSG = frac; }
 };
 
 

Modified: branches/interrupt/source/main/cPopulationInterface.cc
===================================================================
--- branches/interrupt/source/main/cPopulationInterface.cc	2009-03-12 14:37:35 UTC (rev 3188)
+++ branches/interrupt/source/main/cPopulationInterface.cc	2009-03-13 14:43:55 UTC (rev 3189)
@@ -283,7 +283,11 @@
     return false;
   cOrganism* recvr = rcell->GetOrganism();
   assert(recvr != NULL);
-  recvr->ReceiveMessage(msg);
+	if(recvr->GetPhenotype().canReceiveMSG()) {  // can be removed once instructions sets are inherited
+		recvr->ReceiveMessage(msg);
+	} else {
+		GetDeme()->messageDropped();
+	}
   return true;
 }
 




More information about the Avida-cvs mailing list